Advertisement
Catachan

Glew Test Program

Feb 21st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. /*
  2.  * main.cpp
  3.  *
  4.  * This file is supposed to test whether or not
  5.  * my code actually works.
  6.  */
  7.  
  8. #include<iostream>
  9. #include<fstream>
  10. #include<string>
  11.  
  12. #include<GL/glew.h>
  13. #include<GL/glut.h>
  14.  
  15. class Pixel
  16. {
  17.     private:
  18.         int r;  //The Red value
  19.         int g;  //The Green value
  20.         int b;  //The Blue value
  21.  
  22.     public:
  23.         Pixel(): r(0), g(0), b(0)   {}
  24.         Pixel(int R, int G, int B): r(R), g(G), b(B) {}
  25.  
  26.         ~Pixel(){}
  27.        
  28.         void    setR(int R) {r = R;}
  29.         void    setG(int G) {g = G;}
  30.         void    setB(int B) {b = B;}
  31.  
  32.         const   int R() {return r;}
  33.         const   int G() {return g;}
  34.         const   int B() {return b;}
  35. };
  36.  
  37.  
  38. const void init()
  39. {
  40. #if DEBUG == 1
  41.     std::cerr << "Width = " << img.getWidth() << "  Height = " << img.getHeight() << std::endl;
  42. #endif
  43.  
  44.     glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );    
  45.     glutInitWindowPosition(0,0);           
  46.     glutInitWindowSize(640, 480);          
  47.     glutCreateWindow("GLEW TESTER");
  48.     glewInit();
  49.     gluOrtho2D(0,640,0,480);
  50.     glClearColor(0,0,0,0);
  51. }
  52.  
  53. const void drawSquare()
  54. {
  55.     int width = 640;
  56.     int height = 480;
  57.    
  58.     Pixel *pix = new Pixel[width * height];
  59.  
  60.     for(int i = 0; i < (width*height); i++)
  61.     {
  62.         pix[i].setR(i % (width / 256));
  63.         pix[i].setG(i % (height/ 256));
  64.         pix[i].setB(i % ((width * height) / 256));
  65.     }
  66.  
  67.     GLuint verts[][5] = {{0,0,0,0,0}, {width,0,0,width,0}, {width,height,0,width,height}, {0,height,0,0,height}};
  68.     GLuint *buf = new GLuint[5];
  69.    
  70.     std::cerr << "*buf declared." << std::endl;
  71.    
  72.     glGenBuffers(1, buf);
  73.     std::cerr << "Buffers generated." << std::endl;
  74.     glBindBuffer(GL_ARRAY_BUFFER, buf[0]);
  75.  
  76.     glBufferData(GL_ARRAY_BUFFER, 80, verts, GL_STREAM_DRAW);
  77.  
  78.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  79.  
  80.  
  81.    
  82.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_INT, pix);
  83. }
  84.  
  85.  
  86.  
  87.  
  88. const void draw()
  89. {
  90.     glClear(GL_COLOR_BUFFER_BIT);
  91.  
  92.     drawSquare();
  93.  
  94.     glutSwapBuffers();
  95. }
  96.  
  97.  
  98.  
  99. int main(int argc, char* argv[])
  100. {
  101.     std::cout << "int main(int argc, char* argv[])" << std::endl;
  102.  
  103.     glutInit(&argc, argv);
  104.     init();
  105.  
  106.     draw();
  107.  
  108.     //glutMainLoop();
  109.    
  110.     return 0;
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement