gpt4 book ai didi

opengl - glewInit() 失败,OpenGL 应用程序

转载 作者:行者123 更新时间:2023-12-04 04:57:31 27 4
gpt4 key购买 nike

我正在尝试使用 glew/glfw 构建一个 OpenGL 应用程序。我已经下载了二进制文件,将它们放在文件夹的根目录中,将路径添加到 include 和 lib 目录,并告诉我的项目需要 glew32.lib、GLFW.lib 和 opengl32.lib。

我什至将glew32.lib复制到根目录,因为我的项目看不到它。

我必须将所有依赖项保留在项目目录中,因为我将分发它。我不知所措。

现在,当我运行我的程序时,它在 glewInit() 处失败

到目前为止,这是我的实现:

#include "Common.h"

GameEngine::GameEngine()
{
InitWithSize(1024, 768);
InitInput();
}

void GameEngine::InitWithSize(int _width, int _height)
{
try {
// Initialise GLFW
if( !glfwInit() )
throw std::exception("Failed to initialize GLFW\n");

//glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
if( !glfwOpenWindow( _width, _height, 0,0,0,0, 32,0, GLFW_WINDOW ) )
throw std::exception("Failed to initialize GLFW\n");


glfwSetWindowTitle( "Tutorial 01" );

// Initialize GLEW
if (glewInit() != GLEW_OK)
throw std::exception("Failed to initialize GLEW\n");


} catch ( std::system_error const& err) {
fprintf(stdout, "System Error: %s", err.what());
glfwTerminate(); // Free glfw if it has been allocated
// Try Again
this->InitWithSize(_width, _height);
} catch( std::exception const& err) {
fprintf(stdout, "Exception Found: %s", err.what());
} catch ( ... ) {
fprintf(stdout,"Unknown Exception Occurred\n");
}
}

void GameEngine::InitInput()
{
// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );
}

void GameEngine::StartGameLoop()
{
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 ) );
}


void GameEngine::InitTestData()
{
// 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,
};

}

使用我的通用标题:
#ifndef _COMMON_H
#define _COMMON_H

// OpenGL Libraries
#define GLEW_STATIC
//#pragma comment(lib, "glew32.lib")
#include <GL\glew.h>
#include <GL\glfw.h>

// Core Libraries
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <string>
#include <fstream>

// C++ 11 Libraries
#include <memory>
#include <exception>
#include <thread>
#include <chrono>

// Manager Classes
#include "ThreadManager.h"
#include "GameEngine.h"
#include "ShaderManager.h"

// Lesser Classes
#include "Shader.h"

#endif

最佳答案

我知道这个答案来得有点晚,但我没有看到您通过调用 glfwMakeContextCurrent(window) 来使 OpenGL 上下文成为最新的.在调用 glewInit() 之前,您必须这样做

关于opengl - glewInit() 失败,OpenGL 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13784233/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com