c++ - OpenGL Red Book 8th - First Example gives black box (Ubuntu) -


after getting first example program compiled 8th edition opengl programming guide after many alterations suggested many sites, proud owner of black box - vast improvement hours before, it's embarrassing admit i've watch of debugger , unless basic wrong program, have no clue look. other opengl examples have run, i'm trying first example in new book run.

my box:

john@zerofluid:~/downloads$ glxinfo | grep opengl opengl vendor string: nvidia corporation opengl renderer string: geforce gt 610/pcie/sse2 opengl version string: 4.3.0 nvidia 313.30 opengl shading language version string: 4.30 nvidia via cg compiler opengl extensions: 

linux zerofluid 3.8.0-26-generic #38-ubuntu smp mon jun 17 21:43:33 utc 2013 x86_64 x86_64 x86_64 gnu/linux (latest 13.04 ubuntu)

i have problem - it's way code post here, first example of book - small gets , have no idea of problem is. cool if wants - i'd feed author of book. yes, loadshader found elsewhere , might problem, supposed solution. it's kind of hard have faith in book when can't first example compile.

it can found here: https://github.com/kestess/opengl8thfirstexample.git

it's way code post here

not really.

try this:

#include <gl/glew.h> #include <gl/freeglut.h> #include <vector> #include <iostream>  struct program {     static gluint load( const char* vert, const char* geom, const char* frag )     {         gluint prog = glcreateprogram();         if( vert ) attachshader( prog, gl_vertex_shader, vert );         if( geom ) attachshader( prog, gl_geometry_shader, geom );         if( frag ) attachshader( prog, gl_fragment_shader, frag );         gllinkprogram( prog );         checkstatus( prog );         return prog;     }  private:     static void checkstatus( gluint obj )     {         glint status = gl_false, len = 10;         if( glisshader(obj) )   glgetshaderiv( obj, gl_compile_status, &status );         if( glisprogram(obj) )  glgetprogramiv( obj, gl_link_status, &status );         if( status == gl_true ) return;         if( glisshader(obj) )   glgetshaderiv( obj, gl_info_log_length, &len );         if( glisprogram(obj) )  glgetprogramiv( obj, gl_info_log_length, &len );         std::vector< char > log( len, 'x' );         if( glisshader(obj) )   glgetshaderinfolog( obj, len, null, &log[0] );         if( glisprogram(obj) )  glgetprograminfolog( obj, len, null, &log[0] );         std::cerr << &log[0] << std::endl;         exit( -1 );     }      static void attachshader( gluint program, glenum type, const char* src )     {         gluint shader = glcreateshader( type );         glshadersource( shader, 1, &src, null );         glcompileshader( shader );         checkstatus( shader );         glattachshader( program, shader );         gldeleteshader( shader );     } }; #define glsl(version, shader) "#version " #version "\n" #shader   const char* vert = glsl (      400 core,     layout( location = 0 ) in vec4 vposition;     void main()     {         gl_position = vposition;     } );  const char* frag = glsl (      400 core,     out vec4 fcolor;     void main()     {         fcolor = vec4( 0.0, 0.0, 1.0, 1.0 );     } );  enum vao_ids { triangles, numvaos }; enum buffer_ids { arraybuffer, numbuffers }; enum attrib_ids { vposition = 0 };  gluint vaos[numvaos]; gluint buffers[numbuffers];  const gluint  numvertices = 6;  void init(void) {     glgenvertexarrays(numvaos, vaos);     glbindvertexarray(vaos[triangles]);      glfloat  vertices[numvertices][2] = {         { -0.90, -0.90 },  // triangle 1         {  0.85, -0.90 },         { -0.90,  0.85 },         {  0.90, -0.85 },  // triangle 2         {  0.90,  0.90 },         { -0.85,  0.90 }     };      glgenbuffers(numbuffers, buffers);     glbindbuffer(gl_array_buffer, buffers[arraybuffer]);     glbufferdata(gl_array_buffer, sizeof(vertices), vertices, gl_static_draw);      gluint program = program::load( vert, null, frag );     gluseprogram(program);      glvertexattribpointer(vposition, 2, gl_float, gl_false, 0, (void*)(0) );     glenablevertexattribarray(vposition); }  void display(void) {     glclear(gl_color_buffer_bit);      glbindvertexarray(vaos[triangles]);     gldrawarrays(gl_triangles, 0, numvertices);      glutswapbuffers(); }  int main(int argc, char** argv) {      glutinit(&argc, argv);      glutinitdisplaymode( glut_rgba | glut_double );      glutinitwindowsize(512, 512);      glutinitcontextversion(4, 0);      glutinitcontextprofile(glut_core_profile);      glutcreatewindow(argv[0]);       glewexperimental = gl_true;      if( glew_ok != glewinit() )          exit(exit_failure);       init();       glutdisplayfunc(display);      glutmainloop(); } 

no reason request 4.3 context if you're using #version 400 core.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -