I have a new problem now, and my instant guess is I either forgot something or I'm doing something I shouldn't be.
First of all this code runs fine thru SDL on Windows - so I dont think its the code (mainly just hacked together from various tutorials) hence the guess of doing something I shouldn't be. Also just want to point out that I want to keep the code so that it will run on both windows and PSP with minimal code differences.
The problem is it wont render the texture, just a black quad.
Heres the code (it's in a cpp file, thats why theres an extern C)
Code: Select all
/* Test SDL OpenGL support. */
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_opengl.h"
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
SDL_Surface* screen;
GLuint image;//This is our texture
SDL_Surface *temp, *temp2;//This will help get the pixel data for our texture
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
// Load image
SDL_Surface* LoadImage = IMG_Load("TEST.PNG");
if (LoadImage == NULL) {
fprintf(stderr, "IMG_Load: %s\n", IMG_GetError());
return 1;
}
// Convert using SDL_DisplayFormatAlpha
temp2 = SDL_DisplayFormatAlpha( LoadImage );
// Call SDL_SetAlpha on surface
SDL_SetAlpha( temp2, 0, 0 );
// Create temp RGB surface and blit to it
temp = SDL_CreateRGBSurface(temp2->flags, temp2->w, temp2->h, temp2->format->BitsPerPixel, temp2->format->Rmask, temp2->format->Gmask, temp2->format->Bmask, temp2->format->Amask );
SDL_BlitSurface( temp2, NULL, temp, NULL );
if ( temp ) {
//Check that the image is square (width equal to height)
if (temp->w != temp->h) {
return 2;
}
//Check that the image's width is valid and then check that the image's width is a power of 2
if (temp->w < 1) {
return 3;
} else if ( !((temp->w & (temp->w-1))==0) ) {
return 4;
}
//Create the texture
glGenTextures(1, &image);
//Load the texture
glBindTexture(GL_TEXTURE_2D, image);
//Generate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, temp->w, temp->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp->pixels);
//Use nearest filtering, very good
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} else {
return 5;
}
//Free up our temp surface if it was ever used
if (temp) {
SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
SDL_FreeSurface(LoadImage);
}
return 0; // Return The Status
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
float x = 32.0f, y = 16.0f;
//Make certain everything is cleared from the screen before we draw to it
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Enable texturing
glEnable(GL_TEXTURE_2D);
// Enable transparency
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
//Load the texture
glBindTexture(GL_TEXTURE_2D, image);
glBegin(GL_QUADS);
// ISO tile
////Top-left vertex (corner)
//glTexCoord2i(0,0);
//glVertex3f(x, y-16.0f, 0.0f);
////Bottom-left vertex (corner)
//glTexCoord2i(0,1);
//glVertex3f(x-32.0f, y, 0.0f);
////Bottom-right vertex (corner)
//glTexCoord2i(1,1);
//glVertex3f(x, y+16, 0.0f);
////Top-right vertex (corner)
//glTexCoord2i(1,0);
//glVertex3f(x+32, y, 0.0f);
// Fullscreen
//Top-left vertex (corner)
glTexCoord2f(0.0f,0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
//Bottom-left vertex (corner)
glTexCoord2f(0.0f,1.0f);
glVertex3f(0.0f, SCREEN_HEIGHT, 0.0f);
//Bottom-right vertex (corner)
glTexCoord2f(1.0f,1.0f);
glVertex3f(SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f);
//Top-right vertex (corner)
glTexCoord2f(1.0f,0.0f);
glVertex3f(SCREEN_WIDTH, 0.0f, 0.0f);
glEnd();
//Disable texturing
glDisable(GL_TEXTURE_2D); // Keep Going
glDisable(GL_BLEND);
return 1;
}
extern "C" {
int SDL_main() {
//int main(int argc, char* argv[]) {
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;
}
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if ( (screen=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(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f);
// glOrtho(-2, 2, -2, 2, -2, 2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
int result = LoadGLTextures();
if( result != 0 ) {
fprintf(stderr, "Unable to load textures. Returned %d\n", result);
SDL_Quit();
return 1;
}
glClearColor(1.0f,0.0f,1.0f,0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glDisable(GL_CULL_FACE);
while (!done)
{
// glClearColor(1.0f, 0.0f, 1.0f, 0.5f);
//
// 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();
DrawGLScene();
// glFinish();
SDL_GL_SwapBuffers();
}
return 0;
}
}//extern "C"
Code: Select all
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 += -lSDL_image -lpng -lz -ljpeg -lglut -lGLU -lGL `$(PSPBIN)/sdl-config --libs` -lm -lc -lpspdebug -lpspge -lpspdisplay -lpspctrl -lpspsdk -lpspvfpu -lpspuser -lpspkernel -lstdc++
include $(PSPSDK)/lib/build.mak
Thanks in advance for any help.