第一次在这里问一个问题,所以如果它没有正确地布局,或者缺少一些东西,我会尝试把其他的东西都放上来。
我正在尝试学习OpenGl,因为我对开发自己的游戏很感兴趣,而且我更愿意创建自己的引擎,而不是已经存在的引擎。我也在使用GLEW,我知道它是init,因为代码不会输出错误
我花了一点时间在谷歌上搜索错误代码和OpenGL,但没有一个问题真正与我得到的相匹配。我也尝试了GLEW_Experimental = true,但这并没有改变任何事情。
代码: main
#include "src/graphics/window.h"
int main()
{
using namespace FutureGamingEngine;
using namespace graphics;
Window window("Test", 1080, 720);
glClearColor(0, 255, 0, 1.0f); //Red, Green, Blue, No Idea
std::cout << glGetString(GL_VERSION) << std::endl;
std::cout << glGetString(GL_RENDERER) << std::endl;
std::cout << glGetString(GL_RENDER) << std::endl;
while (!window.closed())
{
window.clear();
glBegin(GL_QUADS);
glVertex2f(-0.5f, -0.5f);
glVertex2f(-0.5f, 0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f,-0.5f);
glEnd();
window.update();
}
//system("PAUSE");
return 0;
}窗口:
#include "window.h"
namespace FutureGamingEngine
{
namespace graphics
{
void windowResize(GLFWwindow *window, int width, int height);
Window::Window(const char *title, int width, int height)
{
c_title = title;
c_height = height;
c_width = width;
if (!init())
{
glfwTerminate();
}
}
Window::~Window()
{
glfwTerminate();
}
bool Window::init()
{
glewExperimental = true;
if (!glfwInit())
{
std::cout << "Error Code: 0" << std::endl;
return false;
}
//Create a windowed mode and it's OpenGl Content
c_window = glfwCreateWindow(c_width, c_height, c_title, NULL, NULL);
//If we fail to make the window Terminate OpenGL
if (!c_window)
{
glfwTerminate();
return false;
}
//std::cout << "Open GL: " << glGetString(GL_VERSION) << std::endl;
glfwMakeContextCurrent(c_window);
glfwSetWindowSizeCallback(c_window, windowResize);
if (glewInit() != GLEW_OK)
{
std::cout << "Error Code: 1" << std::endl;
return false;
}
return true;
}
bool Window::closed() const
{
return glfwWindowShouldClose(c_window);
}
void Window::update()
{
//poll for and process events
glfwPollEvents();
glfwGetFramebufferSize(c_window, &c_width, &c_height);
//swap front and backbuffers
glfwSwapBuffers(c_window);
}
void Window::clear() const
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void windowResize(GLFWwindow *window, int width, int height)
{
glViewport(0, 0, width, height);
}
}
}窗口的标题:
#pragma once
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
namespace FutureGamingEngine
{
namespace graphics
{
class Window
{
private:
const char *c_title;
int c_width, c_height;
GLFWwindow *c_window;
bool c_closed;
public:
Window(const char *a_name, int a_width, int a_height);
~Window();
bool closed() const;
void update();
void clear() const;
inline int getHeight() const { return c_height; };
inline int getWidth() const { return c_width; };
private:
bool init();
};
}
}我希望它能告诉我渲染版本。我实际上得到的是std::cout << glGetString(GL_RENDER) << std::endl;上产生的错误:
在FutureGamingEngine-Core.exe: 0xC0000005中的0x7C50F6E0 (ucrtbased.dll)处引发异常:访问冲突读取位置0x00000000。
(https://i.imgur.com/uKu3hxX.png)
并且没有像我请求Gl_render之前那样渲染三角形
发布于 2019-10-12 09:43:56
GL_RENDERER是有效的枚举,而GL_RENDER不是。请看谢谢Ripi2!我显然看得不够仔细:D
https://stackoverflow.com/questions/58349908
复制相似问题