Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Some Guy

SDL/GL tutorials: Compilation is an ugly word...

This topic is 6037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You've probably guessed it already: This Guy has compile problems with some code. Yeah, I'm that Guy. Some Guy. =) Anyway, I tried to compile the base code (slightly modified) from the SDL version of the tutorials. I tried to compile it with Mesa and gcc, mind you. Here's something like what I wrote (I actually had no comments except for a description header at the top of the file, and had many tabs for good allignment, but no other changes; this version is copied from Molofee's source code.):

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenGL/gl.h>	// Header File For The OpenGL32 Library
#include <OpenGL/glu.h>	// Header File For The GLu32 Library
#else
#include <GL/gl.h>	// Header File For The OpenGL32 Library
#include <GL/glu.h>	// Header File For The GLu32 Library
#endif
#include <SDL/SDL.h> //(Some Guy) Changed this from "SDL.h"

int done;
void InitGL (int w, int h);
void DrawGLScene();
void CheckEvents(); //a function I added (Some Guy)

/* A general OpenGL initialization function.  Sets all of the initial parameters. */
void InitGL(int Width, int Height)	        // We call this right after our OpenGL window is created.
{
  glViewport(0, 0, Width, Height);
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);		// This Will Clear The Background Color To Black
  glClearDepth(1.0);				// Enables Clearing Of The Depth Buffer
  glDepthFunc(GL_LESS);				// The Type Of Depth Test To Do
  glEnable(GL_DEPTH_TEST);			// Enables Depth Testing
  glShadeModel(GL_SMOOTH);			// Enables Smooth Color Shading

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();				// Reset The Projection Matrix

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);	// Calculate The Aspect Ratio Of The Window

  glMatrixMode(GL_MODELVIEW);
}

/* The main drawing function. */
void DrawGLScene()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer
  glLoadIdentity();				// Reset The View

  glTranslatef(-1.5f,0.0f,-6.0f);		// Move Left 1.5 Units And Into The Screen 6.0
	
  // draw a triangle
  glBegin(GL_POLYGON);				// start drawing a polygon
  glVertex3f( 0.0f, 1.0f, 0.0f);		// Top
  glVertex3f( 1.0f,-1.0f, 0.0f);		// Bottom Right
  glVertex3f(-1.0f,-1.0f, 0.0f);		// Bottom Left	
  glEnd();					// we're done with the polygon

  glTranslatef(3.0f,0.0f,0.0f);		        // Move Right 3 Units
	
  // draw a square (quadrilateral)
  glBegin(GL_QUADS);				// start drawing a polygon (4 sided)
  glVertex3f(-1.0f, 1.0f, 0.0f);		// Top Left
  glVertex3f( 1.0f, 1.0f, 0.0f);		// Top Right
  glVertex3f( 1.0f,-1.0f, 0.0f);		// Bottom Right
  glVertex3f(-1.0f,-1.0f, 0.0f);		// Bottom Left	
  glEnd();					// done with the polygon

  // swap buffers to display, since we're double buffered.
  SDL_GL_SwapBuffers();
}

void CheckEvents()
{  SDL_Event event;
   while ( SDL_PollEvent(&event) ) {
      if ( event.type == SDL_QUIT ) {
         done = 1;
      }
      if ( event.type == SDL_KEYDOWN ) {
         if ( event.key.keysym.sym == SDLK_ESCAPE ) {
            done = 1;
         }
      }
   }//end while(SDL_PollEvent...)
}

int main(int argc, char **argv) 
{  
  /* Initialize SDL for video output */
  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    exit(1);
  }

  /* Create a 640x480 OpenGL screen */
  if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) {
    fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
    SDL_Quit();
    exit(2);
  }

  /* Set the title bar in environments that support it */
  SDL_WM_SetCaption("Jeff Molofee's GL Code Tutorial ... NeHe '99", NULL);

  /* Loop, drawing and checking events */
  InitGL(640, 480);
  done = 0;
  while ( ! done ) {
    DrawGLScene();
    CheckEvents();
  }
  SDL_Quit();
  return 1;
}

  
Now, basically this is my slightly modified version of Molofee's source code released with the SDL tutorials. I simply made the variable done into a global variable, rather than a local one, and added a function called CheckEvents(), which is called towards the end of main(). I also changed #include "SDL.h" to #include <SDL/SDL.h>, because the former wouldn't compile on my Linux system. Apparently, gcc doesn't like something about this. I narrowed the error messages down, but a few remain like (off the top of my head):
In function main(...)
'exit' undeclared (first use this function)

In function InitGL(...)
'glViewPort' undeclared (first use this function)
  
That last one really bothers me. And here's what I wrote to compile it, in case you want to know:

$ gcc main.cpp -o first

  
Should work, but why isn't it finding either of these functions in the headers? Edited by - Some Guy on February 2, 2002 10:20:35 PM

Share this post


Link to post
Share on other sites
Advertisement
The "exit" function is in stdlib.h. The "glViewport" function doesn''t have the ''P'' capitalized. Also, you should be compiling with:

g++ main.cpp -o first `sdl-config --cflags --libs` -lGL -lGLU

The change of "gcc" to "g++" is all personal preference unless you need have C++ style linking.

Share this post


Link to post
Share on other sites
Now that I looked at your code (not just your error messages), I see that you did have glViewport with the correct capitalization. I''m not sure why it isn''t finding it; I''ll think over that one for a while...

Share this post


Link to post
Share on other sites
I might have actually written glViewPort (doh!). I'll look into it.

---EDIT---

Well, last night I looked into what I typed, and I did have the 'p' in glViewport capitalized.

I fixed that, but the code still wouldn't work. I'm having trouble now getting it to compile correctly on the command line.


$ g++ main.cpp -o first `sdl-config --cflags --libs` -lGL -lGLU


This does not work. So I try this:


$ g++ main.cpp -lGL -lGLU -lSDL -lpthread -o first


This is from the Cone3D tutorials on SDL and OpenGL, and it doesn't work either.

Would changing #include <SDL/SDL.h> back to #include "SDL.h" fix this problem?

Edited by - Some Guy on February 3, 2002 3:38:35 PM

Share this post


Link to post
Share on other sites
When I entered this:


g++ main.cpp -o first ''sdl-config --cflags --libs'' -lGL -GLU


like you told me to, I get this:


g++: sdl-config --cflags --libs: No such file or directory


What do I do?

Share this post


Link to post
Share on other sites
Are u sure you have libsdl1.2-dev (or some package with a name that looks like that one) installed?
Because it doesn''t look like...

Share this post


Link to post
Share on other sites
try adding "-L/usr/X11/lib" to somewhere near the beginning of the commandline. also you should be able to compile with just SDL.h rather than SDL/SDL.h. sdlconfig --cflags should set the include path properly so that just SDL.h (seems to be the standard) is enough.

Share this post


Link to post
Share on other sites
quote:
Original post by Some Guy
When I entered this:


g++ main.cpp -o first ''sdl-config --cflags --libs'' -lGL -GLU


like you told me to, I get this:


g++: sdl-config --cflags --libs: No such file or directory


What do I do?


You are using the wrong quotation marks. You use "straight" quotations marks ( '' ) when you should use "backqoutes" ( ` ) (see the difference).

straight quotations marks will cause the ''sdl-config --cflags --libs'' to be sent as one single argument to gcc (which assumes it is a filename since it doesn''t start with a ''-'' character). The backquotes will cause the command between them to execute and the output will be "pasted" into the commandline where the backquoted command was)

Share this post


Link to post
Share on other sites
Dactylos: Huh?

--EDIT--

Oh, oh... I understand (). I'll give it a shot.

Edited by - Some Guy on February 4, 2002 9:48:38 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!