PDA

View Full Version : applying texture to a quad



driver
03-31-2013, 10:55 AM
Hi

I am trying to apply a texture to a quad but my screen remains black. Can anyone spot why ?- I have been trying to figure this out but i am obviously overlooking something.




glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,WINDOW_WIDTH,WINDOW_HEIGHT, 0,-1, 1);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


Above, I have the initial setup.

And then when I want to draw, the below code applies.




glClearColor(0,0,0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

int cameraX=1500;
int cameraY=200;
int cameraZ=2000;

int worldOriginX=1500;
int worldOriginY=0;
int worldOriginZ=1500;

gluLookAt(cameraX,cameraY,cameraZ,worldOriginX,wor ldOriginY,worldOriginZ,0,1,0);

glEnable(GL_TEXTURE_2D);

//I have a class that loads the texture
Texture t;
t.load("mytexture.png");

glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);

glBindTexture(GL_TEXTURE_2D,t.getid()); //returns texture id and binds it
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(0, 1500,750 );
glTexCoord2f(1,0);
glVertex3f(1500, 1500, 750 );
glTexCoord2f(1,1);
glVertex3f(1500 , -50,750 );
glTexCoord2f(0,1);
glVertex3f(0, -50, 750);
glEnd();

glBindTexture(GL_TEXTURE_2D,0);
glDisable(GL_TEXTURE_2D);

trinitrotoluene
03-31-2013, 12:29 PM
Can you post your TexImage2D and TexParameter code. Maybe the problem is there.

tonyo_au
03-31-2013, 05:22 PM
If you don't display a texture but use a colour - does it display correctly?

driver
03-31-2013, 09:03 PM
This is one of the things I had done earlier for debugging purposes- trying to colour the quad red, but it didn't work. It remains black - so obviously the texture itself is not the problem.



glColor4f(1,0,0,1);

glBegin(GL_QUADS);

glVertex3f(0, 1500,750 );

glVertex3f(1500, 1500, 750 );

glVertex3f(1500 , -50,750 );

glVertex3f(0, -50, 750);
glEnd();

tonyo_au
04-01-2013, 05:59 AM
Correct - so now start modifying the camera parameters - your camera is above the target looking down so your should be in the xz plane like (0,0,1). Also change you clear colour and see if you window fills with the new colour - this tells you you are not looking in the direction you think. You object also looks like it is vertical so it might be dissappearing from the angle of the camera which is close to vertical.