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 

Wrong Colours in GU_PSM_5551 colour mode

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



Joined: 21 Sep 2005
Posts: 28

PostPosted: Sun Nov 27, 2005 4:14 am    Post subject: Wrong Colours in GU_PSM_5551 colour mode Reply with quote

I started playing around with libGU a couple of days ago. I thought I'd start with something easy and looked at the Line Sample. I took away all the unnecessary code til I just had a function to draw lines. It worked perfectly. Then I switched to 5551 colour mode and wrote a simple function to convert 8888 colours to 5551 colours. The function still draws lines but they are in wrong colour, blue becomes green and green becomes orange. I searched the forum and found an other colour conversion function, but it gave me the same result. I printed out the coulor on the screen to check that it was the right value. So can someone tell me what the hell I do wrong!

Code:

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>

#include <pspgu.h>

PSP_MODULE_INFO("Line Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf

static unsigned int __attribute__((aligned(16))) list[262144];

struct Vertex
{
   float x,y,z;
};

int SetupCallbacks();

int done = 0;

#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (2)
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */

void DrawLine(int x1, int y1, int x2, int y2);
void InitGFX();
void Render();

void DrawLine(int x1, int y1, int x2, int y2)
{
   unsigned char r=255,b=0,g=0;
   unsigned short Color;
    Color=((b>>3)<<10) | ((g>>3)<<5) | (r>>3) | 0x8000;
      sceGuColor(Color);
         struct Vertex* vertices = sceGuGetMemory((2) * sizeof(struct Vertex));

         vertices[0].x = x1;
         vertices[0].y = y1;
         vertices[1].x = x2;
         vertices[1].y = y2;
      
         sceGuDrawArray(GU_LINE_STRIP,GU_VERTEX_32BITF|GU_TRANSFORM_2D,(2),0,vertices);
}

void InitGFX()
{

   sceGuInit();

   sceGuStart(GU_DIRECT,list);
   sceGuDrawBuffer(GU_PSM_5551,(void*)0,BUF_WIDTH);
   sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)FRAME_SIZE,BUF_WIDTH);
   sceGuDepthBuffer((void*)(FRAME_SIZE*2),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);
   sceGuFinish();
   sceGuSync(0,0);

   sceDisplayWaitVblankStart();
   sceGuDisplay(GU_TRUE);
}


void Render()
{
      sceGuStart(GU_DIRECT,list);

      // clear screen

      sceGuClearColor(0);
      sceGuClear(GU_COLOR_BUFFER_BIT);
      DrawLine(0,0,240,272);
      // wait for next frame

      sceGuFinish();
      sceGuSync(0,0);
      sceDisplayWaitVblankStart();
      sceGuSwapBuffers();
}


int main(int argc, char* argv[])
{

   SetupCallbacks();
   pspDebugScreenInit();
   InitGFX();
   while(!done)
   {
   Render();
   }

   sceGuTerm();

   sceKernelExitGame();
   return 0;
}

Back to top
View user's profile Send private message
memon



Joined: 03 Oct 2005
Posts: 63

PostPosted: Sun Nov 27, 2005 5:58 am    Post subject: Reply with quote

Unless you are dealing with vertex attributes or pixels, the API assumes R8G8B8A8 format. So you can change the frame buffer format but leave your data as it was.
Back to top
View user's profile Send private message
Mr.Modem



Joined: 21 Sep 2005
Posts: 28

PostPosted: Sun Nov 27, 2005 6:25 am    Post subject: Reply with quote

Thanks it worked!
Back to top
View user's profile Send private message
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