Textures wont show up in Ortho mode....
Having a problem. Can get textures to show in 3D mode, but when I switch to ortho, not only does my square not show up in the width it should, but the textures dont show up either. can anyone tell me why?
//Initalization Code
int Initialize(GLvoid)
{
TIME_DELAY = 40;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // Type Of Depth Testing
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
glAlphaFunc(GL_GREATER,0.1f); // Set Alpha Testing (disable blending)
glEnable(GL_ALPHA_TEST); // Enable Alpha Testing (disable blending)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHTING);
BuildFont();
SCENE = 2;
Scene_1_Initialize();
Scene_2_Initialize();
//Fix the delay at beggining of program
Timer = 35;
return TRUE;
}
//Draw function
static int Draw_Stage_1() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glDisable(GL_LIGHTING);
glLoadIdentity();
//glDisable(GL_CULL_FACE);
gluOrtho2D(0,SCREEN_WIDTH,SCREEN_HEIGHT,0);
//glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
//glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);
//Draw window
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2d(0,0);
glTexCoord2i(1, 0); glVertex2d(SCREEN_WIDTH, 0);
glTexCoord2i(1, 1); glVertex2d(SCREEN_WIDTH,SCREEN_HEIGHT);
glTexCoord2i(0, 1); glVertex2d(0,SCREEN_HEIGHT);
glEnd();
//Return from ortho view
//glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glFlush();
return true;
}
SCREEN_WIDTH is 640 and SCREEN_HEIGHT is 480. any clues?
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com
Uncomment this :
//glMatrixMode(GL_MODELVIEW);
Because for now, you set the projection matrix to the identity matrix...
//glMatrixMode(GL_MODELVIEW);
Because for now, you set the projection matrix to the identity matrix...
Still does not work. Get the same thing. sometimes I get a blank screen.
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com
You''re not binding your texture, uncomment this:
//glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);
And you''re pushing the modelview matrix... Are you sure you don''t want to push the projection matrix onto the stack instead?
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glDisable(GL_LIGHTING);
...
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
I think that should be:
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
...
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
Hope this helps!
//glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);
And you''re pushing the modelview matrix... Are you sure you don''t want to push the projection matrix onto the stack instead?
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glDisable(GL_LIGHTING);
...
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
I think that should be:
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
...
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
Hope this helps!
I know i have the textur enot binded. I''ve played with this function for over 2 hours. At first I couldnt even get the cquare to show, but then I got it. Witht he texture it wont show up at all. I am trying to get my square correct first.
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com
But you''re rendering when in perspective mode!
Don''t you want to switch back to the modelview matrix BEFORE starting to render your quads?
here:
Hope that helps!
Don''t you want to switch back to the modelview matrix BEFORE starting to render your quads?
here:
static int Draw_Stage_1() {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth BufferglLoadIdentity();glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING);//glDisable(GL_CULL_FACE);glMatrixMode(GL_PROJECTION);glPushMatrix(); glLoadIdentity(); gluOrtho2D(0,SCREEN_WIDTH,SCREEN_HEIGHT,0); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);//Draw windowglColor4f(1.0f, 1.0f, 1.0f, 1.0f);glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2d(0,0);glTexCoord2i(1, 0); glVertex2d(SCREEN_WIDTH, 0);glTexCoord2i(1, 1); glVertex2d(SCREEN_WIDTH,SCREEN_HEIGHT);glTexCoord2i(0, 1); glVertex2d(0,SCREEN_HEIGHT);glEnd();//Return from ortho viewglMatrixMode(GL_PROJECTION);glPopMatrix(); glMatrixMode(GL_MODELVIEW);glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glFlush();return true;}
Hope that helps!
Not really relevant to the problem but these comments seem suspect :
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
glAlphaFunc(GL_GREATER,0.1f); // Set Alpha Testing (disable blending)
glEnable(GL_ALPHA_TEST); // Enable Alpha Testing (disable blending)
Neither enabling alpha blending disables alpha testing nor enabling alpha testing disables alpha blending. The alpha test and alpha blending are two independant states.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
glAlphaFunc(GL_GREATER,0.1f); // Set Alpha Testing (disable blending)
glEnable(GL_ALPHA_TEST); // Enable Alpha Testing (disable blending)
Neither enabling alpha blending disables alpha testing nor enabling alpha testing disables alpha blending. The alpha test and alpha blending are two independant states.
This did not help 
I still can not get the square correct. Right now i''m not even worried about the texture showing up, i need to draw a square covering the entire screen in ortho mode. What is so hard about that?
I am running a radeon 9000 if that makes any difference. i am able to render in ortho mode in other projects but there are no differences in the initalization nor were there differences in the drawing code. WTF?
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com

I still can not get the square correct. Right now i''m not even worried about the texture showing up, i need to draw a square covering the entire screen in ortho mode. What is so hard about that?
I am running a radeon 9000 if that makes any difference. i am able to render in ortho mode in other projects but there are no differences in the initalization nor were there differences in the drawing code. WTF?
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com
I got it working. Here is what I did
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
glDisable(GL_LIGHTING);
//glDisable(GL_DEPTH_TEST);
//Setup 2d ortho mode
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,SCREEN_WIDTH,SCREEN_HEIGHT,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Draw window
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);
glBegin(GL_QUADS);
glTexCoord2i(0, 1); glVertex2i(0,0);
glTexCoord2i(0, 0); glVertex2i(0, SCREEN_HEIGHT);
glTexCoord2i(1, 0); glVertex2i(SCREEN_WIDTH, SCREEN_HEIGHT);
glTexCoord2i(1, 1); glVertex2i(SCREEN_WIDTH, 0);
glEnd();
//Return from ortho view
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glFlush();
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
glDisable(GL_LIGHTING);
//glDisable(GL_DEPTH_TEST);
//Setup 2d ortho mode
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,SCREEN_WIDTH,SCREEN_HEIGHT,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Draw window
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, textures[TEX_MENU_HEADER].texID);
glBegin(GL_QUADS);
glTexCoord2i(0, 1); glVertex2i(0,0);
glTexCoord2i(0, 0); glVertex2i(0, SCREEN_HEIGHT);
glTexCoord2i(1, 0); glVertex2i(SCREEN_WIDTH, SCREEN_HEIGHT);
glTexCoord2i(1, 1); glVertex2i(SCREEN_WIDTH, 0);
glEnd();
//Return from ortho view
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glFlush();
Dustin Davis
Owner / CEO
Programmers Unlimited
www.Programmers-Unlimited.com
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement