 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
NovaCaine
Joined: 20 Dec 2005 Posts: 34 Location: New Zealand
|
Posted: Fri Feb 10, 2006 12:12 pm Post subject: Textured Quads Problem (SDL/OPENGL) |
|
|
Hey all,
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: |
/* 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"
|
And the makefile
| Code: |
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
|
Any Ideas?
Thanks in advance for any help. _________________ My work:
TrackBundler for Gripshift
Last edited by NovaCaine on Fri Feb 10, 2006 1:30 pm; edited 1 time in total |
|
| Back to top |
|
 |
HaQue
Joined: 25 Nov 2005 Posts: 91 Location: Adelaide, Australia
|
Posted: Fri Feb 10, 2006 1:29 pm Post subject: |
|
|
in your code it is test.png, so use that. is the /Data/ folder "Data" as in your code? and is the image actaully in YOURAPP/Data/test.png? _________________ www.smartwave-wireless.com |
|
| Back to top |
|
 |
NovaCaine
Joined: 20 Dec 2005 Posts: 34 Location: New Zealand
|
Posted: Fri Feb 10, 2006 1:32 pm Post subject: |
|
|
sorry, I just edited the whole first post to refer to a new problem. the first problem was a basic logic error
| Code: |
if (!LoadImage == NULL) {
should have read
if (LoadImage == NULL) {
|
Now my problem is the texture isn't rendering to the quad, and I get a black square instead. _________________ My work:
TrackBundler for Gripshift |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Fri Feb 10, 2006 2:06 pm Post subject: |
|
|
I thought pspgl didn't support quads at all?
Or is that fixed by now? :| |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sat Feb 11, 2006 6:53 am Post subject: |
|
|
Correct - GL_QUADS is mapped to GL_TRIANGLE_FAN, so if you only render one quad at a time it's ok (but slow if you do lots), but it's broken if you try to draw more than one.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
NovaCaine
Joined: 20 Dec 2005 Posts: 34 Location: New Zealand
|
Posted: Sat Feb 11, 2006 1:57 pm Post subject: |
|
|
| Jim wrote: | Correct - GL_QUADS is mapped to GL_TRIANGLE_FAN, so if you only render one quad at a time it's ok (but slow if you do lots), but it's broken if you try to draw more than one.
Jim |
I had only just realised this after I had posted and left work (I currently dont have the net at home.) but even after I had changed it to triangles it crashes majorly (No BSOD, and have to manually reset the PSP). Just wondering how I would go about rendering a textured triangle, as I'm guessing there is something PSPGL doesn't like about my code. _________________ My work:
TrackBundler for Gripshift |
|
| 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
|