C++ + SDL + OpenGL 3.3 在 Mac OS X 上不起作用?
C++ + SDL + OpenGL 3.3 doesn't work on Mac OS X?
我正在开始开发OpenGL 3(我习惯了1,所以这是一个很大的变化),我正在使用SDL作为我的窗口/图像/声音/事件框架。我有以下代码(取自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: %sn", msg, SDL_GetError());
SDL_Quit();
exit(1);
}
void checkSDLError(int line = -1)
{
#ifndef NDEBUG
const char *error = SDL_GetError();
if (*error != ' ')
{
printf("SDL Error: %sn", error);
if (line != -1)
printf(" + line: %in", 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;
}
这很有效。但如果我更改这一行:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
对此:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
所以它使用OpenGL 3.3而不是3.2,我在每次调用OpenGL时都会得到一个EXC_BAD_ACCES
错误。我确实想使用OpenGL 3.3。我的电脑:2012年末MacBook Pro视网膜Mac OS X Mountain Lion英特尔i7 2.7 GHz英特尔HD 4000NVidia GeForce G
有人知道这是OS X错误、SDL错误还是我的代码有问题吗?(我知道SDL代码可能不是最好的,但它最初是SDL 1.2代码)
因为OSX只有高达3.2的opengl功能。
如果您执行SDL_GetError,它会告诉您哪里出了问题。
编辑:OSX小牛队(10.9)现在支持4.1。
OpenGL 3.3和+目前在OSX上不可用。
然而OpenGL 4.1将在最新的OSX 10.9 Mavericks上提供。。。请继续关注:)
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- GDB OS X Sierra 10.12.3不起作用
- Mac OS X 中的设置区域设置不起作用
- Makefile 在 mac os x Mavericks 上不起作用
- C++ + SDL + OpenGL 3.3 在 Mac OS X 上不起作用?
- GCC C/C++ MEX Matlab R2015 Mac OS X(带OpenMP)不起作用
- Boost ASIO IPv6 join_group在OS X上不起作用