红联Linux门户
Linux帮助

Linux SDL+OpenGL

发布时间:2006-12-26 01:11:44来源:红联作者:swallow
一、下载要SDL runtime 及 SDL develop library

rpm -i *****.rpm
rpm -i ****deve***.rpm
验证是否已安装成功:rpm -qa SDL

二、编写测试程序testsdl.cpp

#include
#include

void initGL()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(600,300,16,SDL_OPENGL);

}
void destroyGL()
{
SDL_Quit();
}
void draw()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);
glEnd();

SDL_GL_SwapBuffers();

}
bool running=true;
void quit()
{
running=false;
}
void loop()
{
SDL_Event event;
while(running)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
quit();
break;
}
}
draw();
SDL_Delay(50);
}

}
int main(int argc,char* argv[])
{
initGL();
loop();
destroyGL();
return 0;
}

三、编译运行:

输入命令行编译:g++ -o testsdl testsdl.cpp $(sdl-config --cflags --libs) -lGL
输入命令行运行:./testsdl
文章评论

共有 0 条评论