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 

PSPGL in SDL

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Tue Feb 07, 2006 11:37 am    Post subject: PSPGL in SDL Reply with quote

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:

/* 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" {

int SDL_main() {
    int done = 0;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
    {
        fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_FULLSCREEN) == NULL)
    {
        fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2, 2, -2, 2, -2, 2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

  while (!done)
    {
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        angle += delta;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef(angle * 1.32f, 0.0f, 0.0f, 1.0f);

        glShadeModel(GL_SMOOTH);

        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_TRIANGLES);
            glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(1.0f, 0.0f, 0.0f);
            glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
            glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f);
        glEnd();
        glFinish();

        SDL_GL_SwapBuffers();
    }

    return 0;
}
}//extern "C"



and this is what I get after running it then running psp-addr2line

Quote:

$ 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?
_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Tue Feb 07, 2006 4:09 pm    Post subject: Reply with quote

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Wed Feb 08, 2006 6:19 am    Post subject: Reply with quote

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
_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Wed Feb 08, 2006 8:29 am    Post subject: Reply with quote

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Wed Feb 08, 2006 8:35 am    Post subject: Reply with quote

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...
_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Wed Feb 08, 2006 11:09 am    Post subject: Reply with quote

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Wed Feb 08, 2006 11:19 am    Post subject: Reply with quote

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.
_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
PacManFan



Joined: 25 Jun 2005
Posts: 66

PostPosted: Thu Feb 09, 2006 8:07 am    Post subject: Problems with GL and SDL too Reply with quote

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



Joined: 25 Jun 2005
Posts: 66

PostPosted: Thu Feb 09, 2006 8:25 am    Post subject: Reply with quote

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Thu Feb 09, 2006 8:51 am    Post subject: Reply with quote

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!
_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Thu Feb 09, 2006 10:12 am    Post subject: Reply with quote

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



Joined: 12 Jul 2005
Posts: 254

PostPosted: Thu Feb 09, 2006 10:15 am    Post subject: Reply with quote

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



Joined: 25 Jun 2005
Posts: 66

PostPosted: Thu Feb 09, 2006 10:19 am    Post subject: Reply with quote

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



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Thu Feb 09, 2006 11:48 am    Post subject: Reply with quote

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)

Quote:

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

_________________
My work:
TrackBundler for Gripshift
Back to top
View user's profile Send private message Visit poster's website
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