Hello there, Im quite new to OpenGL and SDL, I have some code from a friend which works 100% but when i paste it into a new program it doesnt find SDL,
Im using Fedora 15 Eclipse, i have OpenGL and SDL installed.
here is my code
#define GLEW_STATIC // Easier debugging
#include <GL/glew.h>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <iostream>
#include <fstream>
using namespace std;
#define RUN_GRAPHICS_DISPLAY 0x00;
/*
- SDL timers run in separate threads. In the timer thread
- push an event onto the event queue. This event signifies
- to call display() from the thread in which the OpenGL
- context was created.
*/
Uint32 display(Uint32 interval, void *param) {
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = RUN_GRAPHICS_DISPLAY;
event.user.data1 = 0;
event.user.data2 = 0;
SDL_PushEvent(&event);
return interval;
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Don’t forget to swap the buffers
SDL_GL_SwapBuffers();
}
int main(int argc, char ** argv) {
SDL_Surface * surf;
Uint32 width = 640;
Uint32 height = 480;
Uint32 colour_depth = 16; // in bits
Uint32 delay = 1000/60; // in milliseconds
// Initialise SDL - when using C/C++ it's common to have to
// initialise libraries by calling a function within them.
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)<0) {
cout << "Failed to initialise SDL: " << SDL_GetError() << endl;
SDL_Quit();
}
// When we close a window quit the SDL application
atexit(SDL_Quit);
// Create a new window with an OpenGL surface
if (!(surf = SDL_SetVideoMode(width, height, colour_depth, SDL_OPENGL))) {
cout << "Failed to initialise video mode: " << SDL_GetError() << endl;
SDL_Quit();
}
// Initialise GLEW - an easy way to ensure OpenGl 2.0+
// The *must* be done after we have set the video mode - otherwise we have no OpenGL context.
glewInit();
if (!glewIsSupported("GL_VERSION_2_0")) {
cerr<< "OpenGL 2.0 not available" << endl;
return 1;
}
// Call the function "display" every delay milliseconds
SDL_AddTimer(delay, display, NULL);
// Add the main event loop
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
SDL_Quit();
break;
case SDL_USEREVENT:
display();
}
}
}
Error codes
**** Build of configuration Debug for project DurianSoftware-Chapter2 ****
make all
Building file: …/Main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Main.d" -MT"Main.d" -o"Main.o" “…/Main.cpp”
Finished building: …/Main.cpp
Building target: DurianSoftware-Chapter2
Invoking: Cross G++ Linker
g++ -o"DurianSoftware-Chapter2" ./Main.o
./Main.o: In function display(unsigned int, void*)': /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:24: undefined reference to
SDL_PushEvent’
./Main.o: In function display()': /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:29: undefined reference to
glClearColor’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:30: undefined reference to glClear' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:33: undefined reference to
SDL_GL_SwapBuffers’
./Main.o: In function main': /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:45: undefined reference to
SDL_Init’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:46: undefined reference to SDL_GetError' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:47: undefined reference to
SDL_Quit’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:51: undefined reference to SDL_Quit' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:54: undefined reference to
SDL_SetVideoMode’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:55: undefined reference to SDL_GetError' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:56: undefined reference to
SDL_Quit’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:61: undefined reference to glewInit' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:62: undefined reference to
glewIsSupported’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:68: undefined reference to SDL_AddTimer' /home/ben/workspace/DurianSoftware-Chapter2/Debug/../Main.cpp:75: undefined reference to
SDL_Quit’
/home/ben/workspace/DurianSoftware-Chapter2/Debug/…/Main.cpp:72: undefined reference to `SDL_WaitEvent’
collect2: ld returned 1 exit status
make: *** [DurianSoftware-Chapter2] Error 1
But i have a openGL program that draws 4 cubes and has the same main (nearly). I can give the code if you would like. but my question is how come my program doesnt find SDL???
Mr_Approved
P.S. i do also understand this is the openGL forums but i wanted to ask here first as i have more openGL questions to ask at a later date