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 

Mixing 3d and 2d

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



Joined: 15 Dec 2006
Posts: 6

PostPosted: Tue Dec 19, 2006 12:19 pm    Post subject: Mixing 3d and 2d Reply with quote

Has anyone got any advice on this? Currently i am following the tutorials @ http://www.psp-programming.com/code/index.php?id=c:pspgu-neheport-lesson1 to do with PSPGU, after having completed all the tutorials at http://www.psp-programming.com/tutorials/.....My issue is that before i was using loadImage to load a png image then blitTransparentImage from the graphics cpp file provided to make 2d games. However i cant seem to find a compatible set of flags that enables me to make both my 3d objects and 2d objects work.....currently i use this initialisation for my 3d stuff:

Code:

sceGuInit();
   sceGuStart( GU_DIRECT, dList );

   // Set Buffers
   sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH );
   sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
   sceGuDepthBuffer( (void*)0x110000, BUF_WIDTH);

   sceGuOffset( 2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
   sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT);
   sceGuDepthRange( 65535, 0);

   // Set Render States
   sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT);
   sceGuEnable( GU_SCISSOR_TEST );
   sceGuDepthFunc( GU_GEQUAL );
   sceGuShadeModel( GU_SMOOTH );
   sceGuEnable( GU_CLIP_PLANES );
   
   sceGuBlendFunc( GU_ADD, GU_FIX, GU_FIX, 0xff888888, 0xff888888 );
   
   sceGuFinish();
   sceGuSync(0,0);

   sceDisplayWaitVblankStart();
   sceGuDisplay(GU_TRUE);


and this is whats in the graphics cpp file for the 2d stuff:

Code:


   sceGuInit();

   guStart();
   sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE);
   sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE);
   sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
   sceGuDepthBuffer((void*) (FRAMEBUFFER_SIZE*2), PSP_LINE_SIZE);
   sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
   sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
   sceGuDepthRange(0xc350, 0x2710);
   sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
   sceGuEnable(GU_SCISSOR_TEST);
   sceGuAlphaFunc(GU_GREATER, 0, 0xff);
   sceGuEnable(GU_ALPHA_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);
   sceGuTexMode(GU_PSM_8888, 0, 0, 0);
   sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
   sceGuTexFilter(GU_NEAREST, GU_NEAREST);
   sceGuAmbientColor(0xffffffff);
   sceGuEnable(GU_BLEND);
   sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
   sceGuFinish();
   sceGuSync(0, 0);

   sceDisplayWaitVblankStart();
   sceGuDisplay(GU_TRUE);


if i call just the 3d one the images are blitted as black boxes.....if i call just the 2d one the program doesnt even run and if i call both then the 2d image gets blitted correctly but the 3d shapes appear all messed up with crazy lines for textures! What combination of flags could i use to get both to work? Thanks in advance!

-James Grafton
Back to top
View user's profile Send private message
darkplastic



Joined: 15 Dec 2006
Posts: 6

PostPosted: Wed Dec 20, 2006 3:07 am    Post subject: Code to the blit alpha image function: Reply with quote

Code:

void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy)
{
   if (!initialized) return;

   sceKernelDcacheWritebackInvalidateAll();
   //guStart();
   sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data);
   float u = 1.0f / ((float)source->textureWidth);
   float v = 1.0f / ((float)source->textureHeight);
   sceGuTexScale(u, v);
   
   int j = 0;
   while (j < width) {
      Vertex* vertices = (Vertex*) sceGuGetMemory(2 * sizeof(Vertex));
      int sliceWidth = 64;
      if (j + sliceWidth > width) sliceWidth = width - j;
      vertices[0].u = sx + j;
      vertices[0].v = sy;
      vertices[0].x = dx + j;
      vertices[0].y = dy;
      vertices[0].z = 0;
      vertices[1].u = sx + j + sliceWidth;
      vertices[1].v = sy + height;
      vertices[1].x = dx + j + sliceWidth;
      vertices[1].y = dy + height;
      vertices[1].z = 0;
      sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
      j += sliceWidth;
   }
   
   //sceGuFinish();
   //sceGuSync(0, 0);
}


Looking at this again it seems that it need GU_TRANSFORM_2D flag to work...if i set this when the program is initialised then the 3d animation wont work is there any way around this? Cheers
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Thu Dec 21, 2006 7:55 pm    Post subject: Reply with quote

Hi i have the same problem, however i was going to try and just render a triangle with the texture and put it in front of the camera. However this does not seem like the best option so i also would like to know how.
3d stuff is working, my ingame menu also because i don't have to render any 3d then and just set the camera at the origin and render traingles to display my maps and ingame stuff.

hope that someone can help us out :D

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
Bytrix



Joined: 14 Sep 2005
Posts: 72
Location: England

PostPosted: Thu Dec 21, 2006 8:52 pm    Post subject: Reply with quote

I've always used 3D elements for my '2D' on-screen displays. I think it's alot better really because you can get some fancy effects if people turn the on-screen map off you can rotate it, shrink, stretch etc.. as it removes itself from the screen, or provide cool transitions as messages come up and fade away.
Back to top
View user's profile Send private message Send e-mail
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