forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSP-SDL-GL = Nightmare

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
nspmadero



Joined: 28 Aug 2009
Posts: 4

PostPosted: Sun Aug 30, 2009 9:40 am    Post subject: PSP-SDL-GL = Nightmare Reply with quote

I want to make a program that works the same in the PSP as in Windows, because it's faster to test something in windows than in PSP.

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:
/*
 * 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
}

and the make is
Code:
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

and i get the next errors:
Code:
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

If i use the PSP/Nehe makefile and add the SDL libraries & stuff added by $(shell $(SDL_CONFIG) --libs) i make it to compile & link withouth any error, but in the psp i only see the cursor and then it get freezed.

Any suggestion?
Back to top
View user's profile Send private message
KylBlz



Joined: 11 Feb 2009
Posts: 11

PostPosted: Mon Aug 31, 2009 3:27 am    Post subject: Hmm Reply with quote

I would re-install SDL or just use PSP-GL without SDL. Looks like a headder file that defined 'gluPerspectivef' is missing... also, in my makefile i have -lglut in my libs flags
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Mon Aug 31, 2009 5:29 pm    Post subject: Reply with quote

You should have a look at the JGE++ source code which does more or less what you are trying to do (and the JGE code for windows was probably created using the NeHe tutorials, actually).

The approcah is a bit different, in that the rendering engine uses openGL for windows and linux, and GU for the PSP.
When you use the library, you call upper level method names, so that you don't have to care (too much) if you are running on windows/linux or PSP

http://code.google.com/p/wagic/source/browse/trunk/JGE/src/JGfx.cpp
http://code.google.com/p/wagic/source/browse/trunk/JGE/src/win/JRenderer_Win.cpp
http://code.google.com/p/wagic/source/browse/trunk/JGE/src/linux/JGfx.cpp
Back to top
View user's profile Send private message
nspmadero



Joined: 28 Aug 2009
Posts: 4

PostPosted: Tue Sep 01, 2009 3:27 am    Post subject: Reply with quote

Thank you, JGE++ is ++ (object oriented), and I like my code bulky & messy :D

I was checking the OSLib thanks to other post, when i saw it in the devpack I though it was aimed to OS Development but it happend that is exactly what i need

It works like it says on PSP, but now I want to create the libs for windows using DevCPP. (wish me luck :D)
Back to top
View user's profile Send private message
mypspdev



Joined: 11 Jul 2007
Posts: 178

PostPosted: Thu Sep 10, 2009 6:33 am    Post subject: Re: PSP-SDL-GL = Nightmare Reply with quote

nspmadero wrote:
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.


All 10 NeHe lessons with GL are working and compiling well on PSP !!!
no problem at all!!

Let me know if you need the package with source code to be compiled...

ciao
Back to top
View user's profile Send private message
liberty



Joined: 16 Sep 2009
Posts: 35

PostPosted: Wed Oct 14, 2009 12:27 pm    Post subject: Re: PSP-SDL-GL = Nightmare Reply with quote

mypspdev wrote:
nspmadero wrote:
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.


All 10 NeHe lessons with GL are working and compiling well on PSP !!!
no problem at all!!

Let me know if you need the package with source code to be compiled...

ciao


Would u please share the package? I have problem running the lesson 1. The system freeze and then shutdown.
Back to top
View user's profile Send private message
mypspdev



Joined: 11 Jul 2007
Posts: 178

PostPosted: Wed Oct 14, 2009 8:39 pm    Post subject: Re: PSP-SDL-GL = Nightmare Reply with quote

liberty wrote:

Would u please share the package? I have problem running the lesson 1. The system freeze and then shutdown.


I'll do it, since next Saturday (17/10) I'll be out of my home for work reasons... far from my PSP development PC, I'll surely do it...
GL
SDL
SDL_gfx (RotoZoom and Primitives)
are, among others, within MyPSP dev environment (pspsdk).

..............You should have MP....
(with package and ready to be recompiled solutions ...)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group