using gummatrices instead of own matrices (no rendering)

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

using gummatrices instead of own matrices (no rendering)

Post by Ghoti »

Hi folks,

I have made some stuff with using my own matrices. Now I want to create the same things only with the sceGum matrix functions. So i thought i will make a small example of it but I just can't seem to get it to work :s

It renders nothing (what I can see on the screen) hope that you guys can see something wrong :s (the clearing of the screen works and it gets the purple color as supplied in code)

Code: Select all

void GameApp::Render() {
	// render information.
	sceGuStart(GU_DIRECT,list);

	// clear screen
	sceGuClearColor(0xff00ff);
	sceGuClearDepth(0);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	// setting the view
	sceGumMatrixMode(GU_VIEW); 
	sceGumLoadIdentity();
	ScePspFVector3 pos  = {0,0,500}; 
    ScePspFVector3 view = {0,0,0}; 
    ScePspFVector3 up   = {0,1,0}; 
    sceGumLookAt(&pos,&view,&up); 

	// model
	triangle->Render();

	// ending rendering
	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
}
and here is the code of the triangle:

Code: Select all

#include "Triangle.h"
#include <pspgu.h>
#include <pspgum.h>
#include "stdio.h"
#include "malloc.h"

Triangle&#58;&#58;Triangle&#40;&#41; &#123;

	triangle = &#40;vertex*&#41;memalign&#40;16,3 * sizeof&#40;vertex&#41;&#41;;
	triangle&#91;0&#93;.color = 0xff00ff00;
	triangle&#91;0&#93;.x = 0.0f;
	triangle&#91;0&#93;.y = 272.0f;
	triangle&#91;0&#93;.z = 0.0f;

	triangle&#91;1&#93;.color = 0xff00ff00;
	triangle&#91;1&#93;.x = 240.0f;
	triangle&#91;1&#93;.y = 0.0f;
	triangle&#91;1&#93;.z = 0.0f;

	triangle&#91;2&#93;.color = 0xff00ff00;
	triangle&#91;2&#93;.x = 480.0f;
	triangle&#91;2&#93;.y = 272.0f;
	triangle&#91;2&#93;.z = 0.0f;

	rot = 0.0f;

&#125;

Triangle&#58;&#58;~Triangle&#40;&#41; &#123;
	delete&#40;triangle&#41;;
&#125;

void Triangle&#58;&#58;Render&#40;&#41; &#123;

	rot += 0.5f;

	sceGumMatrixMode&#40;GU_MODEL&#41;; 
	sceGumLoadIdentity&#40;&#41;;
	sceGumRotateY&#40;rot&#41;;

	sceGuDrawArray&#40;GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle&#41;;	
&#125;
and in the load function of the gameapp I specify the projection matrix:

Code: Select all

// setting the projection
	sceGumMatrixMode&#40;GU_PROJECTION&#41;; 
	sceGumLoadIdentity&#40;&#41;; 
	sceGumPerspective&#40;45.0f,16.0f/9.0f,10.0f,1000.0f&#41;; 
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

If you use sceGum*()-functions for matrices, you must also switch to sceGumDraw*() instead of sceGuDraw*(), or call sceGumUpdateMatrix() before you call sceGuDraw*(), otherwise the library won't know when to flush the matrices to the hardware.
GE Dominator
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

hmmm thanks I did not know that. however now I get this error:

/usr/local/pspdev/psp/sdk/lib/libpspgum.a(sceGumUpdateMatrix.o): In function `sceGumUpdateMatrix':
/tmp/pspdev/pspsdk/src/gum/pspgum.c:572: undefined reference to `sceGuSetMatrix'

looks like something is wrong in the pspgum files ?
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Nope, but you have the linkorder for pspgum and pspgu wrong. Look at the samples for the correct order.
GE Dominator
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

hmmm k well that also did not the trick too bad but I have learned something extra about the functions :) It does not render the triangle :(

this is what i have now: (maybe I forgot something ?)

Code: Select all

#include "Triangle.h"
#include <pspgu.h>
#include <pspgum.h>
#include "stdio.h"
#include "malloc.h"

Triangle&#58;&#58;Triangle&#40;&#41; &#123;

	triangle = &#40;vertex*&#41;memalign&#40;16,3 * sizeof&#40;vertex&#41;&#41;;
	triangle&#91;0&#93;.color = 0xffffffff;
	triangle&#91;0&#93;.x = 0.0f;
	triangle&#91;0&#93;.y = 272.0f;
	triangle&#91;0&#93;.z = 0.0f;

	triangle&#91;1&#93;.color = 0xffffffff;
	triangle&#91;1&#93;.x = 240.0f;
	triangle&#91;1&#93;.y = 0.0f;
	triangle&#91;1&#93;.z = 0.0f;

	triangle&#91;2&#93;.color = 0xffffffff;
	triangle&#91;2&#93;.x = 480.0f;
	triangle&#91;2&#93;.y = 272.0f;
	triangle&#91;2&#93;.z = 0.0f;

	rot = 0.0f;

&#125;

Triangle&#58;&#58;~Triangle&#40;&#41; &#123;
	delete&#40;triangle&#41;;
&#125;

void Triangle&#58;&#58;Render&#40;&#41; &#123;

	rot += 0.1f;

	sceGumMatrixMode&#40;GU_MODEL&#41;; 
	sceGumLoadIdentity&#40;&#41;;
	sceGumRotateY&#40;rot&#41;;

	sceGumDrawArray&#40;GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle&#41;;	
&#125;
and the gameapp file:

Code: Select all

void GameApp&#58;&#58;Render&#40;&#41; &#123;
	// render information.
	sceGuStart&#40;GU_DIRECT,list&#41;;

	// clear screen
	sceGuClearColor&#40;0xff000000&#41;;
	sceGuClearDepth&#40;0&#41;;
	sceGuClear&#40;GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT&#41;;

	// setting the view
	sceGumMatrixMode&#40;GU_VIEW&#41;; 
	sceGumLoadIdentity&#40;&#41;;
	ScePspFVector3 pos  = &#123;0,0,500&#125;; 
    ScePspFVector3 view = &#123;0,0,0&#125;; 
    ScePspFVector3 up   = &#123;0,1,0&#125;; 
    sceGumLookAt&#40;&pos,&view,&up&#41;; 
	//sceGumUpdateMatrix&#40;&#41;;

	// model
	triangle->Render&#40;&#41;;

	// ending rendering
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0,0&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuSwapBuffers&#40;&#41;;
&#125;
hope you find something else :S
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Are you loading anything into the projection matrix? Without initializing that one, I think anything can happen.
GE Dominator
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Well I create the projection matrix as I have specified in the first post, didn't include it in the last post because i did not change it.

So I do an identity and then a sceGumPerspective, i do it only once in the load function.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hmmm well I also use now my usual matrix functions but they also do not work :s maybe it has something to do with my graphics initialization:

Code: Select all

bool GraphicsObject&#58;&#58;Init3DGraphics&#40;void&#41; &#123;

	// Initialize the GraphicalSystem
	sceGuInit&#40;&#41;;
	sceGuStart&#40;GU_DIRECT,list&#41;;
	sceGuDrawBuffer&#40;GU_PSM_8888,&#40;void*&#41;0,512&#41;;
	sceGuDispBuffer&#40;480,272,&#40;void*&#41;0x88000,512&#41;;
	sceGuDepthBuffer&#40;&#40;void*&#41;0x110000,512&#41;;
	sceGuOffset&#40;2048 - &#40;480/2&#41;,2048 - &#40;272/2&#41;&#41;;

	// create a viewport centered at 2048,2048 width 480 and height 272
	sceGuViewport&#40;2048,2048,480,272&#41;;
	sceGuDepthRange&#40;0xc350,0x2710&#41;;

	sceGuScissor&#40;0,0,480,272&#41;;
	sceGuEnable&#40;GU_SCISSOR_TEST&#41;;
	sceGuDepthFunc&#40;GU_GEQUAL&#41;;
	sceGuEnable&#40;GU_DEPTH_TEST&#41;;
	sceGuFrontFace&#40;GU_CW&#41;;
	sceGuShadeModel&#40;GU_SMOOTH&#41;;
	sceGuEnable&#40;GU_CULL_FACE&#41;;
	sceGuEnable&#40;GU_TEXTURE_2D&#41;;
	sceGuEnable&#40;GU_CLIP_PLANES&#41;;
	//sceGuEnable&#40;GU_LIGHTING&#41;;
	//sceGuEnable&#40;GU_BLEND&#41;;
	//sceGuBlendFunc&#40;GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0&#41;;
	sceGuFinish&#40;&#41;;
	// wait untill the list has finished.
	sceGuSync&#40;0,0&#41;;
	// turn on the display
	sceGuDisplay&#40;GU_TRUE&#41;;

	return true;
&#125;
Hope you can point something out ?
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

Make sure that whenever you start working with a matrix, you call gumLoadIdentity(). It works like sceGumLoadIdentity(), only, it takes a pointer to the ScePspFMatrix4 instance that you want to load the identity to. Make sure you load the identity with this function to all your instances of ScePspFMatrix4 before you do any calculations on it any frame. Also, you should only have to bother with setting up your projection only once every frame. That is, unless you are adjusting it for some special effects every frame. But yeah, just think of loading the identity matrix to your matrix like initializing it because that's what you're doing. It's like: 'int num = 0;'. You're declaring and initializing your integer, only with matrices, you'd do it like this:

Code: Select all

ScePspFMatrix4 mat;
gumLoadIdentity&#40;&mat&#41;;
That's what you want to do. Also, if you change your matrices every frame, you'll want to reset them every frame with gumLoadIdentity() every frame before you do any matrix calculations too. Otherwise, you'll end up getting your current frame's matrix operations with last frame's resultant matrix.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

so using:

Code: Select all

sceGumMatrixMode&#40;GU_VIEW&#41;; 
sceGumLoadIdentity&#40;&#41;;
does not work ? It should store the view matrix in memory and then make it an Identity, also my own code (which also does not work) just sets all the parts of the matrix to identity so it is always made to an identity. Since both ways do not work in this small example (And they do in a 3D game I am making) it feels strange that the problem lies there. I have looked up the gumLoadIdentity and it does nothing else then the scegumLoadIdentity only that it takes the matrix as a parameter.

I know how to identity a matrix and that you should always do that, but as you look to my code presented above I also always do just that.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Okay I solved the problem however in a very strange way (to me).

here is what was the trouble:

1: If you use this code:

Code: Select all

sceGumMatrixMode&#40;GU_MODEL&#41;; 
	sceGumLoadIdentity&#40;&#41;;
	sceGumRotateY&#40;rot&#41;;
You also have to have a variable:

Code: Select all

ScePspFMatrix4 world;
Why is this? It does not seem to me I use it. It is used because when I remove that variable it won't render anymore. Can someone explain this to me? and explain why this is done ? i think it is not very obvious :S

2: If I use:

Code: Select all

sceGuEnable&#40;GU_TEXTURE_2D&#41;;
It expects in any case a texture so if I only pass vertices and color to the draw function, it still expects texture or something because it won't render. When I do not enable it everything is rendered fine with the specified color.

I hope you guys can answer these questions. It would clearify a lot I guess.

greets ghoti
Post Reply