glew使用SDL2 2.0.5和glew 2.0.0缺少GL版本c ++

时间:2017-01-08 16:17:06

标签: c++ opengl glew

我正在关注OpenGL上的“使用Bens制作游戏”教程(https://www.youtube.com/user/makinggameswithben),我得到了这个

  

缺少gl版

每次我尝试初始化glew。
我已经多次重新安装了glew和SDL2 我不明白我做错了什么。

我正在使用glew 2.0.0和SDL2 2.0.5

headerfile:

#pragma once

#include <string>
#include <vector>

//Graphics
#include <SDL2\SDL.h>
#include <GL\glew.h>
class Display
{
public://functions:
    Display(int m_width, int m_heigth, const char title []);
    void update();
    ~Display();
private:

public://variables:
    std::vector<char> error;
    int width;
    int heigth;
private:
    //Window pointer
    SDL_Window * m_window;


};

.cpp文件:

#include "Display.h"    

Display::Display(int m_width, int m_heigth, const char title[])
{
    m_window = nullptr;
    width = m_width;
    heigth = m_heigth;
    //Initialize SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_heigth, SDL_WINDOW_OPENGL);
    //error 1:
    if (m_window = nullptr) {
        error.push_back(255);
    }
    //error 2:
    SDL_GLContext glContext = SDL_GL_CreateContext(m_window);
    if (glContext = nullptr) {
        error.push_back(254);
    }

    const GLenum GLerror = glewInit();
    //error 3:
    if (GLerror != GLEW_OK) {
        error.push_back(GLerror);
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}

void Display::update()
{
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    SDL_GL_SwapWindow(m_window);
}

Display::~Display()
{
    delete m_window;
    SDL_Quit();
}

1 个答案:

答案 0 :(得分:0)

您可能需要这样做:

glewExperimental = GL_TRUE;

之前

glewInit();

这将允许GLEW使用OpenGL 2.0版以上的OpenGL功能。

相关问题