/* * main.cpp * * This file is supposed to test whether or not * my code actually works. * * compiles with: g++ -g -Wall -Weffc++ -pedantic -lm -lglut -lGLEW -lGLU -lexpat main.cpp -o glewtester * produces: int main(int argc, char* argv[]) * GLEW SEEMS TO BE WORKING. No error * EMERGENCY! glGenBuffers is not properly initialized! * glGetString(GL_RENDERER) = Mesa DRI Intel(R) 945GM GEM 20091221 2009Q4 x86/MMX/SSE2 * 0 * *buf declared. * EMERGENCY! glGenBuffers is not properly initialized! * Segmentation fault * */ #include #include #include #include #include class Pixel { private: int r; //The Red value int g; //The Green value int b; //The Blue value public: Pixel(): r(0), g(0), b(0) {} Pixel(int R, int G, int B): r(R), g(G), b(B) {} ~Pixel(){} void setR(int R) {r = R;} void setG(int G) {g = G;} void setB(int B) {b = B;} const int R() {return r;} const int G() {return g;} const int B() {return b;} }; const void init() { #if DEBUG == 1 std::cerr << "Width = " << img.getWidth() << " Height = " << img.getHeight() << std::endl; #endif glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA ); glutInitWindowPosition(0,0); glutInitWindowSize(640, 480); glutCreateWindow("GLEW TESTER"); gluOrtho2D(0,640,0,480); glClearColor(0,0,0,0); GLenum err = glewInit(); if(GLEW_OK != err) { //GLEW Failed std::cerr << "ERROR STRING = " << glewGetErrorString(err) << std::endl; } else std::cerr << "GLEW SEEMS TO BE WORKING. " << glewGetErrorString(err) << std::endl; if(glGenBuffers == NULL) std::cerr << "EMERGENCY! glGenBuffers is not properly initialized!" << std::endl; std::cerr << "glGetString(GL_RENDERER) = " << glGetString(GL_RENDERER) << std::endl; std::cerr << (int) glewGetExtension("ARB_vertex_buffer_object") << std::endl; } const void drawSquare() { int width = 640; int height = 480; Pixel *pix = new Pixel[width * height]; for(int i = 0; i < (width*height); i++) { pix[i].setR(i % (width / 256)); pix[i].setG(i % (height/ 256)); pix[i].setB(i % ((width * height) / 256)); } GLuint verts[][5] = {{0,0,0,0,0}, {width,0,0,width,0}, {width,height,0,width,height}, {0,height,0,0,height}}; GLuint *buf = new GLuint[5]; GLsizei n = 1; std::cerr << "*buf declared." << std::endl; if(glGenBuffers == NULL) std::cerr << "EMERGENCY! glGenBuffers is not properly initialized!" << std::endl; glGenBuffers(n, buf); std::cerr << "Buffers generated." << std::endl; glBindBuffer(GL_ARRAY_BUFFER, buf[0]); glBufferData(GL_ARRAY_BUFFER, 80, verts, GL_STREAM_DRAW); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_INT, pix); } const void draw() { glClear(GL_COLOR_BUFFER_BIT); drawSquare(); glutSwapBuffers(); } int main(int argc, char* argv[]) { std::cout << "int main(int argc, char* argv[])" << std::endl; glutInit(&argc, argv); init(); draw(); //glutMainLoop(); return 0; }