Problem integrating OpenGL with SDL

Started by
5 comments, last by Biased turkey 22 years, 6 months ago
I can''t compile an example from the book " Programming Linux games". So far I had no problem at all for compiling the pure SDL programs, but now I had a lot them of the following type like: Undefined reference to GViewport Undefined reference to glClearColor etc... Obviously, there is some missing openGL ( or Mesa ) header file. The beginning of my source code is: /* Example of OpenGL rendering through SDL. */ #include #include #include #include And I compile the program with the following command ( as specified in the book: gcc XXXX.c -o XXXX `sdl-config --cflags --libs` -I/usr/X11R6/include -L/usr/X11R6/lib 1) The books says " furthermore, you need to compile your copy of SDL with OpenGL video support " How could I , I downloaded and installed the already compiled binary packaged, not the source 2) The missing header file is really in my system: I had the gl.h at /usr/include 3) I had Redhat 7.1 Thanks in advance for any opinion, suggestion or ... r.t.f.m
Advertisement
quote:Original post by Biased turkey
2) The missing header file is really in my system: I had the gl.h at /usr/include

gl.h should reside in a sub-directory called "gl" i.e. /usr/include/gl/gl.h
And you should include it with:

#include <gl/gl.h>

As a small aside: The 'recommended' way of including the SDL.h header is:

#include "SDL.h"

(according to www.libsdl.org)

You should also link to the gl and glu libs.
Add this to your command line when compiling:
   -lgl -lglu   

Or it could be:
   -lopengl -lglu   

I don't quite remember...

Edited by - Dactylos on October 17, 2001 4:58:13 AM
Sorry for the incomplete #include statements. It should have been:
#include
#include
#include
#include

I checked and the path for GL/gl.h is correct, I can see it and display the content of that file.
So, I''ll look for some other mistake I could have done.
I''ll try the -lgl command .
Thanks anyway.
Gee, I don''t know whats wrong with the special characters.
Let''s try it again:
SDL/SDL.h
GL/gl.h
stdio.h
stdlib.h
HTML encoding relies on < and > for tags. You should use the [source][/source] tags, or use &lt; and &gt; instead of < and >

[Resist Windows XP''s Invasive Production Activation Technology!]
To Dactylos: Thanks a bunch for your suggestion, The book never mentions looking for specific libraries ( in our case an OGL or a Mesa library ) BUT the first basic examples source codes and bitmaps included with the book are located in a directory that also includes a makefile for compiling the binaries. I didn''t use the makefile because I first want to get a little familiar with the gcc compiler( new to me ) and thus compiling " by hand " without any help. Yesterday night I had a look at that makefile and to my surprise there is a line that says:
OPENGL_LIB=-L/usr/X11R6/include -lGL.
So as you suggested I added missing -lGL to the command line and ..voila, no more error at compiling time and I get an executable .
Now, when I run the executable, instead of having a colored 3D triangle ( as written in the book ) I have a frozen blue window that also freezes the whole system, like a blue screen of death . I didn''t know Linux Redhat 7.1 includes a Win98n emulator

But I shouldn''t complaint, at least now the program compiles OK.

To Null and Void: thanks for the tip about HTML tags.
I''ve had a similar problem with that particular listing, it doesnt crash the machine though...
Other than that I am very pleased with the rest of the book.

If you want to see more in-depth examples of SDL and OpenGL working together
check out the SDL ports of the NeHe demos, just go to www.libsdl.org/opengl/intro.html
they are written in C and I think they have up to Lesson 30 included. after 30 You have to
look under the demos for the various ports. They all compile without a problem and show
up as they should on screen.


This topic is closed to new replies.

Advertisement