Wrong Colours in GU_PSM_5551 colour mode

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

Moderators: cheriff, TyRaNiD

Post Reply
Mr.Modem
Posts: 28
Joined: Wed Sep 21, 2005 4:43 am

Wrong Colours in GU_PSM_5551 colour mode

Post by Mr.Modem »

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

#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&#40;"Line Test", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;
#define printf pspDebugScreenPrintf

static unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; list&#91;262144&#93;;

struct Vertex
&#123;
	float x,y,z;
&#125;;

int SetupCallbacks&#40;&#41;;

int done = 0;

#define BUF_WIDTH &#40;512&#41;
#define SCR_WIDTH &#40;480&#41;
#define SCR_HEIGHT &#40;272&#41;
#define PIXEL_SIZE &#40;2&#41;
#define FRAME_SIZE &#40;BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE&#41;
#define ZBUF_SIZE &#40;BUF_WIDTH SCR_HEIGHT * 2&#41; /* zbuffer seems to be 16-bit? */

void DrawLine&#40;int x1, int y1, int x2, int y2&#41;;
void InitGFX&#40;&#41;;
void Render&#40;&#41;;

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

			vertices&#91;0&#93;.x = x1;
			vertices&#91;0&#93;.y = y1;
			vertices&#91;1&#93;.x = x2;
			vertices&#91;1&#93;.y = y2;
		
			sceGuDrawArray&#40;GU_LINE_STRIP,GU_VERTEX_32BITF|GU_TRANSFORM_2D,&#40;2&#41;,0,vertices&#41;;
&#125;

void InitGFX&#40;&#41;
&#123;

	sceGuInit&#40;&#41;;

	sceGuStart&#40;GU_DIRECT,list&#41;;
	sceGuDrawBuffer&#40;GU_PSM_5551,&#40;void*&#41;0,BUF_WIDTH&#41;;
	sceGuDispBuffer&#40;SCR_WIDTH,SCR_HEIGHT,&#40;void*&#41;FRAME_SIZE,BUF_WIDTH&#41;;
	sceGuDepthBuffer&#40;&#40;void*&#41;&#40;FRAME_SIZE*2&#41;,BUF_WIDTH&#41;;
	sceGuOffset&#40;2048 - &#40;SCR_WIDTH/2&#41;,2048 - &#40;SCR_HEIGHT/2&#41;&#41;;
	sceGuViewport&#40;2048,2048,SCR_WIDTH,SCR_HEIGHT&#41;;
	sceGuDepthRange&#40;0xc350,0x2710&#41;;
	sceGuScissor&#40;0,0,SCR_WIDTH,SCR_HEIGHT&#41;;
	sceGuEnable&#40;GU_SCISSOR_TEST&#41;;
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0,0&#41;;

	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuDisplay&#40;GU_TRUE&#41;;
&#125;


void Render&#40;&#41;
&#123;
		sceGuStart&#40;GU_DIRECT,list&#41;;

		// clear screen

		sceGuClearColor&#40;0&#41;;
		sceGuClear&#40;GU_COLOR_BUFFER_BIT&#41;;
		DrawLine&#40;0,0,240,272&#41;;
		// wait for next frame

		sceGuFinish&#40;&#41;;
		sceGuSync&#40;0,0&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
		sceGuSwapBuffers&#40;&#41;;
&#125;


int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;

	SetupCallbacks&#40;&#41;;
	pspDebugScreenInit&#40;&#41;;
	InitGFX&#40;&#41;;
	while&#40;!done&#41;
	&#123;
	Render&#40;&#41;;
	&#125;

	sceGuTerm&#40;&#41;;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

memon
Posts: 63
Joined: Mon Oct 03, 2005 10:51 pm

Post by memon »

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.
Mr.Modem
Posts: 28
Joined: Wed Sep 21, 2005 4:43 am

Post by Mr.Modem »

Thanks it worked!
Post Reply