I try to compile in PSP the lesson09.c of the great NeHe withouth any luck.
It works flawlessly in Windows using DevCPP as compiler.
Here's the code:
Code: Select all
/*
* This code was created by Jeff Molofee '99
* (ported to Linux/SDL by Ti Leggett '01)
*
* If you've found this code useful, please let me know.
*
* Visit Jeff at http://nehe.gamedev.net/
*
* or for port-specific comments, questions, bugreports etc.
* email to leggett@eecs.tulane.edu
*/
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
/* screen width, height, and bit depth */
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
#define SCREEN_BPP 24
#define NUM 50 // Number of stars
SDL_Surface *surface; // This is our SDL surface
int twinkle = 0; // Twinkling stars
typedef struct // Define the star structure
{
int r, g, b; // Stars Color
GLfloat dist; // Stars Distance From Center
GLfloat angle; // Stars Current Angle
} star;
star stars[NUM]; // Make an array of size 'NUM' of stars
GLfloat zoom = -15.0f; // Viewing Distance Away From Stars
GLfloat tilt = 90.0f; // Tilt The View
GLuint loop; // General Loop Variable
GLuint texture[1]; // Storage For One Texture
void Quit(int returnCode) // function to release/destroy our resources and restoring the old desktop
{
SDL_Quit( ); // clean up the window
exit( returnCode ); // and exit appropriately
}
void LoadGLTextures( ) // function to load in bitmap as a GL texture
{
SDL_Surface *TexImg[1]; // Create storage space for the texture
if ((TexImg[0] = SDL_LoadBMP( "data/star.bmp" ))) // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
{
glGenTextures(1, &texture[0]); // Create The Texture
// Load in texture
glBindTexture(GL_TEXTURE_2D, texture[0]); // Typical Texture Generation Using Data From The Bitmap
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Generate The Texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexImg[0]->w, TexImg[0]->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TexImg[0]->pixels);
SDL_FreeSurface(TexImg[0]); // Free up any memory we may have used
}
}
void handleKeyPress( SDL_keysym *keysym ) // function to handle key press events
{
switch ( keysym->sym )
{
case SDLK_ESCAPE: // ESC key was pressed
Quit( 0 );
break;
case SDLK_t: // 't' key was pressed
twinkle = !twinkle; // this toggles the twinkling of the stars
break;
case SDLK_UP: // Up arrow key was pressed
tilt -= 0.5f; // this changes the tilt of the stars
break;
case SDLK_DOWN: // Down arrow key was pressed
tilt += 0.5f; // this changes the tilt of the stars
break;
case SDLK_PAGEUP: // PageUp key was pressed
zoom -= 0.2f; // zoom into the scene
break;
case SDLK_PAGEDOWN: // PageDown key was pressed
zoom += 0.2f; // zoom out of the scene
break;
default:
break;
}
}
/* general OpenGL initialization function */
GLvoid initGL (GLsizei Width, GLsizei Height) // We call this right after our OpenGL window is created.
{
LoadGLTextures(); // Load in the texture
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the background black
glClearDepth(1.0f); // Depth buffer setup
glShadeModel(GL_SMOOTH); // Enable smooth 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);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Set The Blending Function For Translucency
glEnable(GL_BLEND); // Enable Blending
for (loop = 0;loop < NUM; loop++) // Create A Loop That Goes Through All The Stars
{
stars[loop].angle = 0.0f; // Start All The Stars At Angle Zero
stars[loop].dist = ((float)loop / NUM) * 5.0f; // Calculate Distance From The Center
stars[loop].r = rand() % 256; // Give star[loop] A Random Red Intensity
stars[loop].g = rand() % 256; // Give star[loop] A Random Green Intensity
stars[loop].b = rand() % 256; // Give star[loop] A Random Blue Intensity
}
}
GLvoid drawGLScene( GLvoid ) /* Here goes our drawing code */
{
static int spin = 0;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Clear The Screen And The Depth Buffer
glBindTexture( GL_TEXTURE_2D, texture[0] ); // Select Our Texture
glLoadIdentity( );
for ( loop = 0; loop < NUM; loop++ ) // Loop Through All The Stars
{
glLoadIdentity(); // Reset The View Before We Draw Each Star
glTranslatef( 0.0f, 0.0f, zoom ); // Zoom Into The Screen (Using The Value In 'zoom')
glRotatef( tilt, 1.0f, 0.0f, 0.0f ); // Tilt The View (Using The Value In 'tilt')
glRotatef( stars[loop].angle, 0.0f, 1.0f, 0.0f ); // Rotate To The Current Stars Angle
glTranslatef( stars[loop].dist, 0.0f, 0.0f ); // Move Forward On The X Plane
glRotatef( -stars[loop].angle, 0.0f, 1.0f, 0.0f ); // Cancel The Current Stars Angle
glRotatef( -tilt, 1.0f, 0.0f, 0.0f ); // Cancel The Screen Tilt
if (twinkle) // Twinkling Stars Enabled
{
glColor4ub(stars[(NUM - loop) - 1].r, stars[(NUM - loop) - 1].g, stars[(NUM - loop) - 1].b, 255); // Assign A Color Using Bytes
glBegin( GL_QUADS ); // Begin Drawing The Textured Quad
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 0.0f );
glEnd( );
}
glRotatef( spin, 0.0f, 0.0f, 1.0f ); // Rotate The Star On The Z Axis
glColor4ub( stars[loop].r, stars[loop].g, stars[loop].b, 255 ); // Assign A Color Using Bytes
glBegin( GL_QUADS ); // Begin Drawing The Textured Quad
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 0.0f );
glEnd( );
spin += 0.01f; // Used To Spin The Stars
stars[loop].angle += (float)loop / NUM; // Changes The Angle Of A Star
stars[loop].dist -= 0.01f; // Changes The Distance Of A Star
if (stars[loop].dist < 0.0f) // Is The Star In The Middle Yet
{
stars[loop].dist += 5.0f; // Move The Star 5 Units From The Center
stars[loop].r = rand() % 256; // Give It A New Red Value
stars[loop].g = rand() % 256; // Give It A New Green Value
stars[loop].b = rand() % 256; // Give It A New Blue Value
}
}
SDL_GL_SwapBuffers(); // Draw it to the screen
}
int main( int argc, char **argv )
{
int done = 0; // main loop variable
SDL_Event event; // used to collect events
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
// SDL_ShowCursor(SDL_DISABLE);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // the flags to pass to SDL_SetVideoMode
surface = SDL_SetVideoMode( // get a SDL surface
SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
SDL_OPENGL // Enable OpenGL in SDL
| SDL_GL_DOUBLEBUFFER // Enable double buffering
| SDL_HWPALETTE // Store the palette in hardware
| SDL_HWSURFACE
| SDL_HWACCEL);
initGL(SCREEN_WIDTH, SCREEN_HEIGHT); // initialize OpenGL
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); // Setup our viewport.
glMatrixMode(GL_PROJECTION); // change to the projection matrix and set our viewing volume.
glLoadIdentity();
gluPerspective(45.0f, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1f, 100.0f ); // Set our perspective
glMatrixMode(GL_MODELVIEW); // Make sure we're chaning the model view and not the projection
glLoadIdentity(); // Reset The View
while(!done) // wait for events
{
while(SDL_PollEvent(&event)) // handle the events in the queue
{
switch(event.type)
{
case SDL_KEYDOWN:
handleKeyPress( &event.key.keysym ); // handle key presses
break;
case SDL_QUIT:
done = 1; // handle quit requests
break;
default:
break;
}
}
drawGLScene(); // draw the scene
}
Quit(0); // clean ourselves up and exit
return(0); // Should never get here
}
Code: Select all
TARGET = lesson09
OBJS = lesson09.o
PSPSDK = $(shell psp-config --pspsdk-path)
PSPDEV = $(shell psp-config -d)
PSPBIN = $(PSPDEV)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config
CFLAGS = -fsingle-precision-constant -O2 -g -Wall
CFLAGS += $(shell $(SDL_CONFIG) --cflags)
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBS = -lgl -lglu -lpspvfpu $(shell $(SDL_CONFIG) --libs)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = lesson09
include $(PSPSDK)/lib/build.mak
Code: Select all
C:/pspsdk/psp/lib\libglu.a(gluPerspectivef.o): In function `gluPerspectivef':
C:\msys\home\Paulo\psptoolchain\devpaks\014_pspgl\pspgl/gluPerspectivef.c:30: undefined reference to `glMultMatrixf'
collect2: ld returned 1 exit status
make: *** [lesson09.elf] Error 1
Any suggestion?