我的盒子:
john@zerofluID:~/Downloads$glxinfo | grep OpenGLOpenGL vendor string: NVIDIA CorporationOpenGL renderer string: GeForce GT 610/PCIE/SSE2OpenGL version string: 4.3.0 NVIDIA 313.30OpenGL shading language version string: 4.30 NVIDIA via Cg compilerOpenGL 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
(最新13.04 Ubuntu)
我有一个问题 – 在这里发布的代码太多了,但这是本书的第一个例子 – 尽可能小,我不知道问题究竟在哪里.如果有人真的想帮忙的话会很酷 – 我会把它反馈给这本书的作者.是的,LoadShader在其他地方被发现并且可能是问题,但它应该是一个解决方案.当我无法获得编译的第一个例子时,对书中有任何信心是很难的.
在这里能找到它:
https://github.com/kestess/opengl8thfirstexample.git
it’s way too much code to post here
并不是的.
试试这个:
#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,&len ); std::vector< char > log( len,'X' ); if( glisShader(obj) ) glGetShaderInfolog( obj,len,NulL,&log[0] ); if( glisProgram(obj) ) glGetProgramInfolog( obj,&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" #shaderconst 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.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,frag ); gluseProgram(program); glVertexAttribPointer(vposition,2,GL_float,GL_FALSE,(voID*)(0) ); glEnabLevertexAttribarray(vposition);}voID display(voID){ glClear(GL_color_BUFFER_BIT); glBindVertexArray(VAOs[Triangles]); glDrawArrays(GL_TRIANGLES,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();}
如果您使用#version 400核心,没有理由要求4.3上下文.
总结以上是内存溢出为你收集整理的c – OpenGL Red Book 8th – 第一个例子给出黑盒子(Ubuntu)全部内容,希望文章能够帮你解决c – OpenGL Red Book 8th – 第一个例子给出黑盒子(Ubuntu)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)