std :: cout << glGetString(GL_RENDER)<< std :: endl;引发错误,但不引发GL_Renderer或GL_Verision,我不知道为什么?

时间:2019-10-12 00:45:17

标签: c++ opengl visual-studio-2017

第一次在这里问一个问题,如果它的布局不正确或缺少某些东西,我会尽力使其他所有内容恢复正常。

我正在尝试学习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();


        };
    }

}

我希望它能告诉我渲染版本。我真正得到的是在std :: cout << glGetString(GL_RENDER)<< std :: endl;上产生错误。 :

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

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

并没有像我之前要求Gl_render那样渲染三角形

1 个答案:

答案 0 :(得分:1)

GL_RENDERER是有效的枚举,而GL_RENDER不是。参见OpenGL doc 谢谢Ripi2!我似乎不够努力:D