我想在mac上編寫一個非常簡單的sdl和gl程序來創建一個三角形,但它並不真正工作。SDL/OpenGL命令未在範圍內設置?
(在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$
打算請告訴我錯在這裏,我如何防止它有未申報的進一步的命令?
你在假設'g ++'是用'-GL'和'-GLU'標記做什麼的?你的意思是'-lGL'和'-lGLU'? – genpfault