Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL won't recognize multitexturing

Started by Mach5Mach Feb 27, 2008 at 3:54 AM 1 replies 1.6k views
Original Post
Mach5Mach
Mach5Mach
Hi, I'm having some trouble implementing bump mapping. I'll give you some background on what I'm trying to do and what is happening. An image is being stored in a pointer for the color map I want to use for the object. I then switch to the second texture unit so I can do this in one pass. The pointer now has the info for the normal map. The tex coords are being passed to GLSL with the MultiTex call so when I'm in the vertex shader I assign the gl_TexCoord[0] to MultiTexCoord0 and gl_TexCoord[1] to MultiTexCoord1. In the frag shader I use the 2D sampler but the second texture just has the values for the first one. Here's my code relevant to the texturing, please help: GLSL in vert shader: gl_TexCoord[0] = gl_MultiTexCoord0; //color map gl_TexCoord[1] = gl_MultiTexCoord1; //normal map in frag shader: vec4 cMap = texture2D(ColorMap, vec2(gl_TexCoord[0])); //cMap is float rgb values of texture vec4 nMap = texture2D(NormalMap, vec2(gl_TexCoord[1])); //nMap is float rgb values of texture C++ in main //texture is GLubyte [256][256][3] and has data by this point // allocate a texture name glGenTextures( 2, textureNum ); //global GLuint textureNum[2]; glActiveTexture(GL_TEXTURE0); //activate texture unit 1 // select our current texture glBindTexture( GL_TEXTURE_2D, textureNum[0] ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // when texture area is small, bilinear filter the closest mipmap glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); // when texture area is large, bilinear filter the original glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // the texture wraps over at the edges (repeat) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); // build our texture mipmaps gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, imagewidth, imageheight, GL_RGB, GL_UNSIGNED_BYTE, texture ); glActiveTexture(GL_TEXTURE1); glBindTexture( GL_TEXTURE_2D, textureNum[1] ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // when texture area is small, bilinear filter the closest mipmap glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); // when texture area is large, bilinear filter the original glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // the texture wraps over at the edges (repeat) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); HeighttoNormalMap(); //texture is changed to store the normal map now gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, imagewidth, imageheight, GL_RGB, GL_UNSIGNED_BYTE, texture ); in display //I have three objects I draw but they all follow this format glActiveTexture(GL_TEXTURE0); //do I need to call bindTexture for each texture unit? glEnable( GL_TEXTURE_2D ); glActiveTexture(GL_TEXTURE1); glEnable( GL_TEXTURE_2D ); glColor3f(1.0f, 1.0f, 1.0f); for(int i = 0; i < FaceList[0]->numFaces; i++){ //goes through each face glBegin(GL_POLYGON); for(int j = 0; j < FaceList->numVerts; j++){ //goes through each vertex float u = ...; //is defined here but is long and not the problem float v = ...; // same here glMultiTexCoord2f(GL_TEXTURE0, u, v); glMultiTexCoord2f(GL_TEXTURE1, u, v); glVertex3f(//same here); } glEnd(); } glActiveTexture(GL_TEXTURE0); glDisable( GL_TEXTURE_2D ); glActiveTexture(GL_TEXTURE1); glDisable( GL_TEXTURE_2D ); }
_the_phantom_
_the_phantom_
While you still have to bind each texture as before in order to get it to work with GLSL you need to inform OpenGL which texture units you are sampling from.

This is done by setting the uniform samplers, in this case ColorMap and NormalMap, to the texture units you are using; so ColorMap would be 0 and NormalMap would be 1.

By default these are 0, which is why you sample the same texture both times.
Mach5Mach
Mach5Mach
Thanks that worked well. I wish I would've asked sooner.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.