PDA

View Full Version : texture problem



shivmitra
07-12-2011, 12:47 AM
I am using 2 texture to apply on 2 diff. rectangles in my scene .

In starting i generate one texture , bind it and set env. variables and fill it with black pixels and then second texture and do the same thing . now I have another function loadFrame which i use to load texture using glTexSubImage() and before that i bind to the required texture . I am loading only one of the two textures but when i draw the polygon (used glBindTexture) both polygon have same texture the one i loaded while i think the second polygon should have black texture ..

here is the code fragment ..

void CPLCOpenGLEngine::initializeTexture()
{
CPUInt8 *in1 = (CPUInt8 *)calloc(m_presentationTextureWidth*m_presentation TextureHeight*4,sizeof(CPUInt8*));
glGenTextures(1, &m_presentationTexture);
glEnable(GL_TEXTURE_2D);
GLclampf priority = 1.0;
//glPrioritizeTextures(1,&m_presentationTexture,&pri ority);
glBindTexture( GL_TEXTURE_2D, m_presentationTexture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); //change GL_LINEAR to GL_NEAREST to improve performance , quality will be reduced .
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); //change GL_LINEAR to GL_NEAREST to improve performance , quality will be reduced .
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT );
glTexImage2D(GL_TEXTURE_2D,0,4,m_presentationTextu reWidth,m_presentationTextureHeight,0,GL_BGRA_EXT, GL_UNSIGNED_BYTE,in1);
free(in1);

CPUInt8 *in2 = (CPUInt8 *)calloc(m_presenterTextureWidth*m_presenterTextur eHeight*4,sizeof(CPUInt8*));
glGenTextures(1, &m_presenterTexture);
glEnable(GL_TEXTURE_2D);
priority = 1.0;
//glPrioritizeTextures(1,&m_presenterTexture,&priori ty);
glBindTexture( GL_TEXTURE_2D, m_presenterTexture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); //change GL_LINEAR to GL_NEAREST to improve performance , quality will be reduced .
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); //change GL_LINEAR to GL_NEAREST to improve performance , quality will be reduced .
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT );
glTexImage2D(GL_TEXTURE_2D,0,4,m_presenterTextureW idth,m_presenterTextureHeight,0,GL_BGRA_EXT,GL_UNS IGNED_BYTE,in2);
free(in2);
}


void CPLCOpenGLEngine::loadFrame(FrameName name,CPUInt8* in)
{

if(name == ePresenterFrame)
{
glBindTexture(GL_TEXTURE_2D, m_presenterTexture);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,m_presenterWid th,m_presenterHeight,GL_BGRA_EXT,GL_UNSIGNED_BYTE, in);
}
else if(name == ePresentationFrame)
{
glBindTexture(GL_TEXTURE_2D , m_presentationTexture);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,m_presentation Width,m_presentationHeight,GL_BGRA_EXT,GL_UNSIGNED _BYTE,in);
}
error = glGetError();
}


void CPLCOpenGLEngine::display()
{
glClear(GL_COLOR_BUFFER_BIT);
glCallList(m_setup);

glCallList(m_drawListPresentation);
glCallList(m_drawListPresentationSmall);
glBindTexture(GL_TEXTURE_2D , m_presenterTexture);
glCallList(m_drawListPresenter);
glCallList(m_drawListPresenterSmall);
error = glGetError();
glFlush();
SwapBuffers(hDC);
}

carsten neumann
07-12-2011, 08:07 AM
Please use [ code]/[ /code] tags around posted source code.

You never unbind the texture or disable texturing, so if display gets called a second time the texture is still bound and will be used for everything in CPLCOpenGLEngine::display().