PSPGL CPP in jsgf version

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

PSPGL CPP in jsgf version

Post by Thanhda »

Hey, i was wondering how do you set up a cpp app in jsgf version of pspgl. In holgers version i was able to with no problem. here the patch he gave me.

Code: Select all

$ svn diff 
Index: psp-setup.c 
=================================================================== 
--- psp-setup.c (revision 1100) 
+++ psp-setup.c (working copy) 
@@ -169,7 +169,7 @@ 
 { 
        int id; 
        pspKernelSetKernelPC(); 
-       pspDebugInstallErrorHandler((void *) 0); 
+       pspDebugInstallErrorHandler((PspDebugErrorHandler) (void *) 0); 
        if ((id = sceKernelCreateThread("update_thread", update_thread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0)) >= 0) 
                sceKernelStartThread(id, 0, 0); 
 } 
Index: eglcube.c 
=================================================================== 
--- eglcube.c   (revision 1082) 
+++ eglcube.c   (working copy) 
@@ -1,3 +1,6 @@ 
+ 
+extern "C" { 
+ 
 #include <pspctrl.h> 
 #include <stdlib.h> 
 #include <stdio.h> 
@@ -7,10 +10,11 @@ 
 #include <GLES/egl.h> 
 #include <GLES/gl.h> 
  
- 
 extern unsigned char logo_start&#91;&#93;; 
  
+&#125;; 
  
+ 
 struct Vertex 
 &#123; 
        float u, v; 
@@ -80,7 +84,7 @@ 
        #define psp_log&#40;x...&#41; __psp_log&#40;x&#41; 
 #else 
        #define psp_log&#40;x...&#41; do &#123;&#125; while &#40;0&#41; 
-       extern void __psp_log &#40;const char *fmt, ...&#41;; 
+       extern "C" void __psp_log &#40;const char *fmt, ...&#41;; 
 #endif 
  
 /* enable GLerror logging to "ms0&#58;/pspgl.ge" */ 
Index&#58; Makefile 
=================================================================== 
--- Makefile    &#40;revision 1049&#41; 
+++ Makefile    &#40;working copy&#41; 
@@ -1,4 +1,5 @@ 
 ARCH = psp- 
+CPP = $&#40;ARCH&#41;g++ 
 CC = $&#40;ARCH&#41;gcc 
 PSP_INSTALL = ../tools/psp-install 
 RM = rm -f 
@@ -6,7 +7,7 @@ 
 PSPPATH &#58;= $&#40;shell psp-config --pspsdk-path&#41; 
 PSPGL_LFLAGS = -lGLU -lGL -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lm -lc -lpspuser -lpspkernel 
 CFLAGS = -g -Wall -O2 -MD -I$&#40;PSPPATH&#41;/include -I.. 
-LFLAGS = -g -Wall -O2 -DMODULE_NAME="test-egl" psp-setup.c -L$&#40;PSPPATH&#41;/lib -L.. $&#40;PSPGL_LFLAGS&#41; 
+LFLAGS = -g -Wall -O2 -DMODULE_NAME="test-egl" psp-setup.c -L$&#40;PSPPATH&#41;/lib -L.. -lstdc++ $&#40;PSPGL_LFLAGS&#41; 
  
 TARGET = pspGL-cube 
 OBJS = eglcube.o logo.o 
@@ -19,7 +20,7 @@ 
 all&#58; $&#40;TARGET&#41; 
  
 .c.o&#58; 
-       $&#40;CC&#41; $&#40;CFLAGS&#41; -c $< 
+       $&#40;CPP&#41; $&#40;CFLAGS&#41; -c $< 
  
 logo.o&#58; logo.raw 
        bin2o -i logo.raw logo.o logo

And it compiles like this

Code: Select all

$ make 
psp-g++ -g -Wall -O2 -MD -I/usr/local/pspdev/psp/sdk/include -I.. -c eglcube.cpp
bin2o -i logo.raw logo.o logo 
psp-gcc eglcube.o logo.o -g -Wall -O2 -DMODULE_NAME="test-egl" psp-setup.c -L/usr/local/pspdev/psp/sdk/lib -L.. -lstdc++ -lGLU -lGL -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lm -lc -lpspuser -lpspkernel -o pspGL-cube 
i've tried implementing this into jsgf version, but certain functions where missing. i'm not at home right now so i cant post the errors i got.
There are 10 types of people in the world: Those who understand binary, and those who don't...
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

I haven't done much with PSPGL and C++, but it shouldn't be too hard to make work properly.
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

i was wondering, since you seem to have taken over the pspgl development, if you can try yourself to see how it might fit in. i havnt given up trying yet tho, but am currently working on the 3ds loader for your version of pspgl.
There are 10 types of people in the world: Those who understand binary, and those who don't...
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Yeah, I'll take a look at it in the next couple of days.

Did you work out your file IO problem?
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

well i havnt had time to work too much on it. since i'm busy with university and all. but the original errors occured in holgers verion of pspgl. So i'm right now slowly coding one using your version of pspgl. but i'm probably going to finish it up during the weekend.
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

Okay, been working on a pspgl cpp for jsf version. Heres what i got so far

Code: Select all

psp-g++ -g -Wall -O2 -MD -MF .deps/glut.d -I.. -I/usr/local/pspdev/psp/sdk/inclu
de -c glut.cpp
glut.cpp&#58;214&#58;3&#58; warning&#58; no newline at end of file
psp-gcc -g -Wall -O2 -MD -MF .deps/psp-setup-glut.d -I.. -I/usr/local/pspdev/psp
/sdk/include -o psp-setup-glut.o -c -DMODULE_NAME="glut" psp-setup.c
psp-gcc -o glut.elf -g -Wall -L.. -stdc++ -L/usr/local/pspdev/psp/sdk/lib glut.o
 psp-setup-glut.o  -lpng -lz -lglut -lGLU -lGL -lm -lc -lpsputility -lpspdebug -
lpspge -lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -lpsprtc
glut.o&#58;&#40;.eh_frame+0x11&#41;&#58; undefined reference to `__gxx_personality_v0'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;glut.elf&#93; Error 1
rm psp-setup-glut.o
Not quite sure what the error is. So i'll post my source online. This includes a Make file. so you just just toss it in the pspgl directory.

http://www.geocities.com/tsune_l/test-cpp.zip

This is based off my BMP loader available at
http://forums.ps2dev.org/viewtopic.php?t=4487

the only think i really did was replace

Code: Select all

extern "C" void __pspgl_log &#40;const char *fmt, ...&#41;;
in line 10, in glchk.h file. and added extern "C" in the cpp file.

here what i did in the make file

Code: Select all

ARCH = psp-
CPP= $&#40;ARCH&#41;g++
CC = $&#40;ARCH&#41;gcc
AS = $&#40;ARCH&#41;as
SIZE = $&#40;ARCH&#41;size
PSP_INSTALL = ../tools/psp-install
RM = rm -f

PSPPATH &#58;= $&#40;shell psp-config --pspsdk-path&#41;
PSPGL_LFLAGS = -lglut -lGLU -lGL -lm -lc -lpsputility -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -lpsprtc
CFLAGS = -g -Wall -O2 -MD -MF $&#40;DEPDIR&#41;/$&#40;basename $@&#41;.d -I.. -I$&#40;PSPPATH&#41;/include
LDFLAGS = -g -Wall -L.. -stdc++ -L$&#40;PSPPATH&#41;/lib

TESTS=glut
#TESTS+=idxtex

BUILDDATE &#58;= $&#40;shell date "+%Y/%m/%d %k&#58;%M&#58;%S"&#41;
PSP_EBOOT_TITLE = $&#40;TARGET&#41; $&#40;BUILDDATE&#41;
PSP_EBOOT_ICON = firefox.png
PSP_EBOOT_ICON1 = NULL
PSP_EBOOT_UNKPNG = NULL
PSP_EBOOT_PIC1 = NULL
PSP_EBOOT_SND0 = NULL
PSP_EBOOT_PSAR = NULL

DEPDIR = .deps
PSPSDK &#58;= $&#40;shell psp-config --pspsdk-path&#41;

all&#58; $&#40;DEPDIR&#41; $&#40;TESTS&#58;%=%.elf&#41;

install&#58; $&#40;TESTS&#58;%=install-%&#41;

-include install-settings

install-%&#58; %.elf
	while &#91; ! -d $&#40;PSP_MOUNTDIR&#41;/psp/game &#93;; do mount $&#40;PSP_MOUNTDIR&#41;; sleep 1; done
	PSP_MOUNTDIR=$&#40;PSP_MOUNTDIR&#41; \
		$&#40;PSP_INSTALL&#41; $&#40;INSTALLFLAGS&#41; $< \
		--eboot-title="$* $&#40;BUILDDATE&#41;" --eboot-icon="firefox.png"
	umount $&#40;PSP_MOUNTDIR&#41;

DXTTEX&#58;=$&#40;wildcard dxt3/*.dxt3&#41;
DXTOBJ&#58;=$&#40;DXTTEX&#58;%.dxt3=%.o&#41;

glut.elf&#58;glut.o $&#40;DXTOBJ&#41;

psp-setup-%.o&#58; psp-setup.c 
	$&#40;CC&#41; $&#40;CFLAGS&#41; -o $@ -c -DMODULE_NAME="$&#40;patsubst psp-setup-%.o,%,$@&#41;" psp-setup.c

%.elf&#58; %.o psp-setup-%.o ../libGL.a ../libGLU.a ../libglut.a
	$&#40;CC&#41; -o $@ $&#40;LDFLAGS&#41; $&#40;filter %.o,$^&#41;  -lpng -lz $&#40;PSPGL_LFLAGS&#41;

%.sys&#58; %-sys.o
	cc -o $@ $^ -lglut -lGL

%.raw&#58; %.png
	convert $< rgba&#58;$@

%-mono.raw&#58; %.png
	convert $< gray&#58;$@

%.o&#58; %.raw
	&#40;sym=`echo $&#40;notdir $*&#41; | tr '-' '_'`; \
	 echo -e ".data\n.global $$&#123;sym&#125;_start\n$$&#123;sym&#125;_start&#58;\n\t.incbin \"$<\"" | $&#40;AS&#41; -o $@&#41;

%.o&#58; %.dxt3
	&#40;sym=`echo $&#40;notdir $*&#41; | tr '-' '_'`; \
	 echo -e ".data\n.global $$&#123;sym&#125;_start\n.global $$&#123;sym&#125;_end\n$$&#123;sym&#125;_start&#58;\n\t.incbin \"$<\"\n$$&#123;sym&#125;_end&#58;\n" | $&#40;AS&#41; -o $@&#41;

textab.h&#58; $&#40;DXTTEX&#41; Makefile
	&#40;for i in $&#40;DXTTEX&#41;; do b=`basename $$i .dxt3`; echo "extern unsigned char $$&#123;b&#125;_start&#91;&#93;, $$&#123;b&#125;_end&#91;&#93;;"; done; \
	 echo "static const struct &#123; const unsigned char *start, *end; &#125; dxt&#91;&#93; = &#123;"; \
	 for i in $&#40;DXTTEX&#41;; do b=`basename $$i .dxt3`; echo "     &#123; $$&#123;b&#125;_start, $$&#123;b&#125;_end &#125;,"; done; \
         echo "&#125;;" &#41;> $@ || rm -f $@


%.o&#58; $&#40;DEPDIR&#41; %.c
	$&#40;CC&#41; $&#40;CFLAGS&#41; -c $*.c

%.o&#58; $&#40;DEPDIR&#41; %.cpp
	$&#40;CPP&#41; $&#40;CFLAGS&#41; -c $*.cpp

%-sys.o&#58; %.c
	cc -g -DSYS -c -o $@ $<

$&#40;DEPDIR&#41;&#58;
	mkdir $&#40;DEPDIR&#41;

clean&#58;
	$&#40;RM&#41; $&#40;DEPDIR&#41;/*.d *.o $&#40;DXTOBJ&#41; *.a *.elf *.sys *~

-include $&#40;wildcard *.d&#41; dummy
There are 10 types of people in the world: Those who understand binary, and those who don't...
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Thanhda wrote:

Code: Select all

psp-gcc -o glut.elf -g -Wall -L.. -stdc++ -L/usr/local/pspdev/psp/sdk/lib glut.o psp-setup-glut.o  -lpng -lz -lglut -lGLU -lGL -lm -lc -lpsputility -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -lpsprtc
Not quite sure what the error is.
Put -lstdc++ at the end. Or use psp-g++. Also read http://forums.ps2dev.org/viewtopic.php?p=23298#23298.
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

still get an error. i tried that already.

Code: Select all

psp-g++ -g -Wall -O2 -MD -MF .deps/glut.d -I.. -I/usr/local/pspdev/psp/sdk/inclu
de -c glut.cpp
glut.cpp&#58;214&#58;3&#58; warning&#58; no newline at end of file
psp-gcc -g -Wall -O2 -MD -MF .deps/psp-setup-glut.d -I.. -I/usr/local/pspdev/psp
/sdk/include -o psp-setup-glut.o -c -DMODULE_NAME="glut" psp-setup.c
psp-g++ -o glut.elf -g -Wall -L.. -L/usr/local/pspdev/psp/sdk/lib glut.o psp-set
up-glut.o  -lpng -lz -lglut -lGLU -lGL -lm -lc -lpsputility -lpspdebug -lpspge -
lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -lpsprtc -lstdc++

/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a&#40;chdir.o&#41;&#58; In function `chdir'&#58;
../../../../../../newlib/libc/sys/psp/libcglue.c&#58;88&#58; undefined reference to sceIoDopen'
../../../../../../newlib/libc/sys/psp/libcglue.c&#58;93&#58; undefined reference to sceIoDclose'
../../../../../../newlib/libc/sys/psp/libcglue.c&#58;95&#58; undefined reference to `sceIoChdir'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a&#40;_stat.o&#41;&#58; In function `_stat'&#58;
../../../../../../newlib/libc/sys/psp/libcglue.c&#58;516&#58; undefined reference to sc
eIoGetstat'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;glut.elf&#93; Error 1
rm psp-setup-glut.o
There are 10 types of people in the world: Those who understand binary, and those who don't...
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

The error is caused by not having the correct library order. Read the post jimparis referred you to or keep fiddling with the order until it works.
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

problem solved. i just placed the -lstdc++ before the -lc and it works. thanks for all the help.

Code: Select all

PSPGL_LFLAGS = -lglut -lGLU -lGL -lstdc++ -lm -lc -lpsputility -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpsplibc -lpspuser -lpspkernel -lpsprtc
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

Okay, Now it compiles just fine, but when i run it. it just goes to a black screen, waits 20 secs, then turns off. does anyone know why it would do this?

Edit Fixed.
changed from this from Makefile

Code: Select all

%.elf&#58; %.o psp-setup-%.o ../libGL.a ../libGLU.a ../libglut.a
	$&#40;CPP&#41; -o $@ $&#40;LDFLAGS&#41; $&#40;filter %.o,$^&#41;  -lpng -lz $&#40;PSPGL_LFLAGS&#41;
to this

Code: Select all

%.elf&#58; %.o psp-setup-%.o ../libGL.a ../libGLU.a ../libglut.a
	$&#40;CC&#41; -o $@ $&#40;LDFLAGS&#41; $&#40;filter %.o,$^&#41;  -lpng -lz $&#40;PSPGL_LFLAGS&#41;
only supose to compile the cpp file using psp-g++. Also removed extern "C" from the glchk.h file. as it only need to be called once in the cpp file.

Here I have posted the code online for people to try it out. Its a port of my bmp loader into cpp.

http://www.geocities.com/tsune_l/test-cpp.zip
There are 10 types of people in the world: Those who understand binary, and those who don't...
SiW
Posts: 7
Joined: Wed Aug 10, 2005 2:31 am
Location: Whittemore, Iowa, USA
Contact:

Post by SiW »

Bringing this back up just for reference.

Thanks for posting the code, Thanhda. To build properly with the current version of PSPSDK, you need to link with pspvfpu also. So the line in the Makefile becomes:

Code: Select all

PSPGL_LFLAGS = -lglut -lGLU -lGL -lstdc++ -lm -lc -lpsputility -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpspvfpu -lpsplibc -lpspuser -lpspkernel -lpsprtc
Post Reply