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 

[SOLVED] PSPGL + SDL Texturing problems

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



Joined: 22 Aug 2005
Posts: 6

PostPosted: Tue Dec 09, 2008 7:50 am    Post subject: [SOLVED] PSPGL + SDL Texturing problems Reply with quote

SOLVED:
I screwed up the parameters to glTexImage2D. It should be

Code:

 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h , 0, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);


Quote:

Hi, I'm trying to compile a simple psp application that will render a textured image to the screen using PSPGL and SDL but it always seems to die at the SDL_GL_SwapBuffers call.

Here is my code:
Code:

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <pspthreadman.h>
#include <stdlib.h>
#include <stdio.h>

#define PSP_SCREEN_HEIGHT 272
#define PSP_SCREEN_WIDTH 480
#define SCREEN_BPP 32

PSP_MODULE_INFO("test", 0, 1, 0);
PSP_HEAP_SIZE_KB(20480);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU);

#define printf pspDebugScreenPrintf

FILE* output;

int exit_callback (int arg1, int arg2, void *common)
{
   sceKernelExitGame();
   return 0;
}


int update_thread (SceSize args, void *argp)
{
   int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);
   sceKernelSleepThreadCB();
   return 0;
}



void setup_callbacks (void)
{
   int id;

   if ((id = sceKernelCreateThread("update_thread", update_thread, 0x11, 0xFA0, 0, 0)) >= 0)
      sceKernelStartThread(id, 0, 0);
}



void back_to_kernel (void)
{
   sceKernelExitGame();
}

int game();
void Display();

GLuint tex;

extern "C" int main(int argc, char* argv[])
{


   int returnNumber = game();


   fclose(output);
   sceKernelSleepThread();
   return returnNumber;
}

int game()
{
   setup_callbacks();

   pspDebugScreenInit();

   SDL_Surface * screen;

   output = fopen("test.txt", "w");

   printf("Starting init\n");

   if (SDL_Init(SDL_INIT_VIDEO) != 0)
   {
      printf("Unable to initialize SDL: %s\n", SDL_GetError());
      return 1;
   }



   printf("Setting Video\n");
   screen = SDL_SetVideoMode(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, 32, SDL_OPENGL);
    if ( screen == NULL ) {
      printf("Unable to set video mode: %s\n", SDL_GetError());
      return 1;
   }

   printf("Starting gl initialization\n");
   glEnable(GL_TEXTURE_2D);
   glViewport(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   glClear(GL_COLOR_BUFFER_BIT);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0f, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   printf("Loading image\n");

   SDL_Surface* surface = SDL_LoadBMP("image.bmp");

   printf("drawing image\n");


  glGenTextures(1, &tex);
  glBindTexture(GL_TEXTURE_2D, tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT , 0, GL_RGBA,
               GL_UNSIGNED_BYTE, surface->pixels);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   SDL_FreeSurface(surface);


   while(1)
   {

       // Clear the screen before drawing
      glClear( GL_COLOR_BUFFER_BIT );
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

      Display();
      printf("Calling swapbuffers\n");
       SDL_GL_SwapBuffers();

   }

   glDeleteTextures( 1, &tex );
   fclose(output);

   return 0;
}

void Display()
{

  float tX = 240;
  float tY = 136;

  glBindTexture(GL_TEXTURE_2D, tex);

 glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex2d(-tX, -tY);

    glTexCoord2f(1,0);
    glVertex2d(tX, -tY);

    glTexCoord2f(1,1);
    glVertex2d(tX, tY);

    glTexCoord2f(0,1);
    glVertex2d(-tX, tY);

  glEnd();

}


I also put it through the debugger and got this out of it:
Code:

Program received signal SIGHUP, Hangup.
0x0884991c in sceGeListEnQueue ()
(gdb) backtrace
#0  0x0884991c in sceGeListEnQueue ()
#1  0xffffffff8809a3f8 in ?? ()
warning: GDB can't find the start of the function at 0x8809a3f8.

    GDB is unable to find the start of the function at 0x8809a3f8
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x8809a3f8 for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.
Previous frame inner to this frame (corrupt stack?)



Any help would be appreciated.

Also another note, I have successfully got an image rendered using SDL or PSPGL but it seems that the combination of the two has problems.

I also forgot to mention that this is being compiled and run on a slim PSP.
[/quote]
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