2016-07-14 1 views
0

SDLでOpenGLを使用しようとしていて、実行時に私のバージョンをチェックすると常にopenGLバージョン2.1を使用しています。今gl3.hを含む私の理解には、OpenGLの3.2以上の機能を与えました。その点のほかに、私は特にOpenGLのバージョン4.1を求めていて、明らかに2.1を実行しています。誰かが私が間違っていることを教えてもらえますか?私はOSX Yosemiteを走っています。私はいつもopenGLバージョン2.1にいるのですか?[OpenGL/SDL]

#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; 
+0

'glGetString(GL_RENDERER)'はあなたに何を伝えますか? – datenwolf

+0

Intel Iris OpenGL Engine – user2905256

+2

コンテキストまたはウィンドウを作成する前に属性を設定する必要があります。 – keltar

答えて

4

コンテキストを作成した後、SetOpenGLAttributesに電話をかけています。 SDL_GL_CreateContext(window);の前に電話してみてください。

関連する問題