PDA

View Full Version : Texure mapped to unwanted objects



WelshWonder
02-24-2011, 09:20 AM
Hi all,

in openGL I've drawn a cube (using triangle strip) and textured it using a TGA file I created. The cube textures based on a buffer array I created with texture coordinates (wanted), but so does a neighbouring object (unwanted!). Also, the neighbouring object's colour influences the TGA texture on the cube.

The TGA texture is meant to be coloured brown with black specks, but it is influenced by the green colour of the neighbourin object.

Can anyone see why this is?



glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);

gluLookAt(0.0,0.0,-100.0,0,0,0,0,1,0);

glRotatef(x_rotationAngle, 1, 0, 0);
glRotatef(y_rotationAngle, 0, 1, 0);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);

glBindBuffer(GL_ARRAY_BUFFER, coordBuffer);
glTexCoordPointer(2, GL_FLOAT, 0, 0);

//Draw the triangles, we pass in the number of indices, the data type of the index array
// (GL_UNSIGNED_INT) and then the pointer to the start of the array
glDrawArrays(GL_TRIANGLE_STRIP, 0, 24);

//Finally disable the vertex array
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glTranslatef(0.0f, 0.0f, -21.0f);
glPushMatrix();
gluSphere(quadratic,1.0f,32,32);
glTranslatef(0.00f, 0.0f, 0.5f);
glRotatef(-90,0,1,0);
gluCylinder(quadratic,0.5f,0.5f,1.5f,36,2);
glPopMatrix();
glTranslatef(-1.5f, 0.0f, 0.5f);
gluSphere(quadratic,0.5f,32,32);

FlorianR
02-24-2011, 11:31 AM
Disable texturing after you use it, just as you enabled it before, with glDisable(GL_TEXTURE_2D). And set the Color to white (1,1,1,1) before rendering the textured object. OpenGL is a state machine, so when you say "Use textures from now on" or "the following objects should be green" OpenGL will do so until you tell it otherwise.

WelshWonder
02-24-2011, 01:02 PM
Thank you very much! Those two things helped solve the problem. I also found that on top of those two things I didn't have my tga file read in using the correct data type either.