[Solved]Some Help with Texturing on the GU

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

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

[Solved]Some Help with Texturing on the GU

Post by coolkehon »

i need some help with texturing on the gu
1) i dont understand uv mapping can someone explain and i already search on google and wiki and looked at psp-programming tuts + ghoti.nl
2) i was able to get an image to load and display once but the framerate was 16 fps so i'm think i was doing something wrong + i was just fiddling with stuff to get it to work and dont know how it got there
3) my texture wont show up and i know the image data is loaded correctly

here is how i init the gu

Code: Select all

//Initializes the GU, preparing it for use.
	
	sceGuInit(); //Turn on the GU
	
	sceGuStart(GU_DIRECT, display_list); //Start filling a command list.
	
//	Set memory locations
	
	sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE); //Point out the display buffer
	
	sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE); //Point out the drawing buffer
	
	sceGuDepthBuffer((void*) (FRAMEBUFFER_SIZE*2), PSP_LINE_SIZE); //Point out the depth buffer
	
//	Configure viewport
	
	sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2)); //Define current drawing area.
	
	sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT); //Center screen in virtual space.
	
//	Set up scissor test
	
	sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); //Sets up a scissor rect for the screen.
	
	sceGuEnable(GU_SCISSOR_TEST); //Enables scissor mode: pixels outside the scissor rect are not rendered.
	
//	Set up alpha test
	
	sceGuAlphaFunc(GU_GREATER, 0, 0xff); //if((alpha & 0xFF) > (0 & 0xFF)) {render pixel}
	
	sceGuEnable(GU_ALPHA_TEST); //Enables sceGuAlphaFunc
	
//	Set up depth test
	
	sceGuDepthRange(0xc350, 0x2710); //Tells the GU what value range to use within the depth buffer.
	
	sceGuDepthFunc(GU_GEQUAL); //Pixels with z less than or equal to the existing pixel z pass the test.
	
	sceGuEnable(GU_DEPTH_TEST); //Only pixels that pass sceGuDepthFunc are rendered.
	
//	Set up texture processing
	
	sceGuEnable(GU_TEXTURE_2D); //Enables texturing of primitives.
	
	sceGuTexMode(GU_PSM_8888, 0, 0, GU_FALSE); //32-bit colors, no mipmaps, (unk - set to 0), interpret images as swizzled
	
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); //Configure the formulas used when blitting an image using sceGuTexImage
	
	sceGuShadeModel(GU_SMOOTH); //Set shading model (required by dialogs)
	
//	Set up alpha blending
	
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); //Set up blending formulas.
	
	sceGuEnable(GU_BLEND); //Activates blending according to sceGuBlendFunc
	
//	Set up screen clearing parameters
	
//	sceGuClearColor(0xFFFFFFFF); //Set the color used by sceGuClear when its passed GU_COLOR_BUFFER_BIT
	sceGuClearColor(0); //clear the screen black =)
	sceGuClearDepth(0); //Set the value to reset the depth buffer pixels to when using sceGuClear with the GU_DEPTH_BUFFER_BIT
	
//	Miscellanaus Stuff
	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuDisable(GU_TEXTURE_2D);
	sceGumOrtho(0,480,272,0,-1,1);
	
	sceGuFinish(); //End of command list
	
	sceGuSync(0, 0); //Wait for list to finish executing
	
	sceGuDisplay(GU_TRUE); //vram should be displayed on screen.
//	set so that we keep track of display of which display buffer is used
	dispBufferNumber = 0;
	return true;
here is the main function graphics->init3dgraphics is what inits gu and tga loader is from psp-programming.com gu tuturials and it loads the texture i gave it in the one from psp-programming.com but wont load the same texture using the same class here and i think i'm blitting it wrong
the canvas stuff doesnt do anything just a holder incase i need to do something so ignore it

Code: Select all

pspDebugScreenInit();
	sceRtcGetCurrentTick( &fpsTickLast );
	tickResolution = sceRtcGetTickResolution();
	
	CTGATexture texture;
	if(!texture.LoadTGA("NeHe.tga"))
	{
		printf("unable to load image");
		sceKernelDelayThread(3*1000*1000);
	}
	texture.Swizzled();
	
	GraphicsInstance * graphics = GraphicsInstance::Instance();
	graphics->Init3DGraphics();
	display_list = graphics->getDisplayList();
 
	DrawingCanvas canvas;
	int count = 0;
		
	while( 1 )
	{
		sceGuStart( GU_DIRECT, display_list );
		sceGuClearColor(GU_RGBA(255,255,255,255));
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
		
		sceGuDisable( GU_DEPTH_TEST );
		
		canvas.repaint();
		sceGuEnable(GU_TEXTURE_2D);
		sceGuTexMode( GU_PSM_8888, 0, 0, texture.Swizzled() );	
		sceGuTexFunc( GU_TFX_REPLACE, GU_TCC_RGB );	// Apply image as a decal (NEW)
		sceGuTexFilter( GU_LINEAR, GU_LINEAR );		// Linear filtering (Good Quality) (NEW)
		sceGuTexScale( 1.0f, 1.0f );                // No scaling
		sceGuTexOffset( 0.0f, 0.0f );
		
		typedef struct 
		{ 
			float u, v;
			float x, y, z; 
		} vertex2d; // vertex to render
		vertex2d * points = (vertex2d *)sceGuGetMemory(4 * sizeof(vertex2d));
		
	// setting the 4 vertices			
		points[0].u = 0.0f;
		points[0].v = 0.0f;
		points[0].x = 0;
		points[0].y = 0;
		points[0].z = 0.0f;
		
		points[1].u = texture.Width();
		points[1].v = 0.0f;
		points[1].x = texture.Width();
		points[1].y = 0;
		points[1].z = 0.0f;
		
		points[2].u = 0.0f;
		points[2].v = texture.Height()-1;
		points[2].x = 0;
		points[2].y = texture.Height()-1;
		points[2].z = 0.0f;
		
		points[3].u = texture.Width()-1;
		points[3].v = texture.Height()-1;
		points[3].x = texture.Width();
		points[3].y = texture.Height();
		points[3].z = 0.0f;
	
	// draw the trianglestrip with transform 2D
		sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, points);
		
		
		sceGuEnable( GU_DEPTH_TEST);
		
		sceGuFinish();
		sceGuSync(0,0);
		FPS();
		fbp0 = graphics->flipScreen();
	}
 
	delete GraphicsInstance::Instance();	// Terminating the Graphics System	
	return 0;
Last edited by coolkehon on Sun Jul 12, 2009 3:35 pm, edited 1 time in total.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

nvm i figured it out i never added the texture of be applied / upload the pixel data duh and i figure out uv mapping by looking at this thread

http://forums.ps2dev.org/viewtopic.php?t=5354
Post Reply