顶点阵列GLFW崩溃C 程序
Vertex Arrays GLFW crashes c++ program
我正在遵循GLFW上Internet的一个教程以制作一个简单的2D游戏。
我的程序被困在一个我必须创建一个顶点阵列以存储我的四边形顶点并将其绘制在屏幕上的点。但是我的程序崩溃了,在我生成以下异常
的情况下,我的程序崩溃了glfwtest.exe中的0x00000000 inthanded Exception:0xc0000005:访问 违规。
这是我的gamewindow.h文件
#include <iostream>
#include <GLglew.h>
#include <GLglfw.h>
class GameWindow{
private:
bool _running;
GLfloat _height;
GLfloat _width;
GLuint _vertexBufferID;
public:
void setRunning(bool nRunning);
bool getRunning();
GameWindow(bool running);
void Render();
void Update();
};
以下是我的gamewindow.cpp
的代码#include "GameWindow.h"
typedef struct{
GLfloat positionCoordinates[3];
}vertexData;
#define Square_Size 100
vertexData vertices[] = {
{0.0f,0.0f,0.0f},
{Square_Size,0.0f,0.0f},
{Square_Size,Square_Size,0.0f},
{0.0f,Square_Size,0.0f}
};
void GameWindow::setRunning(bool nRunning){
_running = nRunning;
}
bool GameWindow::getRunning(){
return _running;
}
GameWindow::GameWindow(bool running){
_running = running;
_height = 800;
_width = 800*16/9;
_vertexBufferID = 0;
glClearColor(1.0,1.0,1.0,1.0); //Set the initial screen to White
glViewport(0.0f,0.0f,_width, _height);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0,_width,0,_height);
glMatrixMode(GL_MODELVIEW);
//generate and make your vertex array ready for usage
glGenBuffers(1,&_vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER,_vertexBufferID);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);
//tells opengl to enable vertex array. Normally for other states we use glEnable
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(vertexData),(GLvoid*)offsetof(vertexData,positionCoordinates));
}
void GameWindow::Render(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glDrawArrays(GL_QUADS,0,4);
glfwSwapBuffers();
}
void GameWindow::Update(){
}
最后,这是我的主要
#include "GameWindow.h"
GameWindow *gameWindow;
int main(int argc,char** argv){
glfwInit();
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE,GL_TRUE);
glfwOpenWindow(640,480,8,8,8,8,0,0,GLFW_WINDOW);
gameWindow = new GameWindow(true);
while(gameWindow->getRunning()){
gameWindow->Render();
gameWindow->Update();
gameWindow->setRunning(glfwGetWindowParam(GLFW_OPENED));
}
delete gameWindow;
glfwTerminate();
}
另外,我的程序无法识别GlgenBuffers(..)说它是不确定的,我不得不添加GLEW库来解决问题,尽管在教程中,从未添加Glew库。我认为问题与Glew有关吗?但是我无法修复它!希望有GLFW经验的人可以提供一些帮助
在glwopenwindow之后呼叫glewInit ()
。
相关文章:
- 程序崩溃并显示"std::out_of_range"错误
- 试图创建流或fopen时程序崩溃
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 如何找出应用程序崩溃的原因 - Win 10 LTSB
- 操纵安卓相机的深度图导致应用程序崩溃
- 为什么当我尝试搜索双链表中第一个数据条目之外的数据时,程序崩溃了?
- DLL Made with CMake 使程序崩溃
- 程序崩溃使用boost::asio
- 调用 free() 有时会导致程序崩溃
- 邮件加密程序崩溃
- 调用 java 的回调() 时应用程序崩溃.由于 detatchThread 而获得运行时错误
- 比较迭代器会使程序崩溃,而不会在自定义气泡排序实现中出现错误
- For 循环在尝试读取数组 c++ 时程序崩溃
- 即使有 0 个错误,Getter 似乎也会使程序崩溃
- Windows桌面程序保存您的计算机会话 - 基于程序崩溃时的恢复会话
- 无法访问的代码如何导致我的程序崩溃?
- 矢量迭代器在尝试调用函数时使我的程序崩溃
- QCompleter set模型使应用程序崩溃
- 使用唯一指针调用函数会使我的程序崩溃
- 删除SDL_PollEvent时程序崩溃