调用glewInit返回为真,glew库中函数指针还是没有被赋值

中国小码农 2014-11-04 06:01:39
// OpenGLFirstLesson.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "OpenGLFirstLesson.h"
#include <Windows.h>
#include <gl/glew.h>
#include <gl/glfw.h>

#pragma comment (lib,"GLFW.lib")
#pragma comment (lib,"GLFWDLL.lib")
#pragma comment (lib,"glew32.lib")
#pragma comment(lib,"OPENGL32.lib")

GLuint VertexArrayID;

// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if(!glfwInit())
{
return 0;
}

glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
glfwTerminate();
return -1;
}

//==================================
// Initialize GLEW
GLenum err;
bool glewExperimental=true; // Needed in core profile
if ((err = glewInit()) != GLEW_OK)
{
return -1;
}

const GLubyte *str = glGetString(GL_EXTENSIONS) ;

glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);

// This will identify our vertex buffer
GLuint vertexbuffer;

// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);

// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
//==================================

glfwSetWindowTitle( "OpenGL glfw 01" );

// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );


// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);

// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

glDisableVertexAttribArray(0);

do{
// Draw nothing, see you in tutorial 2 !

// Swap buffers
glfwSwapBuffers();

} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );

return 0;
}


在这里glfwOpenwindow()函数调用成功,glewInit()函数返回值等于GLEW_OK,但是

这里显示这样的错,我的理解是glewInit()函数并没有给glew库中的函数指针赋值而导致的,但是我不知道为什么会这样,求解惑。
...全文
831 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
openfnzh 2017-03-04
  • 打赏
  • 举报
回复
glewExperimental = GL_TRUE; if (glewInit())
IM131 2016-02-18
  • 打赏
  • 举报
回复
同求啊,我glewinit()返回一个0给我,蒙圈了

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧