简体   繁体   English

为什么我总是使用openGL 2.1版?[openGL / SDL]

[英]Why am I always on openGL version 2.1?[openGL/SDL]

I am trying to use openGL with SDL and whenever I check my version during runtime, it always returns that I am using openGL version 2.1. 我试图将openGL与SDL一起使用,并且每当我在运行时检查版本时,它总是返回我正在使用openGL 2.1版。 Now to my understanding including gl3.h gave you the 3.2+ functionality of openGL. 现在,据我所知,包括gl3.h给了您openGL的3.2+功能。 Besides that point I am specifically asking for version 4.1 of openGL and still apparently running 2.1. 除此之外,我还专门要求使用openGL的4.1版本,并且显然仍在运行2.1。 Can somebody please tell me what I am doing wrong? 有人可以告诉我我做错了吗? I am running OSX Yosemite. 我正在运行OSX Yosemite。

#include <iostream>
//Using SDL and standard IO
#include <SDL2/SDL.h>
#define GL_GLEXT_PROTOTYPES 1
//#include <SDL2/SDL_opengl.h>
#include <GLUT/glut.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <string.h>

#ifdef __APPLE__
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif


using namespace std;


//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;



bool SetOpenGLAttributes()
{
    // Set our OpenGL version.
    // SDL_GL_CONTEXT_CORE gives us only the newer version, deprecated functions are disabled
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    return true;
}



int main( int argc, char* args[] )
{
    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //Initialize SDL
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
    }
    else
    {
        //Create window
        window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL );
        if( window == NULL )
        {
            printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
        }
        else
        {

            //creating new context
            SDL_GL_CreateContext(window);

            //GLuint vertexArrayID;
            // glGenVertexArrays(1, &vertexArrayID);


            SetOpenGLAttributes();

            printf("%s", "This is your version");
            printf("%s\n", glGetString(GL_VERSION));

            SDL_GL_SetSwapInterval(1);
            glEnable(GL_DEPTH_TEST);



            SDL_GL_SwapWindow(window);

            bool running = true;
            while(running){
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glFlush();
                //drawCube(.5);
                SDL_GL_SwapWindow(window);
                SDL_Delay(17);

            }


        }
    }


    //Destroy window
    //SDL_DestroyWindow( window );

    //Quit SDL subsystems
    //SDL_Quit();

    return 0;

You are calling SetOpenGLAttributes after creating the context. 创建上下文后,您将调用SetOpenGLAttributes Try calling it before SDL_GL_CreateContext(window); 尝试在SDL_GL_CreateContext(window);之前调用它SDL_GL_CreateContext(window); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM