我正在尝试在 mac 上编写一个非常简单的 sdl 和 gl 程序来创建一个三角形,但它并没有真正起作用。
(在 C++ 中)
#include <iostream>
#include "SDL/SDL.h"
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
/*INITIALIZE*/
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,640.0/480.0,1.0,500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/*DISPLAY*/
void display() // drawing
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(0.0,2.0,-5.0);
glVertex3f(-2.0,-2.0,-5.0);
glVertex3f(2.0,-2.0,-5.0);
glEnd();
}
/*MAIN*/
int main(int argc, char** argv) // arguments required
{
SDL_Init(SDL_INIT_EVERYTHING); // initialize and setup sdl
SDL_Surface* screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_OPENGL);
bool running = true;
Uint32 start;
SDL_Event event;
init();
while (running)
{
start = SDL_GetTicks();
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
break;
}
}
display();
SDL_GL_SwapBuffers();
if(1000/30 > (SDL_GetTicks() - start))
SDL_Delay(1000/30 - (SDL_GetTicks() - start));
}
SDL_Quit();
return 0;
}
但是当我编译它时:
Computer:sdlcode User$ g++ third.cpp -GL -GLU
third.cpp: In function ‘int main(int, char**)’:
third.cpp:34: error: ‘SDL_OPENGL’ was not declared in this scope
third.cpp:34: error: ‘SDL_SetVideoMode’ was not declared in this scope
third.cpp:55: error: ‘SDL_GL_SwapBuffers’ was not declared in this scope
Computer:sdlcode User$
这里出了什么问题,如何防止它有未声明的进一步命令?