Jump to content
  • Advertisement
Sign in to follow this  
Evan2009

OpenGL Problem with rendering a texture.

This topic is 2475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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] );

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Can I just ask you : "Which texture is a render target?". Are you want to render to "texHandle" texture?

I can't see in your code usage of glCopyTexSubImage2D call or GL framebuffer objects... operations which store data to texture...

Basic way is to use glCopyTexSubImage2D after you done anythink what you want to store in texture but using FBOs produce faster results than first way.

Best wishes, FXACE.

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!