 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Sun Nov 13, 2005 10:43 am Post subject: pspGL Texture problem |
|
|
i'm trying to port a basic texturing mapping code into pspgl, but when i run it, it, it seems to crash. giving me some errors. "Exception - Bus error<data>"
Here the code
| Code: | #include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <GL/glut.h>
/* ascii code for the escape key */
#define ESCAPE 27
/* The number of our GLUT window */
int window;
/* floats for x rotation, y rotation, z rotation */
float xrot, yrot, zrot;
/* storage for one texture */
int texture[1];
/* Image type - contains height, width, and data */
struct Image {
unsigned long sizeX;
unsigned long sizeY;
char *data;
};
typedef struct Image Image;
/******* PSP specific debugging ********************************************/
extern void __psp_log (const char *fmt, ...);
/* enable GLerror logging to "ms0:/log.txt" */
#if 1
#define GLCHK(x) \
do { \
GLint errcode; \
x; \
errcode = glGetError(); \
if (errcode != GL_NO_ERROR) { \
__psp_log("%s (%d): GL error 0x%04x\n", \
__FUNCTION__, __LINE__, \
(unsigned int) errcode); \
} \
} while (0)
#else
#define GLCHK(x) x
#endif
/******* end of PSP specific debugging *************************************/
// quick and dirty bitmap loader...for 24 bit bitmaps with 1 plane only.
int ImageLoad(char *filename, Image *image) {
FILE *file;
unsigned long size; // size of the image in bytes.
unsigned long i; // standard counter.
unsigned short int planes; // number of planes in image (must be 1)
unsigned short int bpp; // number of bits per pixel (must be 24)
char temp; // temporary color storage for bgr-rgb conversion.
// make sure the file is there.
if ((file = fopen(filename, "rb"))==NULL)
{
printf("File Not Found : %s\n",filename);
//return 0;
}
// seek through the bmp header, up to the width/height:
fseek(file, 18, SEEK_CUR);
// read the width
if ((i = fread(&image->sizeX, 4, 1, file)) != 1) {
printf("Error reading width from %s.\n", filename);
//return 0;
}
printf("Width of %s: %lu\n", filename, image->sizeX);
// read the height
if ((i = fread(&image->sizeY, 4, 1, file)) != 1) {
printf("Error reading height from %s.\n", filename);
//return 0;
}
printf("Height of %s: %lu\n", filename, image->sizeY);
// calculate the size (assuming 24 bits or 3 bytes per pixel).
size = image->sizeX * image->sizeY * 3;
// read the planes
if ((fread(&planes, 2, 1, file)) != 1) {
printf("Error reading planes from %s.\n", filename);
//return 0;
}
if (planes != 1) {
printf("Planes from %s is not 1: %u\n", filename, planes);
//return 0;
}
// read the bpp
if ((i = fread(&bpp, 2, 1, file)) != 1) {
printf("Error reading bpp from %s.\n", filename);
//return 0;
}
if (bpp != 24) {
printf("Bpp from %s is not 24: %u\n", filename, bpp);
//return 0;
}
// seek past the rest of the bitmap header.
fseek(file, 24, SEEK_CUR);
// read the data.
image->data = (char *) malloc(size);
if (image->data == NULL) {
printf("Error allocating memory for color-corrected image data");
//return 0;
}
if ((i = fread(image->data, size, 1, file)) != 1) {
printf("Error reading image data from %s.\n", filename);
//return 0;
}
for (i=0;i<size;i+=3) { // reverse all of the colors. (bgr -> rgb)
temp = image->data[i];
image->data[i] = image->data[i+2];
image->data[i+2] = temp;
}
// we're done.
return 1;
}
// Load Bitmaps And Convert To Textures
void LoadGLTextures() {
// Load Texture
Image *image1;
// allocate space for texture
image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
//exit(0);
}
if (!ImageLoad("Image.bmp", image1)) {
//exit(1);
}
// Create Texture
GLCHK(glGenTextures(1, &texture[0]));
GLCHK(glBindTexture(GL_TEXTURE_2D, texture[0])); // 2d texture (x and y size)
GLCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)); // scale linearly when image bigger than texture
GLCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)); // scale linearly when image smalled than texture
// 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
// border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
GLCHK(glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data));
};
/* A general OpenGL initialization function. Sets all of the initial parameters. */
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
{
//LoadGLTextures(); // Load The Texture(s)
GLCHK(glEnable(GL_TEXTURE_2D)); // Enable Texture Mapping
GLCHK(glClearColor(0.0f, 0.0f, 1.0f, 0.0f)); // Clear The Background Color To Blue
GLCHK(glClearDepth(1.0)); // Enables Clearing Of The Depth Buffer
GLCHK(glDepthFunc(GL_LESS)); // The Type Of Depth Test To Do
GLCHK(glEnable(GL_DEPTH_TEST)); // Enables Depth Testing
GLCHK(glShadeModel(GL_SMOOTH)); // Enables Smooth Color Shading
GLCHK(glMatrixMode(GL_PROJECTION));
GLCHK(glLoadIdentity()); // Reset The Projection Matrix
GLCHK(gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f)); // Calculate The Aspect Ratio Of The Window
GLCHK(glMatrixMode(GL_MODELVIEW));
}
static
void reshape (int w, int h)
{
GLCHK(glViewport(0, 0, w, h));
GLCHK(glMatrixMode(GL_PROJECTION));
GLCHK(glLoadIdentity());
GLCHK(glOrtho(-2, 2, -2, 2, -2, 2));
GLCHK(gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f));
GLCHK(glMatrixMode(GL_MODELVIEW));
GLCHK(glLoadIdentity());
}
static float delta = 1.0;
static
void display (void)
{
GLCHK(glShadeModel(GL_SMOOTH));
GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); // Clear The Screen And The Depth Buffer
GLCHK(glLoadIdentity()); // Reset The View
GLCHK(glTranslatef(0.0f,0.0f,-5.0f)); // move 5 units into the screen.
GLCHK(glRotatef(xrot,1.0f,0.0f,0.0f)); // Rotate On The X Axis
GLCHK(glRotatef(yrot,0.0f,1.0f,0.0f)); // Rotate On The Y Axis
GLCHK(glRotatef(zrot,0.0f,0.0f,1.0f)); // Rotate On The Z Axis
GLCHK(glBindTexture(GL_TEXTURE_2D, texture[0])); // choose the texture to use.
GLCHK(glBegin(GL_QUADS)); // begin drawing a cube
// Front Face (note that the texture's corners have to match the quad's corners)
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, 1.0f)); // Bottom Left Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, 1.0f)); // Bottom Right Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, 1.0f)); // Top Right Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, 1.0f)); // Top Left Of The Texture and Quad
// Back Face
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, -1.0f)); // Bottom Right Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, -1.0f)); // Top Right Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, -1.0f)); // Top Left Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, -1.0f)); // Bottom Left Of The Texture and Quad
// Top Face
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, -1.0f)); // Top Left Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, 1.0f)); // Bottom Left Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, 1.0f)); // Bottom Right Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, -1.0f)); // Top Right Of The Texture and Quad
// Bottom Face
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, -1.0f)); // Top Right Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, -1.0f)); // Top Left Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, 1.0f)); // Bottom Left Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, 1.0f)); // Bottom Right Of The Texture and Quad
// Right face
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, -1.0f)); // Bottom Right Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, -1.0f)); // Top Right Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f( 1.0f, 1.0f, 1.0f)); // Top Left Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f( 1.0f, -1.0f, 1.0f)); // Bottom Left Of The Texture and Quad
// Left Face
GLCHK(glTexCoord2f(0.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, -1.0f)); // Bottom Left Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 0.0f)); GLCHK(glVertex3f(-1.0f, -1.0f, 1.0f)); // Bottom Right Of The Texture and Quad
GLCHK(glTexCoord2f(1.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, 1.0f)); // Top Right Of The Texture and Quad
GLCHK(glTexCoord2f(0.0f, 1.0f)); GLCHK(glVertex3f(-1.0f, 1.0f, -1.0f)); // Top Left Of The Texture and Quad
GLCHK(glEnd()); // done with the polygon.
xrot+=15.0f; // X Axis Rotation
yrot+=15.0f; // Y Axis Rotation
zrot+=15.0f; // Z Axis Rotation
// since this is double buffered, swap the buffers to display what just got drawn.
glutSwapBuffers();
glutPostRedisplay();
}
static
void keydown (unsigned char key, int x, int y)
{
switch (key) {
case 'd': /* delta, triangle */
break;
case 'o': /* round */
delta = 0.0f;
break;
case 'q': /* square*/
break;
case 'x': /* cross button */
exit(0);
break;
default:
;
}
}
static
void keyup (unsigned char key, int x, int y)
{
switch (key) {
case 'o':
delta = 1.0f;
break;
default:
;
}
}
static
void joystick (unsigned int buttonMask, int x, int y, int z)
{
GLCHK(glClearColor(x * 1.0f/2000.0f + 0.5f, y * 1.0f/2000.0f + 0.5f, 1.0f, 1.0f));
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutCreateWindow( __FILE__ );
glutKeyboardFunc(keydown);
glutKeyboardUpFunc(keyup);
glutJoystickFunc(joystick, 0);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
InitGL(480, 272);
glutMainLoop();
return 0;
}
|
If i comment out the LoadGLTextures() function, it seems to work, but instead of a rotating cube, its a blur of boxes. that dont resemble a cube at all.
edit: Okay, figure out the weird shaped object problem. its because pspgl only read in triangles not quads. that problem has now been fix. but the texture problem is still there. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
Ryu
Joined: 17 Oct 2005 Posts: 19
|
Posted: Sun Nov 13, 2005 7:22 pm Post subject: |
|
|
the crash probably occurs when you're trying to load the image, try to identify the problem by commenting less and less stuff in the image loader;
and if the problem is not there (i just read the code it seems ok) then comment the pspgl lines in the LoadTextures function instead, that way you might be able to find exactly where it crashes. |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Mon Nov 14, 2005 4:29 am Post subject: |
|
|
this is the exact function that crashes the program. dont know why.
| Code: | if (!ImageLoad("Image.bmp", image1)) {
//exit(1);
} |
does psp have a problem loading bmp images? _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Tue Nov 15, 2005 6:08 am Post subject: |
|
|
| maybe you want to try an absolute path, including the memory stick device prefix. |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Tue Nov 15, 2005 8:55 am Post subject: |
|
|
| holger wrote: | | maybe you want to try an absolute path, including the memory stick device prefix. |
well what is the root path for the ms in the psp? "f:/" or should i just use "/" since "/" is consider to be root.
But i dont know if that is the problem. if it cant find the image, it will load fine, and will not display it. but if the image was found, it will give an error. here link to screens of errors.
http://geocities.com/tsune_l/180658.jpg
http://geocities.com/tsune_l/180705.jpg
get the same error with the OBJ viewer i wrote
http://forums.ps2dev.org/viewtopic.php?t=4109
Here link to download the bin and src direct.
http://geocities.com/tsune_l/pspgl_obj.zip
Edit: It doesnt make a difference. i've set the absolute path, and still i get an error. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Tue Nov 15, 2005 1:13 pm Post subject: |
|
|
there are many known memorystick root
absolute paths you can use
different name, same story ;)
ms0:/
fatms0:/
ftms0:/
ms1:/
etc...
i generally just use ms0:/
OT: i like your coding style more more people
should comment properly as you do ....really
adds class in my opinion to some sources ;) _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Tue Nov 15, 2005 1:47 pm Post subject: |
|
|
| dot_blank wrote: | there are many known memorystick root
absolute paths you can use
different name, same story ;)
ms0:/
fatms0:/
ftms0:/
ms1:/
etc...
i generally just use ms0:/
OT: i like your coding style more more people
should comment properly as you do ....really
adds class in my opinion to some sources ;) |
none the less, it still finds the file. when the file is found, it crashes. because if its not found, it does not display image. plus the "/" symbol means the root of that directory. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Thu Dec 08, 2005 8:30 am Post subject: |
|
|
| Does it crash in a GL call, or in some other place? Does it still crash if you remove all the GL calls? |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Thu Dec 08, 2005 9:40 am Post subject: |
|
|
it crashes when trying to load a file. every time i try to load any file whether it is a bmp or obj file it crashes. So i believe the source of the problem is the io, working with pspgl. I'm going to try to write a simple app using pspgl, that loads a simple txt file and see if i get the same problem. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| Back to top |
|
 |
jsgf
Joined: 12 Jul 2005 Posts: 254
|
Posted: Thu Dec 08, 2005 9:49 am Post subject: |
|
|
| It would be more interesting to try your program with .bmp IO with the GL calls commented out. That would help isolate the problem. |
|
| Back to top |
|
 |
Thanhda

Joined: 09 Apr 2005 Posts: 331 Location: Canada
|
Posted: Thu Dec 08, 2005 11:34 am Post subject: |
|
|
i know its not the problem of binding the texture to the geometry, but its the loading itself. but yes i will try many test to run txt files, obj and bmp images without any gl call. _________________ There are 10 types of people in the world: Those who understand binary, and those who don't... |
|
| 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
|