[SOLVED] PSPGL + SDL Texturing problems

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

Moderators: cheriff, TyRaNiD

Post Reply
darkweb
Posts: 6
Joined: Mon Aug 22, 2005 2:12 am

[SOLVED] PSPGL + SDL Texturing problems

Post by darkweb »

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

Code: Select all

 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h , 0, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
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: Select all

#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&#40;"test", 0, 1, 0&#41;;
PSP_HEAP_SIZE_KB&#40;20480&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU&#41;;

#define printf pspDebugScreenPrintf

FILE* output;

int exit_callback &#40;int arg1, int arg2, void *common&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;


int update_thread &#40;SceSize args, void *argp&#41;
&#123;
	int cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;
	sceKernelSleepThreadCB&#40;&#41;;
	return 0;
&#125;



void setup_callbacks &#40;void&#41;
&#123;
	int id;

	if &#40;&#40;id = sceKernelCreateThread&#40;"update_thread", update_thread, 0x11, 0xFA0, 0, 0&#41;&#41; >= 0&#41;
		sceKernelStartThread&#40;id, 0, 0&#41;;
&#125;



void back_to_kernel &#40;void&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
&#125;

int game&#40;&#41;;
void Display&#40;&#41;;

GLuint tex;

extern "C" int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;


	int returnNumber = game&#40;&#41;;


	fclose&#40;output&#41;;
	sceKernelSleepThread&#40;&#41;;
	return returnNumber;
&#125;

int game&#40;&#41;
&#123;
	setup_callbacks&#40;&#41;;

	pspDebugScreenInit&#40;&#41;;

	SDL_Surface * screen;

	output = fopen&#40;"test.txt", "w"&#41;;

	printf&#40;"Starting init\n"&#41;;

	if &#40;SDL_Init&#40;SDL_INIT_VIDEO&#41; != 0&#41;
	&#123;
		printf&#40;"Unable to initialize SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
		return 1;
	&#125;



	printf&#40;"Setting Video\n"&#41;;
	screen = SDL_SetVideoMode&#40;PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, 32, SDL_OPENGL&#41;;
    if &#40; screen == NULL &#41; &#123;
		printf&#40;"Unable to set video mode&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
		return 1;
	&#125;

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

	printf&#40;"Loading image\n"&#41;;

	SDL_Surface* surface = SDL_LoadBMP&#40;"image.bmp"&#41;;

	printf&#40;"drawing image\n"&#41;;


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

	SDL_FreeSurface&#40;surface&#41;;


	while&#40;1&#41;
	&#123;

	    // Clear the screen before drawing
		glClear&#40; GL_COLOR_BUFFER_BIT &#41;;
		glClearColor&#40;0.0f, 0.0f, 0.0f, 0.0f&#41;;
		glTexEnvi&#40;GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE&#41;;

		Display&#40;&#41;;
		printf&#40;"Calling swapbuffers\n"&#41;;
    	SDL_GL_SwapBuffers&#40;&#41;;

	&#125;

	glDeleteTextures&#40; 1, &tex &#41;;
	fclose&#40;output&#41;;

	return 0;
&#125;

void Display&#40;&#41;
&#123;

  float tX = 240;
  float tY = 136;

  glBindTexture&#40;GL_TEXTURE_2D, tex&#41;;

 glBegin&#40;GL_QUADS&#41;;
    glTexCoord2f&#40;0,0&#41;;
    glVertex2d&#40;-tX, -tY&#41;;

    glTexCoord2f&#40;1,0&#41;;
    glVertex2d&#40;tX, -tY&#41;;

    glTexCoord2f&#40;1,1&#41;;
    glVertex2d&#40;tX, tY&#41;;

    glTexCoord2f&#40;0,1&#41;;
    glVertex2d&#40;-tX, tY&#41;;

  glEnd&#40;&#41;;

&#125;
I also put it through the debugger and got this out of it:

Code: Select all

Program received signal SIGHUP, Hangup.
0x0884991c in sceGeListEnQueue &#40;&#41;
&#40;gdb&#41; backtrace
#0  0x0884991c in sceGeListEnQueue &#40;&#41;
#1  0xffffffff8809a3f8 in ?? &#40;&#41;
warning&#58; 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 &#40;corrupt stack?&#41;

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]
Post Reply