Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Glew Test Program with Updates

By: Catachan on Feb 21st, 2012  |  syntax: C++  |  size: 3.09 KB  |  views: 101  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * main.cpp
  3.  *
  4.  * This file is supposed to test whether or not
  5.  * my code actually works.
  6.  *
  7.  * compiles with: g++ -g -Wall -Weffc++ -pedantic -lm -lglut -lGLEW -lGLU -lexpat main.cpp -o glewtester
  8.  * produces: int main(int argc, char* argv[])
  9.  *      GLEW SEEMS TO BE WORKING.  No error
  10.  *      EMERGENCY! glGenBuffers is not properly initialized!
  11.  *      glGetString(GL_RENDERER) = Mesa DRI Intel(R) 945GM GEM 20091221 2009Q4 x86/MMX/SSE2
  12.  *      0
  13.  *      *buf declared.
  14.  *      EMERGENCY! glGenBuffers is not properly initialized!
  15.  *      Segmentation fault
  16.  *
  17.  */
  18.  
  19. #include<iostream>
  20. #include<fstream>
  21. #include<string>
  22.  
  23. #include<GL/glew.h>
  24. #include<GL/glut.h>
  25.  
  26. class Pixel
  27. {
  28.         private:
  29.                 int     r;      //The Red value
  30.                 int     g;      //The Green value
  31.                 int     b;      //The Blue value
  32.  
  33.         public:
  34.                 Pixel(): r(0), g(0), b(0)       {}
  35.                 Pixel(int R, int G, int B): r(R), g(G), b(B) {}
  36.  
  37.                 ~Pixel(){}
  38.                
  39.                 void    setR(int R)     {r = R;}
  40.                 void    setG(int G)     {g = G;}
  41.                 void    setB(int B)     {b = B;}
  42.  
  43.                 const   int     R()     {return r;}
  44.                 const   int     G()     {return g;}
  45.                 const   int     B()     {return b;}
  46. };
  47.  
  48.  
  49. const void init()
  50. {
  51. #if DEBUG == 1
  52.         std::cerr << "Width = " << img.getWidth() << "  Height = " << img.getHeight() << std::endl;
  53. #endif
  54.  
  55.         glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );        
  56.         glutInitWindowPosition(0,0);                   
  57.         glutInitWindowSize(640, 480);                  
  58.         glutCreateWindow("GLEW TESTER");
  59.         gluOrtho2D(0,640,0,480);
  60.         glClearColor(0,0,0,0);
  61.         GLenum err = glewInit();
  62.         if(GLEW_OK != err)
  63.         {
  64.                 //GLEW Failed
  65.                 std::cerr << "ERROR STRING = " << glewGetErrorString(err) << std::endl;
  66.         }
  67.         else
  68.                 std::cerr << "GLEW SEEMS TO BE WORKING.  " << glewGetErrorString(err) << std::endl;
  69.         if(glGenBuffers == NULL)
  70.                 std::cerr << "EMERGENCY! glGenBuffers is not properly initialized!" << std::endl;
  71.  
  72.         std::cerr << "glGetString(GL_RENDERER) = " << glGetString(GL_RENDERER) << std::endl;
  73.         std::cerr << (int) glewGetExtension("ARB_vertex_buffer_object") << std::endl;
  74. }
  75.  
  76. const void drawSquare()
  77. {
  78.         int width = 640;
  79.         int height = 480;
  80.        
  81.         Pixel *pix = new Pixel[width * height];
  82.  
  83.         for(int i = 0; i < (width*height); i++)
  84.         {
  85.                 pix[i].setR(i % (width / 256));
  86.                 pix[i].setG(i % (height/ 256));
  87.                 pix[i].setB(i % ((width * height) / 256));
  88.         }
  89.  
  90.         GLuint verts[][5] = {{0,0,0,0,0}, {width,0,0,width,0}, {width,height,0,width,height}, {0,height,0,0,height}};
  91.         GLuint *buf = new GLuint[5];
  92.         GLsizei n = 1;
  93.  
  94.         std::cerr << "*buf declared." << std::endl;
  95.  
  96.         if(glGenBuffers == NULL)
  97.                 std::cerr << "EMERGENCY! glGenBuffers is not properly initialized!" << std::endl;
  98.  
  99.         glGenBuffers(n, buf);
  100.         std::cerr << "Buffers generated." << std::endl;
  101.         glBindBuffer(GL_ARRAY_BUFFER, buf[0]);
  102.  
  103.         glBufferData(GL_ARRAY_BUFFER, 80, verts, GL_STREAM_DRAW);
  104.  
  105.         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  106.  
  107.  
  108.        
  109.         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_INT, pix);
  110. }
  111.  
  112.  
  113.  
  114.  
  115. const void draw()
  116. {
  117.         glClear(GL_COLOR_BUFFER_BIT);
  118.  
  119.         drawSquare();
  120.  
  121.         glutSwapBuffers();
  122. }
  123.  
  124.  
  125.  
  126. int main(int argc, char* argv[])
  127. {
  128.         std::cout << "int main(int argc, char* argv[])" << std::endl;
  129.  
  130.         glutInit(&argc, argv);
  131.         init();
  132.  
  133.         draw();
  134.  
  135.         //glutMainLoop();
  136.        
  137.         return 0;
  138.  
  139. }
clone this paste RAW Paste Data