Original Post
Hi; it''s been a while since I''ve posted a really dumb question here, so here I go again:
I''ve tried to use texture mapping in OpenGL, using the approach from the OpenGL RedBook (Ch. 9). However, if I start the program, nothing is drawn (the program stays in the main loop). Also, if I try to drag the window to a new position, the computer pauses for the fraction of a second, which doesn''t happen with normal OpenGL apps.
I''ve tried using either OpenGL through SDL and OpenGL through Windows API. Normal colored polygon painting works in both. Any obvious problem / mistake I could''ve make?
Some code:
My init function:
My display function:
My main function:
I know it''s a lot of code. I''m sorry. Since I don''t know where the mistake is, I can''t isolate it better...
"George W. Bush Geography Simplification Initiative"
My Homepage (C++ SDL OpenGL Game Programming)
bool initGfx(int width, int height, int cDepth, bool fullscreen)
{
height = height ? height : 1; // Prevent Division by zero (see below)
int flags; // The flags to pass to SDL_SetVideoMode()
if(!fullscreen)
flags = SDL_OPENGL;
else
flags = SDL_OPENGL | SDL_FULLSCREEN;
// Set the video mode
if(SDL_SetVideoMode(width, height,
cDepth, flags) == 0 )
{
cerr << "Video mode set failed: " << SDL_GetError() << "\n";
exit(EXIT_FAILURE);
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
&checkImage[0][0][0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0*(GLfloat)width/(GLfloat)height, 1.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.6);
return true;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0,-1.41421);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
// Initialize SDL Video
initGfx(640, 480, 32, false);
bool done = false;
while(!done)
{
// Code for done=true on quit event...
display();
}
}
"George W. Bush Geography Simplification Initiative"
My Homepage (C++ SDL OpenGL Game Programming)