problems with sdl + opengl(SOLVED!)

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

Moderators: cheriff, TyRaNiD

Post Reply
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

problems with sdl + opengl(SOLVED!)

Post by viridite »

Hi, everybody

I'm new to psp development. i'm now using PSP 3.52M33 for development. recently i met a problem and cannot find solution with google. so pls somebody help

my code

Code: Select all


#define SCR_TEX_W   512
#define SCR_TEX_H   256 
// Initializes the PSP Display.
void InitializeGraphics()
{
   float ratio;
   int _3dview_h;
	//SDL_Surface *screen;
	const SDL_VideoInfo* info = NULL;
    /* Our angle of rotation. */
   // The SDL screen surface
SDL_Surface *sdlscrn;
                       
// fe2 UI blits are done to old screen memory and copied to this texture.
static unsigned int screen_tex;

// Set window size, I kept the original 1.6 ratio for now
int screen_w = 432;
int screen_h = 270; 


	if &#40; SDL_Init &#40; SDL_INIT_VIDEO | SDL_INIT_TIMER &#41; < 0 &#41; &#123;
			printf&#40; "Couldn't initialize SDL&#58; %s\n",SDL_GetError&#40;&#41;&#41;;
			exit&#40;1&#41;;
		&#125;




   info = SDL_GetVideoInfo &#40;&#41;;

   

   SDL_GL_SetAttribute &#40;SDL_GL_DOUBLEBUFFER, 1&#41;;

   if &#40;&#40;sdlscrn = SDL_SetVideoMode &#40;screen_w, screen_h, info->vfmt->BitsPerPixel, SDL_OPENGL | SDL_DOUBLEBUF&#41;&#41; == 0&#41; &#123;
      printf &#40;"Video mode set failed&#58; %s\n", SDL_GetError &#40;&#41;&#41;;
      SDL_Quit &#40;&#41;;
      exit &#40;-1&#41;;
   &#125;
  printf &#40;"Video mode set ok"&#41;;
   _3dview_h = screen_h - &#40;32*screen_h&#41;/200;
   ratio = &#40;float&#41; screen_w / &#40;float&#41; _3dview_h;
 
#if 1  
   glDisable &#40;GL_CULL_FACE&#41;;
   glShadeModel &#40;GL_FLAT&#41;;
   glDisable &#40;GL_DEPTH_TEST&#41;;
   glClearColor &#40;0, 0, 0, 0&#41;;

   glViewport &#40;0, 32*screen_h/200, screen_w, _3dview_h&#41;;
   glMatrixMode &#40;GL_PROJECTION&#41;;
   glLoadIdentity &#40;&#41;;

   glEnable &#40;GL_TEXTURE_2D&#41;;
   glGenTextures &#40;1, &screen_tex&#41;;
   glBindTexture &#40;GL_TEXTURE_2D, screen_tex&#41;;
   glTexImage2D &#40;GL_TEXTURE_2D, 0, GL_RGBA, SCR_TEX_W, SCR_TEX_H, 0, GL_RGBA, GL_INT, 0&#41;;
   glTexParameterf &#40;GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP&#41;;
   glTexParameterf &#40;GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP&#41;;
   glTexParameterf &#40;GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST&#41;;
   glTexParameterf &#40;GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST&#41;;

   glBlendFunc &#40;GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA&#41;;
   glDisable &#40;GL_TEXTURE_2D&#41;;

   glClear &#40;GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT&#41;;
   glMatrixMode &#40;GL_MODELVIEW&#41;;
   glLoadIdentity &#40;&#41;;

   // Configure some SDL stuff
   SDL_EventState&#40;SDL_MOUSEMOTION, SDL_ENABLE&#41;;
   SDL_EventState&#40;SDL_MOUSEBUTTONDOWN, SDL_ENABLE&#41;;
   SDL_EventState&#40;SDL_MOUSEBUTTONUP, SDL_ENABLE&#41;;
   SDL_ShowCursor&#40;SDL_ENABLE&#41;; 
#endif			
&#125;
i found it always crash when there are some gl function calls. there will be blue screen appeareing and displays

Code: Select all

 psp-addr2line -e taget.elf -f -C 0x89298d8 0x5c30fc8a 0x89007e0
and I tried and found following things

Code: Select all

psp-addr2line -e .elf -f -C 0x89298d8 0x5c30fc8a 0x89007e0
__pspgl_context_writereg
/media/windows/docs/psp/pspsvn/pspgl/pspgl_context.c&#58;14
??
??&#58;0
InitializeGraphics
??&#58;0


I just wonder why the crash may happen? in fact i have already tried to add -DHAVE_OPENGL in both comiling makefiles(SDL and my application)
my makefile


Code: Select all



ROOT &#58;= $&#40;shell pwd&#41;

MODULE_OBJS	=

ZOUT		= $&#40;ROOT&#41;/zout

INCDIR += $&#40;PSPSDK&#41;/../include/GL

INCDIR += $&#40;PSPSDK&#41;/../../include/SDL







OBJS = main.o graphics.o menulogic.o kernel.o

LIBS += -lSDLmain -lSDL -lGL -lGLU -lglut -lpsprtc -lpspvfpu









CFLAGS = -O2 -G0 -Wall 

CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti

ASFLAGS = $&#40;CFLAGS&#41;



EXTRA_TARGETS = EBOOT.PBP

PSP_EBOOT_TITLE = UI



PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
PSPBIN = $&#40;PSPSDK&#41;/../bin
CFLAGS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --cflags&#41; -DHAVE_OPENGL 
LIBS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --libs&#41; -lm -lc -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpspvfpu -lpspuser -lpspkernel -lstdc++ 


include $&#40;PSPSDK&#41;/lib/build.mak





so , any solution?
Last edited by viridite on Thu Nov 08, 2007 7:52 pm, edited 1 time in total.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Compile with debugging symbols (-g) and the psp-addr2line output should be more useful. Also the full text of the blue screen error output would help.
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

i changed to a precompiled lib and it outputs
exception detail:
I regret to inform you your psp has just crashed
Exception Details:
Exception - Bus error(data)
EPC - 08927808

...(some numbers)

The offending routing may be identified with
psp-addr2line -e taget.elf -f -C 0x89298d8 0x5c30fc8a 0x89007e0
when using the debug line
/home/quercio/pspgl_modified/glEnable.c:9
??
??:0
InitializeGraphics
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

sorry . i think i need to post the debug info when using the lib built by myself.

it also crashes with data bus error, but as i used the psp-addr2line for debug, i found the problem report by the system is when calling the following function

Code: Select all

/**
 *  cached register write, save value and mark as touched...
 */
void __pspgl_context_writereg &#40;struct pspgl_context *c, uint32_t cmd,
			       uint32_t argi&#41; 
&#123;
	uint32_t new = &#40;cmd << 24&#41; | &#40;argi & 0xffffff&#41;;

	if &#40;new != c->hw.ge_reg&#91;cmd&#93;&#41; &#123;
		c->hw.ge_reg&#91;cmd&#93; = new;
		c->hw.ge_reg_touched&#91;cmd/32&#93; |= &#40;1 << &#40;cmd % 32&#41;&#41;;
	&#125;
&#125;

the following line will cause a data bus exception

Code: Select all

if &#40;new != c->hw.ge_reg&#91;cmd&#93;&#41; &#123;
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

I used

Code: Select all


   info = SDL_GetVideoInfo &#40;&#41;;

   printf&#40; "\r\n info is 0x%x",&#40;Uint32&#41;info&#41;;
to get information from the initialization and got 0x89480A8
that is 00001000 10010100 10000000 10101000b
according to

Code: Select all

typedef struct SDL_VideoInfo &#123;
	Uint32 hw_available &#58;1;	/* Flag&#58; Can you create hardware surfaces? */
	Uint32 wm_available &#58;1;	/* Flag&#58; Can you talk to a window manager? */
	Uint32 UnusedBits1  &#58;6;
	Uint32 UnusedBits2  &#58;1;
	Uint32 blit_hw      &#58;1;	/* Flag&#58; Accelerated blits HW --> HW */
	Uint32 blit_hw_CC   &#58;1;	/* Flag&#58; Accelerated blits with Colorkey */
	Uint32 blit_hw_A    &#58;1;	/* Flag&#58; Accelerated blits with Alpha */
	Uint32 blit_sw      &#58;1;	/* Flag&#58; Accelerated blits SW --> HW */
	Uint32 blit_sw_CC   &#58;1;	/* Flag&#58; Accelerated blits with Colorkey */
	Uint32 blit_sw_A    &#58;1;	/* Flag&#58; Accelerated blits with Alpha */
	Uint32 blit_fill    &#58;1;	/* Flag&#58; Accelerated color fill */
	Uint32 UnusedBits3  &#58;16;
	Uint32 video_mem;	/* The total amount of video memory &#40;in K&#41; */
	SDL_PixelFormat *vfmt;	/* Value&#58; The format of the video surface */
&#125; SDL_VideoInfo;
hw_available is 0, which means the hardware surfaces isn't available. is it normal? is it the reason why it crashes and display blue screen?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

If you compile everything with -g and run psp-addr2line, it should be more useful in terms of tracing the calls (no ?? in the output).

Anyway, yeah, the crash is somewhere inside pspgl. I'm not sure which of your calls is triggering it (better psp-addr2line output could make it more clear) but my guess would be that you're either passing a bad parameter to something or you're not initializing it properly. (I haven't touched pspgl at all myself, so I don't have any more specific advice, sorry).

What you listed for "info" is wrong, it's a pointer, you need to look at "*info" if you want to check out the contents.

Are you sure you compiled SDL with HAVE_OPENGL defined?
When you run the SDL configure script, make sure you see:

Code: Select all

checking for OpenGL &#40;pspgl&#41; support... yes
You can also check by running

Code: Select all

psp-nm /usr/local/pspdev/psp/lib/libSDL.a | grep PSP_GL_Init
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

Thank you!
after checking the SDL lib, i found when using ./configure the openGL isn't supported.

could you tell me how to configure this by the way?
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

sorry, forget one thing.

I just modified the Makefile generated by ./configure............ so i don't know whether it's enough.....
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

Thank you! I've solved this problem:)

i rechecked the configure file and and opengl enable in command line...it won't crash now~:)
Post Reply