 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Wed Sep 23, 2009 10:42 pm Post subject: [pspgl + sdl] psp hangs up |
|
|
Hi all.
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: |
#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;
}
|
Makefile:
| Code: |
.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)
|
pspsdk - rev 2473
sdl configure command: ./configure --host psp --prefix= $(psp-config --psp-prefix) --with-sdl-prefix=$(psp-config --psp-prefix) --enable-video-opengl
Firmware 3.90 |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Sep 24, 2009 2:33 am Post subject: |
|
|
| PSPGL uses the vfpu. Add THREAD_ATTR_VFPU to the thread attributes. |
|
| Back to top |
|
 |
iceman755
Joined: 21 Jul 2008 Posts: 34
|
Posted: Thu Sep 24, 2009 2:54 am Post subject: |
|
|
I had to make a lot of changes to compile this, so I don't know if this is the solution for you, but it doesn't worked until I add PSP_HEAP_SIZE_KB(-1024);
I think I'm using a newer SDK than yours, in the main.c changes aren't a lot, but the makefile is completely different:
| Code: | #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_MODULE_INFO("zOpenGL",THREAD_ATTR_USER, 3, 5); //added
//PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER); //comented
PSP_HEAP_SIZE_KB(-1024); //added
#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 main(void) //changed from SDL_main to main
{
SDL_Surface *scrn;
//but_t *but1, *but2; //comented
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;
} |
And the makefile:
| Code: | TARGET = zgl
OBJS = main.o
PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(shell psp-config —psp-prefix)/bin
CFLAGS = -O2 -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBS = -lSDL_ttf -lfreetype -lSDL_gfx -lSDL_image -ljpeg -lpng -lz -lm -lSDL -lGL -lpspvfpu -lpsphprm -lpspaudio -lpspgu
LDFLAGS =
BUILD_PRX =1
PSP_FW_VERSION = 500
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = OpenGL
PSP_LARGE_MEMORY = 1
include $(PSPSDK)/lib/build.mak |
_________________ "Libera eas de ore leonis, ne absorbeat eas tartarus, ne cadant in obscurum" |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Sat Sep 26, 2009 2:10 am Post subject: |
|
|
| J.F. wrote: | | PSPGL uses the vfpu. Add THREAD_ATTR_VFPU to the thread attributes. |
Still hangs up... |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Sat Sep 26, 2009 2:13 am Post subject: |
|
|
| iceman755 wrote: | I had to make a lot of changes to compile this, so I don't know if this is the solution for you, but it doesn't worked until I add PSP_HEAP_SIZE_KB(-1024);
I think I'm using a newer SDK than yours, in the main.c changes aren't a lot, but the makefile is completely different:
|
I have the latest sdk from the svn. I've updated my firmware to 5.00M33-6 and compile your code. So, psp hangs up the same way as with my code.
:-( |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Sun Sep 27, 2009 3:38 am Post subject: |
|
|
| Some new information. Pure OpenGL programs are compiled nice. |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Mon Sep 28, 2009 12:51 am Post subject: |
|
|
I've tried to debug the program. This is a gdb output:
| Code: |
(gdb) continue
Continuing.
[New Thread 77048945]
Program received signal SIGBUS, Bus error.
[Switching to Thread 77048945]
__pspgl_matrix_select (c=0x0, s=0x5c0) at pspgl_matrix.c:52
52 struct pspgl_matrix_stack *stk = c->current_matrix_stack;
(gdb) backtrace
#0 __pspgl_matrix_select (c=0x0, s=0x5c0) at pspgl_matrix.c:52
#1 0x088042f4 in initgl () at ogl.c:211
#2 0x08804f40 in main () at ogl.c:257
(gdb)
|
Will this help :-)? |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Sep 30, 2009 1:05 pm Post subject: |
|
|
| Looks like the pspgl context wasn't initialized. As far as I know SDL should do that setup if it was built properly. Are you sure it was built with pspgl support? The output of "nm /usr/local/pspdev/psp/lib/libSDL.a | grep GL" should show if it was. Also, try compiling other SDL OpenGL PSP apps that you know work, that will let you know your build system is OK. |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Wed Sep 30, 2009 5:52 pm Post subject: |
|
|
| jimparis wrote: | | Looks like the pspgl context wasn't initialized. As far as I know SDL should do that setup if it was built properly. Are you sure it was built with pspgl support? The output of "nm /usr/local/pspdev/psp/lib/libSDL.a | grep GL" should show if it was. |
| Code: |
~$ nm ../pspdev/psp/lib/libSDL.a | grep GL
00000ad8 T SDL_GL_GetAttribute
00000c30 T SDL_GL_GetProcAddress
00000c94 T SDL_GL_LoadLibrary
00000088 T SDL_GL_Lock
00000b2c T SDL_GL_SetAttribute
00000aa8 T SDL_GL_SwapBuffers
00000090 T SDL_GL_Unlock
00000080 T SDL_GL_UpdateRects
00000078 T SDL_GL_UpdateRectsLock
|
| jimparis wrote: | | Also, try compiling other SDL OpenGL PSP apps that you know work, that will let you know your build system is OK. |
I have not such application yet :-). So, I searched this and other forums, I found several similar unresolved problems with running SDL + pspgl programs. Looks like a bug in pspgl or sdl psp port.
Thank for the reply! |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Thu Oct 01, 2009 5:07 am Post subject: |
|
|
Your SDL was not built properly. You should see:
| Code: |
00000008 T PSP_GL_GetAttribute
00000290 T PSP_GL_GetProcAddress
00000010 T PSP_GL_Init
00000248 T PSP_GL_MakeCurrent
00000238 T PSP_GL_SwapBuffers
000010f8 T SDL_GL_GetAttribute
00001250 T SDL_GL_GetProcAddress
000012b4 T SDL_GL_LoadLibrary
00000388 T SDL_GL_Lock
0000114c T SDL_GL_SetAttribute
000010c8 T SDL_GL_SwapBuffers
00000600 T SDL_GL_Unlock
00000078 T SDL_GL_UpdateRects
0000067c T SDL_GL_UpdateRectsLock
U PSP_GL_GetAttribute
U PSP_GL_GetProcAddress
U PSP_GL_Init
U PSP_GL_MakeCurrent
U PSP_GL_SwapBuffers
|
Rebuild SDL and pay attention to the configure output. |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Thu Oct 01, 2009 7:27 pm Post subject: |
|
|
| jimparis wrote: | Your SDL was not built properly. You should see:
| Code: |
00000008 T PSP_GL_GetAttribute
00000290 T PSP_GL_GetProcAddress
00000010 T PSP_GL_Init
00000248 T PSP_GL_MakeCurrent
00000238 T PSP_GL_SwapBuffers
000010f8 T SDL_GL_GetAttribute
00001250 T SDL_GL_GetProcAddress
000012b4 T SDL_GL_LoadLibrary
00000388 T SDL_GL_Lock
0000114c T SDL_GL_SetAttribute
000010c8 T SDL_GL_SwapBuffers
00000600 T SDL_GL_Unlock
00000078 T SDL_GL_UpdateRects
0000067c T SDL_GL_UpdateRectsLock
U PSP_GL_GetAttribute
U PSP_GL_GetProcAddress
U PSP_GL_Init
U PSP_GL_MakeCurrent
U PSP_GL_SwapBuffers
|
Rebuild SDL and pay attention to the configure output. |
Thanks!
I tried to configure with --enable-video-psp option and this functions had appeared in the lib.
But this option is documented neither in the README.PSP nor in the ./configure --help output. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Fri Oct 02, 2009 5:42 am Post subject: |
|
|
| Post the output of the configure script here. It will tell you if it found PSPGL. |
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Fri Oct 02, 2009 7:53 pm Post subject: |
|
|
| jimparis wrote: | | Post the output of the configure script here. It will tell you if it found PSPGL. |
Sorry. Everything fine. There is no option --enable-video-psp :-). I have understood why my SDL was without PSPGL functions. First, my pspsdk was built without pspgl. After I built pspgl, I configured sdl and called make without make clean. Stupid error.
Thank you for the help! |
|
| Back to top |
|
 |
|
|
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
|