Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL/OpenGL screen


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 aspic   Members   -  Reputation: 106

Like
0Likes
Like

Posted 28 October 2013 - 08:27 PM

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, 28 October 2013 - 08:33 PM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS