 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Thu Feb 05, 2009 12:01 pm Post subject: Loading textures causes crash. |
|
|
I can't figure out what's causing the crash when I call glEnable(GL_TEXTURE_2D).
Is there something wrong with how I'm creating the textures?
| Code: |
glBindTexture(GL_TEXTURE_2D, surfaceTex[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
|
This works on windows. So i know it's not a normal OpenGL glitch. If anybody wants the full source, I can paste it.
| Code: | #include <SDL/SDL.h>
#include <SDL/SDL_OpenGL.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
#define PI 3.14159265
// This will determine what kind of tile we are looking at
static int level[8][8] =
{
{1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1},
{0,0,1,0,1,0,1,0},
{1,0,0,1,0,1,0,1},
{0,1,0,0,1,0,1,0},
{1,0,1,0,0,1,0,1},
{0,1,0,1,0,0,1,0},
{1,0,1,0,1,0,0,1}
};
// this will determine the height of each tile
static int height[8][8] =
{
{8,8,8,8,8,8,8,8},
{8,2,2,3,4,4,3,6},
{8,2,3,3,4,3,2,4},
{8,3,4,4,3,2,1,2},
{8,3,4,3,2,1,1,2},
{8,4,3,2,1,2,1,4},
{8,3,2,1,1,1,1,6},
{9,8,2,8,4,8,0,8}
};
// these two arrays contain the texture information
// relevant to the demonstration.
GLuint surfaceTex[2];
GLuint edgeTex[1];
// angle of rotation
float rAngle = 0;
// camera position
float xCam = 0;
float yCam = 0;
// This code creates the texture and loads it into memory
void BuildTextures()
{
// Load textures from file.
SDL_Surface *t0 = SDL_LoadBMP("000.bmp");
SDL_Surface *t1 = SDL_LoadBMP("001.bmp");
SDL_Surface *h0 = SDL_LoadBMP("100.bmp");
// allocate the texture slots.
glGenTextures(2, surfaceTex);
glGenTextures(1, edgeTex);
// setup the texture parameter
glBindTexture(GL_TEXTURE_2D, surfaceTex[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
// more texture loading
// Release the surfaces.
SDL_FreeSurface(t0);
SDL_FreeSurface(t1);
SDL_FreeSurface(h0);
}
// This code frees up the allocated textures.
void DeleteTextures()
{
glDeleteTextures(2, surfaceTex);
glDeleteTextures(1, edgeTex);
}
void DrawGridPiece(int x, int y, int h, GLint tileTex, GLint borderTex)
{
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, tileTex);
glTranslatef(x*64, h*16, y*64);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(0,0,0);
glTexCoord2f(0,1);
glVertex3f(0,0,64);
glTexCoord2f(1,1);
glVertex3f(64,0,64);
glTexCoord2f(1,0);
glVertex3f(64,0,0);
glEnd();
glPopMatrix();
// more drawing code
}
void SetupScene()
{
glViewport(0,0,480,272);
// glEnable(GL_TEXTURE_2D); // uncommenting this causes a crash
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100,100,-200,200,-300,300);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(35, 1, 0, 0);
}
void Render()
{
glClearColor(0,0,0,0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rAngle, 0,1,0);
glTranslatef(xCam, 0, yCam);
glTranslatef(0,-30,0);
for(int y = 0; y < 8; y +=1)
{
for(int x = 0; x < 8; x += 1)
{
DrawGridPiece(x,y,height[y][x], surfaceTex[level[y][x]],edgeTex[0]);
//DrawGridPiece(x,y,height[y][x], surfaceTex[0],0);
}
}
glPopMatrix();
SDL_GL_SwapBuffers();
}
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
extern "C"
int SDL_main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_SetVideoMode(480,272,32,SDL_OPENGL);
SetupScene();
BuildTextures();
SDL_Event e;
while(true)
{
SDL_PollEvent(&e);
if(e.type == SDL_QUIT)
break;
Render();
}
DeleteTextures();
SDL_Quit();
return 0;
}
|
Last edited by longjoel on Wed Feb 11, 2009 3:47 pm; edited 1 time in total |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Sat Feb 07, 2009 5:11 am Post subject: |
|
|
| Can I please get some help with this? I've been digging through the psgl source and i can't seem to find anything that i'm doing wrong. |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Wed Feb 11, 2009 3:47 pm Post subject: |
|
|
| pretty please? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Feb 11, 2009 6:47 pm Post subject: |
|
|
| You need to give more info, like where it actually blows up. Put logging in between all those commands and see what is the last thing to work. Or get it going in psplink if you can. You know - debug the thing. It LOOKS fine, which means you'll just have to get your hands dirty and log the hell out of it until you narrow it down. |
|
| Back to top |
|
 |
PosX100
Joined: 15 Aug 2007 Posts: 98
|
Posted: Wed Feb 11, 2009 7:57 pm Post subject: |
|
|
In your "buildTextures" function , you're creating 2 textures( 1 with size of 3 elements , and another one with 2), but only 1(Just 1 out of 5) actually
gets binded.
Its simple , you have no idea what you're doing ... |
|
| Back to top |
|
 |
kuroneko
Joined: 08 Dec 2005 Posts: 24 Location: Chigasaki, Japan
|
Posted: Wed Feb 11, 2009 9:03 pm Post subject: |
|
|
| PosX100 wrote: | In your "buildTextures" function , you're creating 2 textures( 1 with size of 3 elements , and another one with 2), but only 1(Just 1 out of 5) actually
gets binded.
Its simple , you have no idea what you're doing ... |
Could it be that it wasn't the complete source? There is a comment saying // more texture loading. |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Thu Feb 12, 2009 5:27 am Post subject: |
|
|
| PosX100 wrote: | In your "buildTextures" function , you're creating 2 textures( 1 with size of 3 elements , and another one with 2), but only 1(Just 1 out of 5) actually
gets binded.
Its simple , you have no idea what you're doing ... |
Thank you for your constructive feedback, PosX100. Your post has helped me more than I could ever imagine. You are truly an amazing resource.
@kuroneko:
I've been doing line item commenting and testing some of the code in other projects. The image loading code works. I'm not sure if my glTexParameteri values are valid though.
Weird, if i change this :
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
to this:
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, t0->pixels);
It executes, but shows the textures as the wrong color. I think i'm getting closer...
Is there a resource for the PSP version of OpenGL so I can know what's implemented and whats not? I haven't been able to find much on google about it. |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Thu Feb 12, 2009 7:57 am Post subject: |
|
|
I've narrowed it down, it is infact glTexImage that is causing the issue. It only seems to want to work with GL_RGB, trying to use GL_BGR causes it to crash.
Is there a way to get GL_BGR to work or am I going to have to alter my artwork or swap the red and blue channels when I load the texture? |
|
| Back to top |
|
 |
kuroneko
Joined: 08 Dec 2005 Posts: 24 Location: Chigasaki, Japan
|
Posted: Thu Feb 12, 2009 9:58 am Post subject: |
|
|
| longjoel wrote: | | I've narrowed it down, it is infact glTexImage that is causing the issue. It only seems to want to work with GL_RGB, trying to use GL_BGR causes it to crash. |
Does glTexImage actually accept GL_BGR, i.e. what is the status reported from glGetError() before and after this call? |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Thu Feb 12, 2009 3:45 pm Post subject: |
|
|
| kuroneko wrote: | | longjoel wrote: | | I've narrowed it down, it is infact glTexImage that is causing the issue. It only seems to want to work with GL_RGB, trying to use GL_BGR causes it to crash. |
Does glTexImage actually accept GL_BGR, i.e. what is the status reported from glGetError() before and after this call? |
I'll tell you after i get psplink working. lol |
|
| Back to top |
|
 |
kuroneko
Joined: 08 Dec 2005 Posts: 24 Location: Chigasaki, Japan
|
Posted: Thu Feb 12, 2009 3:57 pm Post subject: |
|
|
I just noticed something, you use
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
Internal format 3 and external being GL_BGR. They have to be the same. When you changed it to GL_RGB it worked because 3 is mapped to GL_RGB internally. So assuming GL_BGR is actually supported you should use
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
HTH |
|
| Back to top |
|
 |
longjoel
Joined: 29 Jan 2009 Posts: 14
|
Posted: Thu Feb 12, 2009 4:27 pm Post subject: |
|
|
| kuroneko wrote: | I just noticed something, you use
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
Internal format 3 and external being GL_BGR. They have to be the same. When you changed it to GL_RGB it worked because 3 is mapped to GL_RGB internally. So assuming GL_BGR is actually supported you should use
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR, 64, 64, 0, GL_BGR, GL_UNSIGNED_BYTE, t0->pixels);
HTH |
Still crashes. going to try and get PSPLink working so i can grab the glErrors. |
|
| Back to top |
|
 |
|
|
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
|