我尝试将我的Angel的书的Windows代码移植到Mac并且得到GLSL版本150不支持错误,我确信我的计算机支持,我将glGenVertexArrays()更改为glGenVertexArraysAPPLE()
我不知道为什么会这样返回错误?
void init(){
glGenBuffers( 3, buffers );
//Vertex buffer for the vertex coordinates
glBindBuffer( GL_ARRAY_BUFFER, buffers[cube_vertices] );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
//Elements buffer for the pointers
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffers[cube_indeces] );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffers[wire_indeces] );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices_wire), indices_wire, GL_STATIC_DRAW);
glGenVertexArraysAPPLE(2, VAO);
// Load shaders and use the resulting shader programs
program[0] = InitShader( "vshader30_TwoCubes_FullPipe.glsl", "fshader30_TwoCubes.glsl" );
program[1] = InitShader( "vshader30_TwoCubes_FullPipe.glsl", "fshader6_2.glsl" );
program[2] = InitShader( "vshader6_2.glsl", "fshader6_2.glsl" );
//VAO[0] the Cube
glUseProgram( program[0] );
glBindVertexArrayAPPLE(VAO[0]);
glBindBuffer( GL_ARRAY_BUFFER, buffers[cube_vertices] );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[cube_indeces]);
GLuint vPosition = glGetAttribLocation( program[0], "vPosition" );
glEnableVertexAttribArray( vPosition );
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
//done with this packet
glBindVertexArrayAPPLE(0);
//VAO[1] the wireframe
glUseProgram(program[1]);
glBindVertexArrayAPPLE(VAO[1]);
glBindBuffer( GL_ARRAY_BUFFER, buffers[cube_vertices] );
GLuint vPosition_Wire = glGetAttribLocation( program[1], "vPosition" );
glEnableVertexAttribArray( vPosition_Wire );
glVertexAttribPointer( vPosition_Wire, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[wire_indeces]);
//done with this packet
glBindVertexArrayAPPLE(0);
//glUseProgram(0);
glClearColor( 1.0, 1.0, 1.0, 0.0 );
glClearDepth( 1.0 );
glEnable( GL_DEPTH_TEST );
glDepthFunc(GL_LEQUAL);
glPolygonMode(GL_FRONT, GL_FILL);
}
void display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//Make sure you start with the Default Coordinate Systems
projmat=mat4(1.0);
modelviewStackTop = mat4(1.0);
mat4 modelviewStackBottom = modelviewStackTop;
//Set up the camera optics
projmat = projmat*Perspective(30,1.0,0.1,20.0);
//Position and orient the camera
modelviewStackTop = modelviewStackTop*LookAt(eye, eye-n, v);
modelviewStackTop = modelviewStackTop*Translate(0.15, 0.15, -2.5);
modelviewStackBottom = modelviewStackTop; //mvstack.push
//Render wireframe
glUseProgram(program[1]);
proj_loc = glGetUniformLocation(program[1], "projection");
model_view_loc = glGetUniformLocation(program[1], "modelview");
glUniformMatrix4fv(proj_loc, 1, GL_TRUE, projmat);
glUniformMatrix4fv(model_view_loc, 1, GL_TRUE, modelviewStackTop);
glBindVertexArrayAPPLE(VAO[1]);
glDrawElements(GL_LINES, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
modelviewStackTop = modelviewStackBottom; //mvstack.pop
modelviewStackBottom = modelviewStackTop; //mvstack.push
//Render surface mesh
glUseProgram(program[0]);
color_loc = glGetUniformLocation(program[0], "color");
proj_loc = glGetUniformLocation(program[0], "projection");
model_view_loc = glGetUniformLocation(program[0], "modelview");
glUniformMatrix4fv(proj_loc, 1, GL_TRUE, projmat);
glUniformMatrix4fv(model_view_loc, 1, GL_TRUE, modelviewStackTop);
glUniform4fv(color_loc, 1, green_transparent);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);
glBindVertexArrayAPPLE(VAO[0]);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
glDisable(GL_POLYGON_OFFSET_FILL);
modelviewStackTop = modelviewStackBottom; //mvstack.pop
//The glut cone
modelviewStackTop = modelviewStackTop*Translate(1.0, -1.0, -3.0);
glUseProgram(program[2]);
proj_loc = glGetUniformLocation(program[1], "projection");
model_view_loc = glGetUniformLocation(program[1], "modelview");
glUniformMatrix4fv(proj_loc, 1, GL_TRUE, projmat);
glUniformMatrix4fv(model_view_loc, 1, GL_TRUE, modelviewStackTop);
glutSolidCone(0.5, 3.0, 2, 3);
glutSwapBuffers();
}
答案 0 :(得分:2)
对于非核心上下文,OSX在OpenGL 2.1(#version 120
)上最高。
确保使用#version 150 core
并从GLUT请求核心上下文。