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 

[Solved]Some Help with Texturing on the GU

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



Joined: 20 Oct 2008
Posts: 355

PostPosted: Sat Jul 11, 2009 1:00 pm    Post subject: [Solved]Some Help with Texturing on the GU Reply with quote

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:
//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:
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
Back to top
View user's profile Send private message MSN Messenger
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Sun Jul 12, 2009 3:33 pm    Post subject: Reply with quote

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