Jump to content
  • Advertisement
Sign in to follow this  

SDL/OpenGL screen

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

Help when i add texture to my quad the screen only pops and close
but when i remove the texture function the quad screen would run.

i dont think there's problem with the code
and the lighting and color works fine! 
help i don't know what to do in this

here's the code
 

float angle = 0.0;
const int triangle = 1;

/*unsigned  int loadTexture(const char* filename)
{
        SDL_Surface* img = SDL_LoadBMP(filename);
        unsigned int id;
        glGenTextures(1, &id);
        glBindTexture(GL_TEXTURE_2D, id);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->w, img->h, 0, GL_RGB,GL_UNSIGNED_BYTE, img->pixels);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        SDL_FreeSurface(img);
        return id;
}
*/
unsigned int tex;

void init()
{
        glClearColor(0.0,0.0,0.0,1.0);  //background color and alpha
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45,640.0/480.0,1.0,500.0);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);
        //tex = loadTexture("brink.bmp");
}

void display()
{
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glTranslatef(0.0,0.0,-5.0);
        glRotatef(angle,1.0,1.0,1.0);   // angle, x-axis, y-axis, z-axis
        glBindTexture(GL_TEXTURE_2D, tex);
        glBegin(GL_QUADS);
                glTexCoord2f(0.0,2.0);
                glVertex3f(-2.0,2.0,0.0);
                glTexCoord2f(0.0,0.0);
                glVertex3f(-2.0,-2.0,0.0);
                glTexCoord2f(2.0,0.0);
                glVertex3f(2.0,-2.0,0.0);
                glTexCoord2f(2.0,2.0);
                glVertex3f(2.0,2.0,0.0);
        glEnd();
}
Edited by aspic

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!