PSPGL in SDL

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

Moderators: cheriff, TyRaNiD

Post Reply
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

PSPGL in SDL

Post by NovaCaine »

Ok, I got another problem.

Im trying to get PSPGL to run under SDL, so that I have SDL for timer, joystick etc and PSPGL for rendering.

After searching the forums I found a code snippet that seemed to do this except when I finally got it to compile it crashes my PSP in setting up the Viewport(?). The thread link is here. the post is near the bottom of the page by mrbrown.

Here's the code

Code: Select all

/* Test SDL OpenGL support. */ 
#include <stdio.h> 
#include <stdlib.h> 

#include "SDL.h" 
#include "SDL_opengl.h" 


#define SCREEN_WIDTH 479 
#define SCREEN_HEIGHT 271 

static GLfloat delta = 1.0f; 
static GLfloat angle; 
extern "C" &#123;

int SDL_main&#40;&#41; &#123;
    int done = 0; 

    if &#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_JOYSTICK&#41; < 0&#41; 
    &#123; 
        fprintf&#40;stderr, "Unable to initialize SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;; 
        return 1; 
    &#125; 

    if &#40;SDL_SetVideoMode&#40;SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_FULLSCREEN&#41; == NULL&#41; 
    &#123; 
        fprintf&#40;stderr, "Unable to create OpenGL screen&#58; %s\n", SDL_GetError&#40;&#41;&#41;; 
        SDL_Quit&#40;&#41;; 
        return 1; 
    &#125; 

    glViewport&#40;0, 0, SCREEN_WIDTH, SCREEN_HEIGHT&#41;; 
    glMatrixMode&#40;GL_PROJECTION&#41;; 
    glLoadIdentity&#40;&#41;; 
    glOrtho&#40;-2, 2, -2, 2, -2, 2&#41;; 
    glMatrixMode&#40;GL_MODELVIEW&#41;; 
    glLoadIdentity&#40;&#41;; 

  while &#40;!done&#41; 
    &#123; 
        glClearColor&#40;0.0f, 0.0f, 0.0f, 0.0f&#41;; 

        angle += delta; 
        glMatrixMode&#40;GL_MODELVIEW&#41;; 
        glLoadIdentity&#40;&#41;; 
        glRotatef&#40;angle * 1.32f, 0.0f, 0.0f, 1.0f&#41;; 

        glShadeModel&#40;GL_SMOOTH&#41;; 

        glClear&#40;GL_COLOR_BUFFER_BIT&#41;; 
        glBegin&#40;GL_TRIANGLES&#41;; 
            glColor3f&#40;0.0f, 0.0f, 1.0f&#41;; glVertex3f&#40;1.0f, 0.0f, 0.0f&#41;; 
            glColor3f&#40;0.0f, 1.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 1.0f, 0.0f&#41;; 
            glColor3f&#40;1.0f, 0.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 0.0f, 1.0f&#41;; 
        glEnd&#40;&#41;; 
        glFinish&#40;&#41;; 

        SDL_GL_SwapBuffers&#40;&#41;; 
    &#125; 

    return 0; 
&#125;
&#125;//extern "C"

and this is what I get after running it then running psp-addr2line
$ psp-addr2line -e hello.elf - f -C 0x890168c 0x0 0x890038
glViewport
/cygdrive/h/Source/pspgl/glViewport.c:9
??
??:0
SDL_Main
??:0
I have tried calling sceGuInit() as well, as the thread where I found this code stated it was needed to get this working, but still get the same error.

Have I forgotten to do something I should have?
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

I haven't used PSPGL with SDL, but it looks like the GL context hasn't been made current; either the context hasn't been created, or eglMakeCurrent() hasn't been called on it.

Was SDL compiled with HAVE_OPENGL defined?
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

No, like I said, this was a copy-and-paste from the thread i'd posted.

That is all the code that I'm compiling there, how do I compile with HAVE_OPENGL? is it just a #define?

Will try eglMakeCurrent(), hopefully this will fix it :P
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

No, SDL should be doing it for you. HAVE_OPENGL is a build-time config setting for SDL which makes it support OpenGL or not. Hm, it seems to be set OK when I build SDL here...
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Oh, You mean in the SetVideoMode function? Yes I have got the flag set.

Did you manage to get the code to compile and run? I could compile the code fine, but when I run it on my PSP (v1.5 btw) it crashes and points to the glViewport.c file. I know theres nothing wrong with my PSPGL build, as I can build and run the demos fine - its only this lot of code that I'm having trouble with. And same with SDL...
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

No, when you built SDL, was it built with -DHAVE_OPENGL on the compiler command line.

I can't see any problem with your code or with SDL, assuming SDL has PSPGL support in it.

I'll try running the code later today.
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Sorry bout this noob question, but I'm still trying to get my head around the whole linux programming setup.

When you say "built SDL" Im guessing you mean when I biult the lib from svn. Then the answer is no - i did exactly how the README stated. Where do I call it? (LDFLAGS? CFLAGS? Doesn't help that the only linux guru I know doesn't program much...)

This may be the problem then and I'll try rebuilding SDL.
PacManFan
Posts: 66
Joined: Sat Jun 25, 2005 6:01 am

Problems with GL and SDL too

Post by PacManFan »

I've been trying to port some games that use both OpenGL and SDL together, and I'm having the same problems. -DHAVE_OPENGL was defined as one of the CFlags in the SDL makefile. GL seems to be crashing when I set up the viewport.

Both GL applications and SDL applications seem to work fine separately.

Any ideas?

-PMF
"I'm a little source code, short and stout
Here is my input, here is my out."

Author of PSPQuake and PSPSOne.
PacManFan
Posts: 66
Joined: Sat Jun 25, 2005 6:01 am

Post by PacManFan »

from my BSOD screen, the psp-addr2line tells me it's this:

struct pspvfpu_context *pspvfpu_initcontext(void)
{
struct pspvfpu_context *c;

/* Make sure the kernel preserves this thread's VFPU state */
if (sceKernelChangeCurrentThreadAttr(0, PSP_THREAD_ATTR_VFPU) < 0)
return NULL;

c = memalign(VFPU_ALIGNMENT, sizeof(*c));

if (c != NULL) {
c->owned = 0;
c->valid = 0;
}

return c;
}

somehow, it's the call to sceKernelChangeCurrentThreadAttr that's causing the crash.

-PMF
"I'm a little source code, short and stout
Here is my input, here is my out."

Author of PSPQuake and PSPSOne.
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Cool, got it working now, maybe it should be written in the readme file to add -DHAVE_OPENGL for openGL support.

Thanks for the help PacManFan and jsgf!
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

NovaCaine wrote:Cool, got it working now, maybe it should be written in the readme file to add -DHAVE_OPENGL for openGL support!
Cool. When I built SDL, it was defined by default. Do you have some older version or something?
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

PacManFan wrote:somehow, it's the call to sceKernelChangeCurrentThreadAttr that's causing the crash.
Well, that's a new one. Certainly a different problem from NovaCaine's.

What firmware are you using? Does PSPGL work at all for you, or does it only crash in SDL?

I'm not sure why sceKernelChangeCurrentThreadAttr() would crash; fail and return an error, sure, but crash?
PacManFan
Posts: 66
Joined: Sat Jun 25, 2005 6:01 am

Post by PacManFan »

How did you get it working?
my SDL makefile already had the -DHAVE_OPENGL define flag set, and it's still crashing.

-PMF
"I'm a little source code, short and stout
Here is my input, here is my out."

Author of PSPQuake and PSPSOne.
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Try compiling my code above - it should give a 3d triangle rotating.

All I did was rebuild my main SDL with the -DHAVE_OPENGL in the CFLAGS of the makefile (it may have been an older one, but I did try an update).

The error I got when it crashed was on line 9 of glViewport.c, which had something to do with setting the x value of the viewport IIRC.

Otherwise like I said, the code in my first post is what I am compiling, the only other change was that I also have -DHAVE_OPENGL in my projects cflags as well - if that does anything (i'm not sure)
TARGET = hello
OBJS = Main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL GL

PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(PSPSDK)/../bin
CFLAGS += `$(PSPBIN)/sdl-config --cflags` -DHAVE_OPENGL
LIBS += -lglut -lGLU -lGL `$(PSPBIN)/sdl-config --libs` -lm -lc -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpspvfpu -lpspuser -lpspkernel -lstdc++
include $(PSPSDK)/lib/build.mak
Post Reply