我正在尝试在 OpenGL 中使用顶点缓冲区对象(在 Code::Blocks 中),但显然您需要执行额外的步骤才能实际使用这些对象,因为我一直有“glGenBuffers 未在此范围内声明”错误,所以经过一番搜索后我发现您可以通过安装加载库来使用这些“扩展”功能:GLEW,它可以为您处理这些问题。
这就是我所做的:我下载了 GLEW Windows 二进制文件。将 glew32.dll 放在我的 Windows/System32 文件夹中,并将 glew32 添加到我的 MinGW 的 lib 文件夹中,并将包含添加到 MinGW 的包含文件夹中。为了安全起见,我还手动添加了 lib 的搜索目录并包含在 Code::Blocks 中。还在我的链接器选项中添加了“-lglew32”。
我已将 Glew 和 Glut 包括在内,如下所示:
#ifndef INCLUDES_H_INCLUDED
#define INCLUDES_H_INCLUDED
/* Main Header file that contains all the HEADER */
#include <windows.h>
//Some Main constants
#define PI 3.14159265
//Standard includes
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <vector>
#include <ctime>
using namespace std;
// Open GL and GLUT
#include <gl/glew.h>
#include <gl/glut.h>
/* Game Headers */
#include "Game.h"
#include "Functions.h"
#endif // INCLUDES_H_INCLUDED
就我而言,现在一切都应该正常工作,但是在编译时出现以下错误:
'GLAPI' does not name a type
我初始化 glut 和 glew 的主要功能
int main(int argc, char* args[])
{
// #1: GLUT window initialization
glutInit(&argc, args);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(width/2, height/2);
glutCreateWindow("OpenGL 3D Programming.");
//glutFullScreen(); //optional
// #2: Registering callbacks
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glewInit();
// #3: GLUT main loop
game.init(width, height);
glutMainLoop();
return 0;
}
Code::Blocks 中构建选项的完整列表
-lglu32
-lfreeglut
-lglew32
-lwinmm -lgdi32
-lmingw32 -lopengl32
-static-libgcc -static-libstdc++
我现在完全被卡住了,OpenGL 让我现在很难开始使用顶点缓冲区学习 OpenGL。有什么我做错了我错过了吗?
更新
好的,我现在有一些工作。我也将所有包含和库添加到 Code::Blocks/mingw 文件夹中(而不是“仅”C:/MinGW 文件夹)并且丢失了我的 GLAPI 错误。
目前我不确定它是否是一个防故障构建,因为我不太确定我使用的所有步骤,但现在它似乎正在工作。