簡體   English   中英

std::cout << glGetString(GL_RENDER) << std::endl; 拋出錯誤,但不是 GL_Renderer 或 GL_Verision,我不知道為什么?

[英]std::cout << glGetString(GL_RENDER) << std::endl; Throws an Error but not GL_Renderer or GL_Verision and I can't figure out why?

第一次在這里問一個問題,所以如果它沒有正確布局或缺少某些東西,我會嘗試把其他所有東西都整理好。

我正在嘗試學習 OpenGl,因為我對開發自己的游戲很感興趣,而且我寧願創建自己的引擎,而不是已經存在的引擎。 我也在使用 GLEW,我知道它是 inits,因為代碼沒有 output 錯誤

我在谷歌上搜索錯誤代碼和 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;
}

Window:

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

Header 用於 window:

#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 之前那樣渲染三角形

GL_RENDERER 是有效的枚舉,GL_RENDER 不是。 請參閱OpenGL 文檔謝謝 Ripi2:我顯然看起來不夠努力:D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM