[英]C++ + SDL + OpenGL 3.3 doesn't work on Mac OS X?
I'm starting developing OpenGL 3 (I'm used to 1, so it's quite a change), and I'm using SDL as my windowing/image/sound/event-framework. 我正在开始开发OpenGL 3(我习惯于1,所以这是一个很大的改变),我正在使用SDL作为我的窗口/图像/声音/事件框架。 I have the following code(taken from opengl.org and slightly modified): 我有以下代码(取自opengl.org并稍加修改):
#include <stdio.h>
#include <stdlib.h>
/* If using gl3.h */
/* Ensure we are using opengl's core profile only */
#define GL3_PROTOTYPES 1
#include <OpenGL/gl3.h>
#include <SDL2/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
}
void render(SDL_Window* win){
glClearColor(1.0,0.0,0.0,1.0);
glClear ( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapWindow(win);
}
/* 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);
render(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;
}
And this works well. 这很好用。 But if I change this line: 但如果我改变这一行:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
To this: 对此:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
So it uses OpenGL 3.3 instead of 3.2, I get a EXC_BAD_ACCES
error on every single OpenGL call. 因此它使用OpenGL 3.3而不是3.2,我在每个OpenGL调用上都会出现EXC_BAD_ACCES
错误。 I do want to use OpenGL 3.3. 我确实想使用OpenGL 3.3。 My Computer: MacBook Pro retina late 2012 Mac OS X Mountain Lion Intel i7 2.7 GHz Intel HD 4000 NVidia GeForce G 我的电脑:MacBook Pro视网膜2012年末Mac OS X Mountain Lion Intel i7 2.7 GHz Intel HD 4000 NVidia GeForce G
Anyone knows wether this is a OS X error, a SDL error, or something wrong with my code? 任何人都知道这是OS X错误,SDL错误或我的代码有问题吗? (I know the SDL-code may not be the best, but it was originally SDL 1.2 code) (我知道SDL代码可能不是最好的,但最初是SDL 1.2代码)
because OSX only have opengl capabilities up to 3.2. 因为OSX只具有高达3.2的opengl功能 。
if you do SDL_GetError , it will tell you what is wrong. 如果你做SDL_GetError ,它会告诉你什么是错的。
Edit: OSX Mavericks (10.9) now supports 4.1. 编辑:OSX Mavericks(10.9)现在支持4.1。
OpenGL 3.3 and + is not available on OSX for now. 目前,OSX上还没有OpenGL 3.3和+。
However OpenGL 4.1 will be available on the latest OSX 10.9 Mavericks... so stay tuned :) 但是OpenGL 4.1将在最新的OSX 10.9 Mavericks上提供...所以请继续关注:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.