forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

using gummatrices instead of own matrices (no rendering)

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sat Sep 22, 2007 10:08 pm    Post subject: using gummatrices instead of own matrices (no rendering) Reply with quote

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:
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:
#include "Triangle.h"
#include <pspgu.h>
#include <pspgum.h>
#include "stdio.h"
#include "malloc.h"

Triangle::Triangle() {

   triangle = (vertex*)memalign(16,3 * sizeof(vertex));
   triangle[0].color = 0xff00ff00;
   triangle[0].x = 0.0f;
   triangle[0].y = 272.0f;
   triangle[0].z = 0.0f;

   triangle[1].color = 0xff00ff00;
   triangle[1].x = 240.0f;
   triangle[1].y = 0.0f;
   triangle[1].z = 0.0f;

   triangle[2].color = 0xff00ff00;
   triangle[2].x = 480.0f;
   triangle[2].y = 272.0f;
   triangle[2].z = 0.0f;

   rot = 0.0f;

}

Triangle::~Triangle() {
   delete(triangle);
}

void Triangle::Render() {

   rot += 0.5f;

   sceGumMatrixMode(GU_MODEL);
   sceGumLoadIdentity();
   sceGumRotateY(rot);

   sceGuDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle);   
}


and in the load function of the gameapp I specify the projection matrix:
Code:
// setting the projection
   sceGumMatrixMode(GU_PROJECTION);
   sceGumLoadIdentity();
   sceGumPerspective(45.0f,16.0f/9.0f,10.0f,1000.0f);

_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sat Sep 22, 2007 10:25 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sat Sep 22, 2007 10:41 pm    Post subject: Reply with quote

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 ?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sat Sep 22, 2007 11:16 pm    Post subject: Reply with quote

Nope, but you have the linkorder for pspgum and pspgu wrong. Look at the samples for the correct order.
_________________
GE Dominator
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sat Sep 22, 2007 11:46 pm    Post subject: Reply with quote

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:
#include "Triangle.h"
#include <pspgu.h>
#include <pspgum.h>
#include "stdio.h"
#include "malloc.h"

Triangle::Triangle() {

   triangle = (vertex*)memalign(16,3 * sizeof(vertex));
   triangle[0].color = 0xffffffff;
   triangle[0].x = 0.0f;
   triangle[0].y = 272.0f;
   triangle[0].z = 0.0f;

   triangle[1].color = 0xffffffff;
   triangle[1].x = 240.0f;
   triangle[1].y = 0.0f;
   triangle[1].z = 0.0f;

   triangle[2].color = 0xffffffff;
   triangle[2].x = 480.0f;
   triangle[2].y = 272.0f;
   triangle[2].z = 0.0f;

   rot = 0.0f;

}

Triangle::~Triangle() {
   delete(triangle);
}

void Triangle::Render() {

   rot += 0.1f;

   sceGumMatrixMode(GU_MODEL);
   sceGumLoadIdentity();
   sceGumRotateY(rot);

   sceGumDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3, 0, triangle);   
}


and the gameapp file:
Code:
void GameApp::Render() {
   // render information.
   sceGuStart(GU_DIRECT,list);

   // clear screen
   sceGuClearColor(0xff000000);
   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);
   //sceGumUpdateMatrix();

   // model
   triangle->Render();

   // ending rendering
   sceGuFinish();
   sceGuSync(0,0);
   sceDisplayWaitVblankStart();
   sceGuSwapBuffers();
}


hope you find something else :S
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Sep 23, 2007 3:21 am    Post subject: Reply with quote

Are you loading anything into the projection matrix? Without initializing that one, I think anything can happen.
_________________
GE Dominator
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Sep 23, 2007 4:37 am    Post subject: Reply with quote

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.
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Thu Sep 27, 2007 4:09 am    Post subject: Reply with quote

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:
bool GraphicsObject::Init3DGraphics(void) {

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

   // create a viewport centered at 2048,2048 width 480 and height 272
   sceGuViewport(2048,2048,480,272);
   sceGuDepthRange(0xc350,0x2710);

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

   return true;
}


Hope you can point something out ?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Vincent_M



Joined: 03 Apr 2007
Posts: 73

PostPosted: Thu Sep 27, 2007 6:47 am    Post subject: Reply with quote

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:

ScePspFMatrix4 mat;
gumLoadIdentity(&mat);


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.
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Thu Sep 27, 2007 7:06 am    Post subject: Reply with quote

so using:
Code:
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
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.
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sat Sep 29, 2007 2:25 am    Post subject: Reply with quote

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:
sceGumMatrixMode(GU_MODEL);
   sceGumLoadIdentity();
   sceGumRotateY(rot);
You also have to have a variable:
Code:
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:
sceGuEnable(GU_TEXTURE_2D);
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
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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