Advertisement
Guest User

Untitled

a guest
Aug 18th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <GL/glut.h>
  2.  
  3. #define WIDTH 640
  4. #define HEIGHT 480
  5.  
  6. unsigned int TEX_NAME;
  7.  
  8. unsigned char* tex_data;
  9.  
  10. void display();
  11.  
  12. int main(int argc, char** argv)
  13. {
  14.     glutInit(&argc, argv);
  15.  
  16.     glutInitWindowSize(WIDTH, HEIGHT);
  17.     glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  18.  
  19.     glutCreateWindow("A test thing");
  20.    
  21.     // Set all callback functions
  22.     glutDisplayFunc(display);
  23.  
  24.     // Set up opengl
  25.     glViewport(0, 0, WIDTH, HEIGHT);
  26.     glEnable(GL_TEXTURE_2D);
  27.     glClearColor(0.0f, 0.5f, 0.5f, 0.0f);
  28.  
  29.     glMatrixMode(GL_PROJECTION);
  30.     glLoadIdentity();
  31.     glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
  32.  
  33.     // Prepare texture-related nonsense
  34.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  35.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  36.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  37.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  38.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  39.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  40.  
  41.     tex_data = new unsigned char[WIDTH * HEIGHT * 4];
  42.  
  43.     for (int i = 0; i < WIDTH * HEIGHT * 4; i++) {
  44.         tex_data[i] = 0;
  45.     }
  46.    
  47.     glGenTextures(1, &TEX_NAME);
  48.     glBindTexture(GL_TEXTURE_2D, TEX_NAME);
  49.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
  50.  
  51.     glutMainLoop();
  52.  
  53.     return 0;
  54. }
  55.  
  56. void display()
  57. {
  58.     glClear(GL_COLOR_BUFFER_BIT);
  59.     glEnable(GL_TEXTURE_2D);
  60.  
  61.     glMatrixMode(GL_MODELVIEW);
  62.     glLoadIdentity();
  63.    
  64.     glBindTexture(GL_TEXTURE_2D, TEX_NAME);
  65.  
  66.     // Draw quad
  67.     glBegin(GL_QUADS);
  68.     glColor3f(1.0f, 1.0f, 1.0f);
  69.     glTexCoord2f(0.0f, 0.0f);
  70.     glVertex3f(0.0, 0.0, 0.0);
  71.     glTexCoord2f(1.0f, 0.0f);
  72.     glVertex3f(1.0, 0.0, 0.0);
  73.     glTexCoord2f(1.0f, 1.0f);
  74.     glVertex3f(1.0, 1.0, 0.0);
  75.     glTexCoord2f(0.0f, 1.0f);
  76.     glVertex3f(0.0, 1.0, 0.0);
  77.     glEnd();
  78.  
  79.     glutSwapBuffers();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement