Mixing 3d and 2d

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

Moderators: cheriff, TyRaNiD

Post Reply
darkplastic
Posts: 6
Joined: Fri Dec 15, 2006 8:50 pm

Mixing 3d and 2d

Post by darkplastic »

Has anyone got any advice on this? Currently i am following the tutorials @ http://www.psp-programming.com/code/ind ... rt-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: Select all

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: Select all


	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
darkplastic
Posts: 6
Joined: Fri Dec 15, 2006 8:50 pm

Code to the blit alpha image function:

Post by darkplastic »

Code: Select all

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 &#40;j < width&#41; &#123;
		Vertex* vertices = &#40;Vertex*&#41; sceGuGetMemory&#40;2 * sizeof&#40;Vertex&#41;&#41;;
		int sliceWidth = 64;
		if &#40;j + sliceWidth > width&#41; sliceWidth = width - j;
		vertices&#91;0&#93;.u = sx + j;
		vertices&#91;0&#93;.v = sy;
		vertices&#91;0&#93;.x = dx + j;
		vertices&#91;0&#93;.y = dy;
		vertices&#91;0&#93;.z = 0;
		vertices&#91;1&#93;.u = sx + j + sliceWidth;
		vertices&#91;1&#93;.v = sy + height;
		vertices&#91;1&#93;.x = dx + j + sliceWidth;
		vertices&#91;1&#93;.y = dy + height;
		vertices&#91;1&#93;.z = 0;
		sceGuDrawArray&#40;GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices&#41;;
		j += sliceWidth;
	&#125;
	
	//sceGuFinish&#40;&#41;;
	//sceGuSync&#40;0, 0&#41;;
&#125;
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
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

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
Bytrix
Posts: 72
Joined: Wed Sep 14, 2005 7:26 pm
Location: England

Post by Bytrix »

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.
Post Reply