gpt4 book ai didi

c++ - std::cout << glGetString(GL_RENDER) << std::endl;抛出错误但不抛出 GL_Renderer 或 GL_Verision,我不知道为什么?

转载 作者:行者123 更新时间:2023-11-28 04:08:05 24 4
gpt4 key购买 nike

第一次在这里提问,所以如果布局不正确或缺少某些内容,我会尝试解决其他所有问题。

我正在尝试学习 OpenGl,因为我对开发自己的游戏很感兴趣,而且我宁愿创建自己的引擎也不愿创建现有的引擎。我也在使用 GLEW,我知道它是初始化的,因为代码没有输出错误

我在谷歌上搜索错误代码和 OpenGL 时花了一点时间,但没有一个问题与我得到的真正匹配。我也尝试了 GLEW_Experimental = true 但这并没有改变任何东西。

代码:主要

#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();


};
}

}

我希望它能告诉我渲染版本。我实际得到的是 Error Produced on std::cout << glGetString(GL_RENDER) << std::endl; :

在 FutureGamingEngine-Core.exe 中的 0x7C50F6E0 (ucrtbased.dll) 抛出异常:0xC0000005:访问冲突读取位置 0x00000000。

( https://i.imgur.com/uKu3hxX.png )

并且无法像在我请求 Gl_render 之前那样渲染三角形

最佳答案

GL_RENDERER 是有效枚举,GL_RENDER 不是。参见 OpenGL doc 谢谢瑞皮2!我显然看起来不够努力 :D

关于c++ - std::cout << glGetString(GL_RENDER) << std::endl;抛出错误但不抛出 GL_Renderer 或 GL_Verision,我不知道为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58349908/

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