PDA

View Full Version : Cannot load in another texture sprite object



john13th
05-09-2010, 02:02 PM
I am currently developing an A.I.-project, written in C++ and rendered in OpenGL. It is going to be shown in 2D view and I am currently loading in all the sprites in form of texture objects. I have managed to load in the background image in the scene which is clearly shown on the screen.

But when I try to load in a sprite object which is going to be part of the foreground it cannot be shown on the the screen even though I am loading in the sprite object in the same way as the background image using genTextures, bindTextures and so on.

I tried to load in the same sprite image in another application and it worked. But I cannot figure why it won't work in this case. Here is the code sample:

void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


----//This is the one that works and it is the background image//-------
glBindTexture(GL_TEXTURE_2D, texId_bground);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

//Draw the background
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0, 0, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(gWidth, 0, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(gWidth, gHeight, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0, gHeight, 0);
glEnd();
--------------------------------------------------------------

----//This is the sprite image that doesn't show up on the screen//-------

glPushMatrix();
glTranslatef(10.5f, 10.5f, 0);
glScalef(20.0f, 20.0f, 1);

glBindTexture(GL_TEXTURE_2D, texId_camera);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

//Draws the sprite
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.5f, 0.5f, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.5f, -0.5f, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, -0.5f, 0);
glEnd();
glPopMatrix();
--------------------------------------------------------------


glDisable(GL_TEXTURE_2D);

glutSwapBuffers();
}