I have a trouble with pspgl on my psp. I tried to convert my program from sdl to sdl+pspgl. So, when my program reachs first gl function ( glMatrixMode(GL_PROJECTION) ), psp hangs up.
my example code:
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_opengl.h>
/*
#include <GL/gl.h>
#include <GL/glu.h>
*/
#include <math.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspthreadman.h>
#include <pspdisplay.h>
#include <pspnet_inet.h>
#include <pspnet.h>
#include <psputility.h>
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
/*
  Convert a HSV color to a RGB color.
  hsv_h must be from 0 to 360.
  hsv_s and hsv_v must be from 0 to 100.
  r_out, g_out and b_out will be set to a value from 0 to 255.
*/
void hsv_to_rgb(float hsv_h, float hsv_s, float hsv_v,
                float *const r_out,
                float *const g_out,
                float *const b_out)
{
  float f, p, q, t;
  float r = 0, g = 0, b = 0;
  /* Convert to a number in a 0..1 range. */
  hsv_s /= 100;
  hsv_v /= 100;
  f = hsv_h/60 - floor(hsv_h/60);
  p = hsv_v * (1.0 - hsv_s);
  q = hsv_v * (1.0 - f*hsv_s);
  t = hsv_v * (1.0 - (1.0 - f)*hsv_s);
  switch ((unsigned int)floor(hsv_h/60) % 6) {
  case 0:
    r = hsv_v; g = t; b = p;
    break;
  case 1:
    r = q; g = hsv_v; b = p;
    break;
  case 2:
    r = p; g = hsv_v; b = t;
    break;
  case 3:
    r = p; g = q; b = hsv_v;
    break;
  case 4:
    r = t; g = p; b = hsv_v;
    break;
  case 5:
    r = hsv_v; g = p; b = q;
    break;
  }
  *r_out = r;
  *g_out = g;
  *b_out = b;
}
void draw_win(unsigned int x, unsigned int y,
                unsigned int w, unsigned int h,
              unsigned int hsv_h, unsigned int hsv_s_in)
{
  float r, g, b;
  float hsv_s, hsv_s_step, hsv_v, hsv_v_step;
  /* A hsv_s zero value position. */
  float const hsv_s_zp = (float)3/4;
  float const white_line_w = 0.05*w;
  float const hsv_s_dh = (1.0 - hsv_s_zp)*((float)w - white_line_w);
  int Xi, Yi;
  w = (int)((float)hsv_s_zp*w) - white_line_w;
  hsv_v_step = (float)100/powf(w, 2);
  hsv_s_step = (float)hsv_s_in/powf(hsv_s_dh, 2);
  w += x;
  h += y;
  glBegin(GL_LINE_STRIP);
  hsv_s = hsv_s_in;
  for(Xi = x, hsv_v = 0;
    Xi < w;
      //    Xi++, hsv_v = hsv_v_step*powf(Xi - x, 2)) {
    Xi++, hsv_v = 100 - hsv_v_step*powf(w - Xi, 2)) {
    if ( (Xi - x) > (w - x - hsv_s_dh)) {
      //hsv_s = hsv_s_step*powf(w - Xi, 2);
      hsv_s = (float)hsv_s_in - hsv_s_step*powf(Xi - (w - x - hsv_s_dh) - x, 2);
    }
    hsv_to_rgb((double)hsv_h, hsv_s, hsv_v, &r, &g, &b);
    glColor3f(r, g, b);
    for(Yi = y; Yi < h; Yi++) {
      glVertex3i(Xi, Yi, 0);
    }
  }
  w += white_line_w;
  hsv_to_rgb((double)hsv_h, 0, 100, &r, &g, &b);
  glColor3f(r, g, b);
  for(; Xi < w; Xi++) {
    for(Yi = y; Yi < h; Yi++) {
      glVertex3i(Xi, Yi, 0);
    }
  }
  hsv_s_step = (float)(hsv_s_in*2/3)/powf(hsv_s_dh, 2);
  w += hsv_s_dh;
  for(; Xi < w; Xi++) {
    hsv_s = (float)hsv_s_in*2/3 - hsv_s_step*powf(w - Xi, 2);
    hsv_to_rgb((double)hsv_h, hsv_s, hsv_v, &r, &g, &b);
    glColor3f(r, g, b);
    for(Yi = y; Yi < h; Yi++) {
      glVertex3i(Xi, Yi, 0);
    }
  }
  glEnd();
}
void initgl(void)
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 480, 0, 272, -1, 1);
  //glFrustum(0, 480, 0, 272, 0.9999, 100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glViewport(0, 0, 480, 272);
  glClearColor(0.0, 0.0, 0.0, 0.0);
}
int SDL_main(void)
{
  SDL_Surface *scrn;
  but_t *but1, *but2;
  if ( SDL_Init(SDL_INIT_VIDEO) ) {
    fprintf(stderr, "Error: %s\n", SDL_GetError());
    return 1;
  }
  if ( TTF_Init() ) {
    fprintf(stderr, "TTF Error: %s\n", TTF_GetError());
    exit(1);
  }
  atexit(SDL_Quit);
  atexit(TTF_Quit);
  if ( !(scrn = SDL_SetVideoMode(480, 272, 32, SDL_OPENGL)) ) {
    fprintf(stderr, "Set video Error: %s\n", SDL_GetError());
    return 2;
  }
  initgl();
  glClear(GL_COLOR_BUFFER_BIT);
  draw_win(50, 100, 200 - 4, 100 - 4, 284, 92);
  SDL_GL_SwapBuffers();
  sceKernelSleepThreadCB();
  return 0;
}
Code: Select all
.PHONY: myclean
MOUNTDIR := /media/usbflash
DESTDIR := $(MOUNTDIR)/psp/game380/ogl_test
TARGET = ogl.c 
OBJS = ogl.o
PSP-PREF = $(shell psp-config --psp-prefix)
MEM_CONTROL = 2
MEM_CONTROL_LOG = 0
DEBUG = 0
ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG -g3 -ggdb
endif
CFLAGS += -O2 -G0 -Wall -I$(PSP-PREF)/include \
         $(shell $(PSP-PREF)/bin/sdl-config --cflags) \
        -DMEM_CONTROL=$(MEM_CONTROL) -DMEM_CONTROL_LOG=$(MEM_CONTROL_LOG)
LDFLAGS :=
LIBS =  -L$(PSP-PREF)/lib -L$(shell psp-config --pspsdk-path)/lib \
        -lconfig \
        -lSDL_ttf -lSDLmain -lSDL -lglut -lGLU -lGL \
        -lfreetype -lpspvfpu -lm -lpspgu -lpspaudio -lpspwlan \
        -lpsphprm -lpsprtc 
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
PSP_FW_VERSION = 380
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = ogl test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
myclean:
        rm -f *~
install: all
        mount $(MOUNTDIR)
        mkdir -p $(DESTDIR) || true
        cp EBOOT.PBP $(DESTDIR)/
        mkdir $(DESTDIR)/fonts && \
          cp /usr/share/fonts/truetype/freefont/Free{Sans,Serif}.ttf \
            $(DESTDIR)/fonts/ || \
          true
        umount $(MOUNTDIR)
sdl configure command: ./configure --host psp --prefix= $(psp-config --psp-prefix) --with-sdl-prefix=$(psp-config --psp-prefix) --enable-video-opengl
Firmware 3.90