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

Problem with rendering a texture.

Started by Evan2009 Oct 7, 2011 at 5:42 PM 0 replies 1.5k views
Original Post
Evan2009
Evan2009
Good morning everyone,

Working on a side project of mine using OpenGL and ran into a problem with rendering a texture on the model I'm trying to animate. The model always shows up as completely black. I've bind the texture I'm trying to use to a quad and it rendered without a problem. This means that I'm loading/binding the texture correctly. I have also disabled lighting, and checked the texture coordinates I'm using which look fine. At the very least if the texture coordinates were wrong I should see something other than black. I have also checked glGetError and I'm not getting any errors. If anyone could point me in the right direction that would be great. Thank you.

InitGL()


CLight::Initialize();
CTextureManager::GetInstance()->Initialize();
establishProjectionMatrix(width, height);
//glShadeModel(GL_SMOOTH);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_PERSPECTIVE_CORRECTION_HINT);

glEnableClientState( GL_VERTEX_ARRAY );
//glEnableClientState( GL_NORMAL_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

mainCLight = new CLight(LSPOT);
mainCLight->setDiffuse(1.0f, 1.0f, 1.0f, 1.0f);
mainCLight->setPosition(0, 50, 0);



DrawScene()


//Setup Scene
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
establishProjectionMatrix(windowWidth, windowHeight);

//TODO: remove
GLuint err = glGetError();

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnable(GL_LIGHTING);
glDisable(GL_BLEND);

//Update the scene from mouse control
glTranslatef(translate.x, translate.y, zoom);
glRotatef(rotateX, 1.0f, 0.0f, 0.0f);
glRotatef(rotateY, 0.0f, 1.0f, 0.0f);

//Draw all lights in the scene
for(int i = 0; i < (int)CLight::lights.size(); i++)
{
CLight* test = CLight::lights;
CLight::lights->updateLight();
}

//Draw grid with no texture
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
drawGrid();

//Draw the model we're animating
glDisable(GL_BLEND);
model.DrawModel(bRenderSkin, bRenderPoints, bRenderJoints);

//Draw Controls
glColor3f(1.0f, 1.0f, 1.0f);
glDisable(GL_LIGHTING);
setOrtho(windowWidth, windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
displayFPS();
drawControls();

//Clean
glFlush();
SDL_GL_SwapBuffers();



CModel Render()

//Draw Quad TODO: remove later

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texHandle);

glBegin(GL_QUADS);
glVertex3f(-1.0f, -1.0f, 0.0f); // The bottom left corner
glTexCoord2f(0, 0);
glVertex3f(-1.0f, 1.0f, 0.0f); // The top left corner
glTexCoord2f(1, 0);
glVertex3f(1.0f, 1.0f, 0.0f); // The top right corner
glTexCoord2f(0, 1);
glVertex3f(1.0f, -1.0f, 0.0f); // The bottom right corner
glTexCoord2f(1, 1);
glEnd( );

//Draw Model

glVertexPointer( 3, GL_FLOAT, 0, &m_vMeshes->GetVertices()[0] ); //NOTE: Remember the [0] at the end when using vectors
//glNormalPointer(GL_FLOAT, 0, &m_vMeshes->GetNormals()[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &m_vMeshes->GetTexCoords()[0]);

glDisable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texHandle);

glDrawElements( GL_TRIANGLES, (GLsizei)m_vMeshes->GetIndices().size(), GL_UNSIGNED_INT, &m_vMeshes->GetIndices()[0] );

Topic Locked

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

Sign in to reply to this topic.