OpenGL texture problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

 glBindTexture(GL_TEXTURE_2D, TextureID);
	glLoadIdentity();
    //Move to offset
    glTranslatef( rPlayer.x , rPlayer.y , 0 );

    //Start quad
    glBegin( GL_QUADS );

        //Set color to white
     // glColor4f( 1.0, 1.0, 1.0, 1.0 );

        //Draw square
	glTexCoord2f(0, 0);   glVertex3f( 0,            0,             0 );
	glTexCoord2f(1, 0);   glVertex3f( SQUARE_WIDTH, 0,             0 );
	glTexCoord2f(1, 1);   glVertex3f( SQUARE_WIDTH, SQUARE_HEIGHT, 0 );
	glTexCoord2f(0, 1);   glVertex3f( 0,            SQUARE_HEIGHT, 0 );

    //End quad
    glEnd();

    	glLoadIdentity();
    //Move to offset
    glTranslatef( 20 , 200 , 0 );

    //Start quad
    glBegin( GL_QUADS );

        //Set color to white
      glColor4f( 1.0, 1.0, 1.0, 1.0 );

        //Draw square
	glVertex3f( 0,            0,             0 );
        glVertex3f( SQUARE_WIDTH, 0,             0 );
	glVertex3f( SQUARE_WIDTH, SQUARE_HEIGHT, 0 );
	glVertex3f( 0,            SQUARE_HEIGHT, 0 );

    //End quad
    glEnd();


I dont know why but the secound SQUARE gets the same color as the textures border.

pic1
http://data.fuskbugg.se/skalman02/ec89030c_pic1.png

pic2
http://data.fuskbugg.se/skalman02/8b6d66f2_pic2.png
This is because you never change the texture or texcoord. The previous glTexCoord2f call remains in effect until you change it. Therefore it's as if all points of the 2nd square are being rendered with glTexCoord2f(0, 1);.

If you want to make it so the texture does not apply to that quad, then disable texturing:

1
2
// put this before your 2nd glBegin
glDisable(GL_TEXTURE_2D);  // iirc... it's been a while 


Of course you'll need to re-enable textures when you want them to take effect again.
Aha, now it works thanks :)
Topic archived. No new replies allowed.