为什么我总是使用 openGL 2.1 版?[openGL/SDL]
Why am I always on openGL version 2.1?[openGL/SDL]
我正在尝试将 openGL 与 SDL 一起使用,每当我在运行时检查我的版本时,它总是返回我使用的是 openGL 版本 2.1。现在据我了解,包括gl3.h为您提供了openGL的3.2+功能。除此之外,我特别要求 openGL 的 4.1 版本,并且显然仍在运行 2.1。有人可以告诉我我做错了什么吗?我正在运行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: %sn", 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: %sn", SDL_GetError() );
}
else
{
//creating new context
SDL_GL_CreateContext(window);
//GLuint vertexArrayID;
// glGenVertexArrays(1, &vertexArrayID);
SetOpenGLAttributes();
printf("%s", "This is your version");
printf("%sn", 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;
您在
创建上下文后调用SetOpenGLAttributes
。尝试在SDL_GL_CreateContext(window);
之前调用它。
相关文章:
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- 如何在使用 SDL 编写的游戏中仅实现一部分 OpenGL 代码?
- E/libEGL:调用没有当前上下文的 OpenGL ES API (每个线程记录一次) - Android/SDL
- 初始化多个纹理 OpenGL、SDL C++ 时出现问题
- 使用 OpenGL 窗口(如 GLFW)或周围的窗口(如 GTK 或 SDL)是否存在性能差异?
- 用SDL TTF显示带有SDL2和OpenGL的文本
- 即使 OpenGL、SDL 和 GLSL 都没有抛出错误,也没有绘制多边形
- 从SDL调色板表面(SDL_PIXELFORMAT_INDEX8)创建OpenGL纹理
- OpenGL + SDL + glew 在成功初始化后不会绘制任何内容
- SDL OpenGL:创建缓冲区时访问违规
- 在VIsual studio 2010 express中使用GLEW,SDL和OpenGL的未解析外部符号
- OpenGL SDL链接错误
- c++ OpenGL/SDL 2.0加载纹理失败
- 纹理渲染和 VBO 的 [OpenGL/SDL/C++]
- 使用openGL/SDL绘制点
- OpenGL SDL屏幕故障
- 有人可以清楚地解释这段代码的作用吗?- OpenGL & SDL
- 我的c++ OpenGL SDL程序不像我预期的那样工作
- 为什么我总是使用 openGL 2.1 版?[openGL/SDL]