Using lighting and colours with pspgl

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

Moderators: cheriff, TyRaNiD

Post Reply
GlennNZ
Posts: 25
Joined: Sat Jan 13, 2007 1:13 pm

Using lighting and colours with pspgl

Post by GlennNZ »

I'm not sure if pspgl supports it but I'm trying to use the following code to create all the light induced shades on my model.

Code: Select all

glShadeModel(GL_SMOOTH);
//Set up lighting
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
I'm expecting my model to be coloured according to what I set using glColor but instead I get lots of shades of gray. It works when I run it in Linux though.

Does pspgl support GL_COLOR_MATERIAL? If not, what should I use instead? No lighting is not nice.

Cheers

Glenn
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

Im having the same problem. Im going to experiement around. Tell me if you get it working as well ;)
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

I do not do PSPGL, but just checking the sources out gives an answer:

Code: Select all

        case GL_COLOR_MATERIAL:
        case GL_RESCALE_NORMAL:
        case GL_POLYGON_OFFSET_FILL:
        case GL_VERTEX_ARRAY:
        case GL_NORMAL_ARRAY:
        case GL_COLOR_ARRAY:
        case GL_TEXTURE_COORD_ARRAY:
        case GL_MULTISAMPLE:
        case GL_SAMPLE_ALPHA_TO_COVERAGE:
        case GL_SAMPLE_ALPHA_TO_ONE:
        case GL_SAMPLE_COVERAGE:
        default:
                GLERROR(GL_INVALID_ENUM);
                return;
        }
GL_COLOR_MATERIAL is not supported :)
GL_NORMALIZE is not implemented either... Just a break into the abyss...

How to solve these problems? Use Gu/Gum :)
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Or fix PSPGL :)

On another note:
Are you in New Zealand GlennNZ?
I'm in Hamilton myself :)
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

Is there a way around it? Or would I have to disable lighting when drawing models with colors :-\
GlennNZ
Posts: 25
Joined: Sat Jan 13, 2007 1:13 pm

Post by GlennNZ »

adrahil wrote:I do not do PSPGL, but just checking the sources out gives an answer:

GL_COLOR_MATERIAL is not supported :)
GL_NORMALIZE is not implemented either... Just a break into the abyss...

How to solve these problems? Use Gu/Gum :)
Yeah, I saw that but was hoping for a workaround. I'm starting to think that texture mapping is the only solution (I'm not geeky enough to add to pspgl). I was trying to stay away from GU and GUM so I could keep my code as cross platform as possible but it looks like I have little choice if I'm to make a decent app. I'm currently using SDL + OpenGL.

Is it possible to do SDL + GU/GUM?

to danzel: Yes, I'm in Auckland. Maybe your screen name should instead be daNZel
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

So there is no wayaround it? :(

I made a 3d break out clone, and the ball emits light with a 0.2 attentuation. The walls are gray so they are affected by the balls light perfectly. But the bricks and paddel, both not being gray, dont change whatsoever when disabling lighting when rendierng them since color_material isnt implemented. It doesnt lookawful, but hte lighting looks great on windows opengl.

One thing im looking into is to use fog, have its origin be the ball, color be black or gray, and id judge the density and distance appropriatly, and this should replicate it...

What do you think? I rather not move to GU, mainly because i love the portability. I can develope a game on windows, port it to the PSP, as ive done here.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Fog is working nicely in Gu, with VFPU optimisations :3 And, to someone knowledgeable porting from OpenGL to Gu shouldn't be a problem, as the logic is the same, only the syntax changes...
GlennNZ
Posts: 25
Joined: Sat Jan 13, 2007 1:13 pm

The solution.

Post by GlennNZ »

Yes, I'm guilty of pulling this thread out of the abyss, but I have an excuse.

There is a way to work with materials using pspgl and for some reason I never posted the solution here. After breaking my PSP build a few months ago after a refactor, I came to this thread thinking I'd posted that solution. Turns out I didn't so now that I've only just figured out the solution, I've come to post it.

In order to use materials you have to use something like

Code: Select all

GLfloat materialColour[4] = {1.0f, 0.0f, 0.0f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColour);
The catch is that you have to enable lighting and disable blending i.e.

Code: Select all

glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
If blending is enabled, the model ends up being totally transparent. If lighting is disabled, the model turns white.

While I'm at it, another quirk of PSPGL is that when you use blending (such as with a texture with transparency) you have to disable lighting.

Cheers.
Post Reply