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 

problems with sdl + opengl(SOLVED!)

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



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 4:37 am    Post subject: problems with sdl + opengl(SOLVED!) Reply with quote

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:


#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 ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
         printf( "Couldn't initialize SDL: %s\n",SDL_GetError());
         exit(1);
      }




   info = SDL_GetVideoInfo ();

   

   SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);

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

   glViewport (0, 32*screen_h/200, screen_w, _3dview_h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();

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

   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glDisable (GL_TEXTURE_2D);

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();

   // Configure some SDL stuff
   SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
   SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
   SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
   SDL_ShowCursor(SDL_ENABLE);
#endif         
}


i found it always crash when there are some gl function calls. there will be blue screen appeareing and displays


Code:

 psp-addr2line -e taget.elf -f -C 0x89298d8 0x5c30fc8a 0x89007e0


and I tried and found following things

Code:

psp-addr2line -e .elf -f -C 0x89298d8 0x5c30fc8a 0x89007e0
__pspgl_context_writereg
/media/windows/docs/psp/pspsvn/pspgl/pspgl_context.c:14
??
??:0
InitializeGraphics
??: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:



ROOT := $(shell pwd)

MODULE_OBJS   =

ZOUT      = $(ROOT)/zout

INCDIR += $(PSPSDK)/../include/GL

INCDIR += $(PSPSDK)/../../include/SDL







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

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









CFLAGS = -O2 -G0 -Wall

CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti

ASFLAGS = $(CFLAGS)



EXTRA_TARGETS = EBOOT.PBP

PSP_EBOOT_TITLE = UI



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


include $(PSPSDK)/lib/build.mak







so , any solution?


Last edited by viridite on Thu Nov 08, 2007 7:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Nov 08, 2007 5:54 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 12:44 pm    Post subject: Reply with quote

i changed to a precompiled lib and it outputs
exception detail:

Quote:

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
Quote:

/home/quercio/pspgl_modified/glEnable.c:9
??
??:0
InitializeGraphics
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 1:18 pm    Post subject: Reply with quote

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:

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

   if (new != c->hw.ge_reg[cmd]) {
      c->hw.ge_reg[cmd] = new;
      c->hw.ge_reg_touched[cmd/32] |= (1 << (cmd % 32));
   }
}



the following line will cause a data bus exception
Code:

if (new != c->hw.ge_reg[cmd]) {
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 1:29 pm    Post subject: Reply with quote

I used

Code:


   info = SDL_GetVideoInfo ();

   printf( "\r\n info is 0x%x",(Uint32)info);


to get information from the initialization and got 0x89480A8
that is 00001000 10010100 10000000 10101000b
according to
Code:

typedef struct SDL_VideoInfo {
   Uint32 hw_available :1;   /* Flag: Can you create hardware surfaces? */
   Uint32 wm_available :1;   /* Flag: Can you talk to a window manager? */
   Uint32 UnusedBits1  :6;
   Uint32 UnusedBits2  :1;
   Uint32 blit_hw      :1;   /* Flag: Accelerated blits HW --> HW */
   Uint32 blit_hw_CC   :1;   /* Flag: Accelerated blits with Colorkey */
   Uint32 blit_hw_A    :1;   /* Flag: Accelerated blits with Alpha */
   Uint32 blit_sw      :1;   /* Flag: Accelerated blits SW --> HW */
   Uint32 blit_sw_CC   :1;   /* Flag: Accelerated blits with Colorkey */
   Uint32 blit_sw_A    :1;   /* Flag: Accelerated blits with Alpha */
   Uint32 blit_fill    :1;   /* Flag: Accelerated color fill */
   Uint32 UnusedBits3  :16;
   Uint32 video_mem;   /* The total amount of video memory (in K) */
   SDL_PixelFormat *vfmt;   /* Value: The format of the video surface */
} 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?
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Nov 08, 2007 5:10 pm    Post subject: Reply with quote

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:
checking for OpenGL (pspgl) support... yes

You can also check by running
Code:
psp-nm /usr/local/pspdev/psp/lib/libSDL.a | grep PSP_GL_Init
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 7:23 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 7:30 pm    Post subject: Reply with quote

sorry, forget one thing.

I just modified the Makefile generated by ./configure............ so i don't know whether it's enough.....
Back to top
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Thu Nov 08, 2007 7:52 pm    Post subject: Reply with quote

Thank you! I've solved this problem:)

i rechecked the configure file and and opengl enable in command line...it won't crash now~:)
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