SDL2做为OpenGL的窗口程序,其接入程序为:
#include
#include
#include
#include
#include
#include
#include
// 控制显示的帧渲染
bool quit;
SDL_Window* window;
SDL_GLContext glContext;
SDL_Event sdlEvent;
// 窗口的尺寸
const GLuint WIDTH = 1280, HEIGHT = 720;
int main(int argc, char *argv[])
{
quit = false;
//将openGL设置为3.1 core
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
// Display error message
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return -1;
}
else
{
// Create window
window = SDL_CreateWindow("Hello World!"

这篇博客详细介绍了如何利用SDL2库创建一个OpenGL渲染的窗口程序,内容涵盖SDL2的基本用法和OpenGL的结合,适合想要学习游戏开发或图形编程的读者。
最低0.47元/天 解锁文章
962

被折叠的 条评论
为什么被折叠?



