据我所知,Macbook Air 2012支持OpenGL 3.2。但是,使用SDL 2.0创建OpenGL上下文时,上下文仅为opengl 2.1版。在OSX上使用SDL2创建OpenGL 3.x上下文(Macbook Air 2012)
SDL 2.0可以创建GL 3.2上下文吗?
据我所知,Macbook Air 2012支持OpenGL 3.2。但是,使用SDL 2.0创建OpenGL上下文时,上下文仅为opengl 2.1版。在OSX上使用SDL2创建OpenGL 3.x上下文(Macbook Air 2012)
SDL 2.0可以创建GL 3.2上下文吗?
大家谁还有这个问题,因为周三的10月10日,SDL2允许你创建在Mac上一个OpenGL 3.2上下文中运行的Mac OS X 10.7(狮子)及以上。 你只需要添加以下代码:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
如果你从
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
运行OS X 10.10,以上仍是解决方案不能解决问题,改变上述例子的第二行
到
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
可以为你工作。
#include <stdio.h>
#include <stdlib.h>
/* If using gl3.h */
/* Ensure we are using opengl's core profile only */
#define GL3_PROTOTYPES 1
#include <GL3/gl3.h>
#include <SDL.h>
#define PROGRAM_NAME "Tutorial1"
/* A simple function that prints a message, the error code returned by SDL,
* and quits the application */
void sdldie(const char *msg)
{
printf("%s: %s\n", msg, SDL_GetError());
SDL_Quit();
exit(1);
}
void checkSDLError(int line = -1)
{
#ifndef NDEBUG
const char *error = SDL_GetError();
if (*error != '\0')
{
printf("SDL Error: %s\n", error);
if (line != -1)
printf(" + line: %i\n", line);
SDL_ClearError();
}
#endif
}
/* Our program's entry point */
int main(int argc, char *argv[])
{
SDL_Window *mainwindow; /* Our window handle */
SDL_GLContext maincontext; /* Our opengl context handle */
if (SDL_Init(SDL_INIT_VIDEO) < 0) /* Initialize SDL's Video subsystem */
sdldie("Unable to initialize SDL"); /* Or die on error */
/* Request opengl 3.2 context.
* SDL doesn't have the ability to choose which profile at this time of writing,
* but it should default to the core profile */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
/* Turn on double buffering with a 24bit Z buffer.
* You may need to change this to 16 or 32 for your system */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
/* Create our window centered at 512x512 resolution */
mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (!mainwindow) /* Die if creation failed */
sdldie("Unable to create window");
checkSDLError(__LINE__);
/* Create our opengl context and attach it to our window */
maincontext = SDL_GL_CreateContext(mainwindow);
checkSDLError(__LINE__);
/* This makes our buffer swap syncronized with the monitor's vertical refresh */
SDL_GL_SetSwapInterval(1);
/* Clear our buffer with a red background */
glClearColor (1.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
/* Swap our back buffer to the front */
SDL_GL_SwapWindow(mainwindow);
/* Wait 2 seconds */
SDL_Delay(2000);
/* Same as above, but green */
glClearColor (0.0, 1.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(mainwindow);
SDL_Delay(2000);
/* Same as above, but blue */
glClearColor (0.0, 0.0, 1.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(mainwindow);
SDL_Delay(2000);
/* Delete our opengl context, destroy our window, and shutdown SDL */
SDL_GL_DeleteContext(maincontext);
SDL_DestroyWindow(mainwindow);
SDL_Quit();
return 0;
}
请注意,这需要SDL中的特殊支持,因为MacOSX的上下文创建API与3.2和2.1不同。 – 2012-08-15 01:08:19
啊,是的,我也看到了这个教程。使用精确的代码仍然会在OSX Mountain Lion的Air上生成OpenGL 2.1上下文。在我使用的几台Windows机器上(使用Nvidia和ATI卡),这会创建支持最高版本的环境(例如3.3)。 – 2012-08-15 01:11:49
@NicolBolas这就是我现在想知道的......这可能只是当前版本SDL的一个缺点。 – 2012-08-15 01:14:40
编辑:见https://stackoverflow.com/a/13095742/123387 - SDL2现在应该本身支持这一点。以下注释适用于最新的SDL2版本之前的版本。
目前的版本(如周三08月15日21时○○分33秒2012 -0400的; 6398:c294faf5fce5)不支持10.7系列。但是,如果您愿意运行不稳定的SDL进行踢球,则可以使用 添加支持。
给这一个镜头:
的src /视频/可可/ SDL_cocoaopengl.m +90(Cocoa_GL_CreateContext)
if(_this->gl_config.major_version == 3 && _this->gl_config.minor_version == 2) { attr[i++] = NSOpenGLPFAOpenGLProfile; attr[i++] = NSOpenGLProfileVersion3_2Core; }
然后在你的应用程序,这些方针的东西。
SDL_Init(SDL_INIT_EVERYTHING); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); window = SDL_CreateWindow("3.2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); context = SDL_GL_CreateContext(window);
我从2011年运行下我的Mac 10.7.4空,当我跑了几个GL从3.2 诊断SDL启用应用程序我得到:
Driver : cocoa Renderer : Intel HD Graphics 3000 OpenGL Engine Vendor : Intel Inc. Version : 3.2 INTEL-7.18.18 GLSL : 1.50
我没有测试过多少在此之外,但希望其他人可以 给它一个刺,并有一点成功。
编辑:如果你使用GLEW,你会想启用glewExperimental。 请注意,当您查询 GL_EXTENSIONS时,3.2核心配置文件中存在一个错误。它会报告1280(好像它不支持 ) - 但是这不会影响你使用1.50着色器 等等。
这应该做得很好,至少暂时。 – 2012-08-20 19:17:35
请参阅David Greiner的评论。 – 2012-11-09 23:21:08
谢谢你这个神奇的咒语! – 2014-11-15 02:03:49