Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

randomZ

OpenGL OpenGL Texture Mapping doesn't work

This topic is 5731 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

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:
  
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;
}
  
My display function:
  
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();
}
  
My main function:
  
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();
  }
}
  
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)

Share this post


Link to post
Share on other sites
Advertisement
youre not gonna see anything on screen if youre using a doublebuffered window
u will also need to swap buffers
ie remove the glFLush command + stick in a SDL_swapbuffers(..) or something like that


http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites

  • 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!