GU: 2 Boxes get the same color :(

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

Moderators: cheriff, TyRaNiD

Post Reply
thomas_fogh
Posts: 21
Joined: Fri Jul 20, 2007 10:22 pm
Location: Denmark

GU: 2 Boxes get the same color :(

Post by thomas_fogh »

Hi, I'm trying to draw a box with a frame around, but they get the same color even though I use to different textures.
Can someone see what's wrong with my code?

Code: Select all

  unsigned char  __attribute__((aligned(16))) solid_tex1[2] = { 0xff, 0x00 }; //YELLOW
  unsigned char  __attribute__((aligned(16))) solid_tex2[2] = { 0xf0, 0x00 }; //RED
....
  // setup GU

  sceGuInit();

  sceGuStart(GU_DIRECT,list);
  sceGuDrawBuffer(GU_PSM_8888,(void*)0,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(0xc350,0x2710);
  sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
  sceGuEnable(GU_SCISSOR_TEST);
  sceGuDepthFunc(GU_GEQUAL);
  sceGuEnable(GU_DEPTH_TEST);
  sceGuFrontFace(GU_CCW);
  sceGuShadeModel(GU_SMOOTH);
  sceGuEnable(GU_CULL_FACE);
  sceGuFinish();
  sceGuSync(0,0);

  sceDisplayWaitVblankStart();
  sceGuDisplay(GU_TRUE);

  // run sample

  int val = 0;

  for(;;)
    {
      sceGuStart(GU_DIRECT,list);

      // clear screen

      sceGuClearColor(0xff554433);
      sceGuClearDepth(0);
      sceGuClearStencil(0);
      sceGuClear(GU_COLOR_BUFFER_BIT   | 
		 GU_STENCIL_BUFFER_BIT | 
		 GU_DEPTH_BUFFER_BIT);

      // setup matrices for cube
      sceGumMatrixMode(GU_PROJECTION);
      sceGumLoadIdentity();
      sceGumOrtho(0,480,272,0, -250, 250);

      sceGumMatrixMode(GU_VIEW);
      {
        ScePspFVector3 pos = {xx, yy, zz};
        ScePspFVector3 rot = {rot_xx, rot_yy, rot_zz};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
        sceGumRotateXYZ(&rot);
      }
      sceGumMatrixMode(GU_MODEL);
      sceGumLoadIdentity();
      sceGuEnable(GU_TEXTURE_2D);
      sceGuTexMode(GU_PSM_4444,0,0,0);
      sceGuTexImage(0,1,1,1,solid_tex1);
      sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
      sceGuTexFilter(GU_LINEAR,GU_LINEAR);
      sceGuTexScale(1.0f,1.0f);
      sceGuTexOffset(0.0f,0.0f);
      sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF  | 
		      GU_COLOR_8888 | GU_VERTEX_32BITF | 
		      GU_TRANSFORM_3D, 36, 0, left_box);
      sceGuDisable(GU_TEXTURE_2D);

      sceGumMatrixMode(GU_MODEL);
      sceGumLoadIdentity();
      sceGuEnable(GU_TEXTURE_2D);
      sceGuTexMode(GU_PSM_4444,0,0,0);
      sceGuTexImage(0,1,1,1,solid_tex2);
      sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
      sceGuTexFilter(GU_LINEAR,GU_LINEAR);
      sceGuTexScale(1.0f,1.0f);
      sceGuTexOffset(0.0f,0.0f);
      sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF  | 
		      GU_COLOR_8888 | GU_VERTEX_32BITF | 
		      GU_TRANSFORM_3D, 36, 0, left_frame);
      sceGuDisable(GU_TEXTURE_2D);
		
      sceGuFinish();
      sceGuSync(0,0);

      sceDisplayWaitVblankStart();
      sceGuSwapBuffers();
    }

  sceGuTerm();
thomas_fogh
Posts: 21
Joined: Fri Jul 20, 2007 10:22 pm
Location: Denmark

Post by thomas_fogh »

Anyone?
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

Why do you draw a second GU_TRIANGLES (should it not a GU_LINES instead ?) for the frame over the box ?
thomas_fogh
Posts: 21
Joined: Fri Jul 20, 2007 10:22 pm
Location: Denmark

Post by thomas_fogh »

The frame is just another box slightly larger than the main box to get a wider frame.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

thomas_fogh wrote:The frame is just another box slightly larger than the main box to get a wider frame.
so always draw the largest one first then the smallest one. That is first left_frame, then left_box.
thomas_fogh
Posts: 21
Joined: Fri Jul 20, 2007 10:22 pm
Location: Denmark

Post by thomas_fogh »

The box is slightly thicker (z-axis) than the frame so that the frame doesn't overlap the box.
It's actually the frame that gets the same color as the box. (yellow).
Post Reply