为了澄清,我希望能够加载四种不同的纹理,并根据四边形/顶点的高度,将纹理从一个渐变到下一个.
编辑:下面是一些代码,以帮助显示我想知道的内容
#include <windows.h>#include <SFML/Graphics.hpp>#include <gl/gl.h>#include <gl/glu.h>#define GL_CLAMP_TO_EDGE 0x812Fclass Scene {public: voID resize( int w,int h ) { // OpenGL Reshape glVIEwport( 0,w,h ); glMatrixMode( GL_PROJECTION ); glLoadIDentity(); gluPerspective( 120.0,(GLdouble)w/(GLdouble)h,0.5,500.0 ); glMatrixMode( GL_MODELVIEW ); }};int main() { sf::RenderWindow window(sf::VIDeoMode(800,600,32),"Test"); ///Setup the scene,materials,lighting Scene scene; scene.resize(800,600); glEnable(GL_DEPTH_TEST); glEnable(GL_liGHTING); glcolorMaterial(GL_FRONT_AND_BACK,GL_EMISSION); glEnable(GL_color_MATERIAL); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_Alpha,GL_ONE_MINUS_SRC_Alpha); glEnable(GL_liGHT0); float XL = .5,YL = .1,ZL = 1; GLfloat ambIEntlight[] = { 0.2f,0.2f,1.0f }; GLfloat diffuselight[] = { 0.8f,0.8f,0.8,1.0f }; GLfloat specularlight[] = { 0.5f,0.5f,1.0f }; GLfloat lightpos[] = {XL,YL,ZL,0.}; gllightfv(GL_liGHT0,GL_AMBIENT,ambIEntlight); gllightfv(GL_liGHT0,GL_DIFFUSE,diffuselight); gllightfv(GL_liGHT0,GL_specular,specularlight); gllightfv(GL_liGHT0,GL_position,lightpos); ///Test terrain texture splatting ///Load the textures sf::Image tex1; tex1.loadFromfile("texture1.png"); sf::Image tex2; tex2.loadFromfile("texture2.png"); ///Set the first texture gluint grass; glGenTextures(1,&grass); glBindTexture(GL_TEXTURE_2D,grass); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_liNEAR ); glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_liNEAR ); glTexImage2D( GL_TEXTURE_2D,GL_RGBA,tex1.getSize().x,tex1.getSize().y,GL_UNSIGNED_BYTE,(const GLvoID*)tex1.getPixelsPtr() ); ///Set the second texture gluint dirt; glGenTextures(1,&dirt); glBindTexture(GL_TEXTURE_2D,dirt); glTexEnvf(GL_TEXTURE_ENV,tex2.getSize().x,tex2.getSize().y,(const GLvoID*)tex2.getPixelsPtr() ); ///Start loop while( window.isopen() ) { sf::Event event; while( window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) window.close(); } ///Clear buffer and set camera glClear( GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_PROJECTION); glLoadIDentity(); gluPerspective(50.0,1.0,50); glMatrixMode(GL_MODELVIEW); glLoadIDentity(); gluLookAt(1,1,0); ///Begin rendering quad glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,grass); ///I kNow that around here I should enable blending in order to get my two textures to mix,but I am not certain glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-0.5,-0.5,0.0); glTexCoord2f(1,1); glVertex3f(0.5,0.0); glTexCoord2f(0,0.0); glEnd(); ///@R_404_5990@ env settings for SFML glTexEnvf(GL_TEXTURE_ENV,GL_MODulATE); window.display(); } return 1;}解决方法 如上所述,使用可编程管道,使用着色器.在片段着色器中,您可以传递所有纹理,并根据从顶点着色器接收的顶点数据在它们之间进行插值.
快速搜索给了我this result.我相信这就是你所需要的.另请参阅this post. this论文非常好地解释了这项技术.
总结以上是内存溢出为你收集整理的c – OpenGL中的Texture Splatting是如何实现的?全部内容,希望文章能够帮你解决c – OpenGL中的Texture Splatting是如何实现的?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)