双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

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

中国小码农 中国小码农 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
// 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库中的函数指针赋值而导致的,但是我不知道为什么会这样,求解惑。
...全文
评论 2
收藏 已收藏
分享
返回顶部