Strange blitting of sprites

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Strange blitting of sprites

Post by Ghoti »

Hi folks,

I'm trying to make an messagesystem. It displays a message on screen when you encounter a door for example. The message"press x to open the door" will be displayed onscreen.

Since my game is 3d and the letters has to be on the screen i use the spritefunction to render a sprite onscreen. however i get this strange behaviour:
Image

I have made the background blue so that why it is blue, but there are two things wrong, firstly the texture seems messed up. It should display some letters but it does not. Secondly the letters are not rendered on the screen but are rendered in the level.

does anybody has any idea what is going wrong?

here is the code i use:

Code: Select all

int MessageEngine::RenderMessages() {

		if (MessageAvailable == 0) return 1;		// if there is no message return

		MessageLength--;
		if &#40;MessageLength <= 0&#41; &#123; MessageAvailable = 0; return 2; &#125;

		int BeginPos = 240 - &#40;MessageLength*8&#41;;		// set the begin x value of the string for centering in the screen
		for&#40;int i=0;i<MessageLength;i++&#41; &#123;			// loop through the char array and render every letter
			// get the value of the char &#58;D
			int Char = &#40;int&#41;Message&#91;i&#93;;
			int row, column;
			

			if &#40;Char == 32&#41; &#123;
				//space char
				row = 4;
				column = 8;
			&#125; else if &#40;Char == 33&#41; &#123;
				// !
				row = 4;
				column = 3;
			&#125; else if &#40;Char == 45&#41; &#123;
				// -
				row = 4;
				column = 5;
			&#125; else if &#40;Char == 63&#41; &#123;
				// ?
				row = 4;
				column = 4;
			&#125; else &#123;
				Char = Char - 96;
				if &#40;Char < 9&#41; &#123;
					// get image from first row
					row = 1;
					column = Char;
				&#125;
				else if &#40;Char < 17&#41; &#123;
					// get image from second row
					row = 2;
					column = Char - 8;
				&#125;
				else if &#40;Char < 25&#41; &#123;
					// get image from third row
					row = 3;
					column = Char - 16;
				&#125;
				else &#123;
					row = 4;
					column = Char - 24;

				&#125;
			&#125;
			sceGuTexMode&#40;GU_PSM_8888, 0 ,0 ,0&#41;;
			sceGuTexFunc&#40;GU_TFX_REPLACE, GU_TCC_RGB&#41;;
			sceGuTexFilter&#40;GU_LINEAR, GU_LINEAR&#41;;
			sceGuTexOffset&#40;0.0f, 0.0f&#41;;
			sceGuTexImage&#40;0, Alphabet->textureWidth, Alphabet->textureHeight, Alphabet->textureWidth, &#40;void*&#41; Alphabet->data&#41;;
			float u = 1.0f / &#40;&#40;float&#41;Alphabet->textureWidth&#41;;
			float v = 1.0f / &#40;&#40;float&#41;Alphabet->textureHeight&#41;;
			sceGuTexScale&#40;u, v&#41;;

			DisplayVertices&#91;0&#93;.u = &#40;column-1&#41; * 16;
			DisplayVertices&#91;0&#93;.v = &#40;row-1&#41; * 16;
			DisplayVertices&#91;0&#93;.color = 0xffffffff;
			DisplayVertices&#91;0&#93;.x = BeginPos + &#40;16*i&#41;;
			DisplayVertices&#91;0&#93;.y = 253;
			DisplayVertices&#91;0&#93;.z = 0;

			DisplayVertices&#91;1&#93;.u = &#40;column&#41; * 16;
			DisplayVertices&#91;1&#93;.v = &#40;row&#41; * 16;
			DisplayVertices&#91;1&#93;.color = 0xffffffff;
			DisplayVertices&#91;1&#93;.x = BeginPos + &#40;16*&#40;i+1&#41;&#41;;
			DisplayVertices&#91;1&#93;.y = 269;
			DisplayVertices&#91;1&#93;.z = 0;

			sceGuDrawArray&#40;GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, DisplayVertices&#41;;

			//blitImageToScreen&#40;&#40;column-1&#41; * 16 ,&#40;row-1&#41; * 16 ,16 , 16, Alphabet, BeginPos + &#40;16*i&#41;, 253&#41;;	// render the letters
		&#125;

		return 0;
	&#125;
greets ghoti
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi folks,

i have displayed a 2d sprite onscreen as i want but instead of rendering my whole loop it just renders the last letter :(

Code: Select all

int MessageEngine&#58;&#58;RenderMessages&#40;&#41; &#123;

		char sBuffer&#91;256&#93;;

		if &#40;MessageAvailable == 0&#41; return 1;		// if there is no message return

		MessageLifeLeft--;
		if &#40;MessageLifeLeft <= 0&#41; &#123; MessageAvailable = 0; return 2; &#125;

		sceGuDisable&#40;GU_DEPTH_TEST&#41;; 

		sceGuTexImage&#40;0, Alphabet->textureWidth, Alphabet->textureHeight, Alphabet->textureWidth, &#40;void*&#41; Alphabet->data&#41;;

		int BeginPos = 240 - &#40;MessageLength*8&#41;;		// set the begin x value of the string for centering in the screen
		int Char = 0;
		int row, column;
		
		for&#40;int i=0;i<MessageLength-6;i++&#41; &#123;			// loop through the char array and render every letter
			// get the value of the char &#58;D
			Char = &#40;int&#41;Message&#91;i&#93;;
			if &#40;Char == 32&#41; &#123;
				//space char
				row = 4;
				column = 8;
			&#125; else if &#40;Char == 33&#41; &#123;
				// !
				row = 4;
				column = 3;
			&#125; else if &#40;Char == 45&#41; &#123;
				// -
				row = 4;
				column = 5;
			&#125; else if &#40;Char == 63&#41; &#123;
				// ?
				row = 4;
				column = 4;
			&#125; else &#123;
				Char = Char - 96;
				if &#40;Char < 9&#41; &#123;
					// get image from first row
					row = 1;
					column = Char;
				&#125;
				else if &#40;Char < 17&#41; &#123;
					// get image from second row
					row = 2;
					column = Char - 8;
				&#125;
				else if &#40;Char < 25&#41; &#123;
					// get image from third row
					row = 3;
					column = Char - 16;
				&#125;
				else &#123;
					row = 4;
					column = Char - 24;

				&#125;
			&#125;
			//sceGuTexMode&#40;GU_PSM_8888, 0 ,0 ,0&#41;;

			
			DisplayVertices&#91;0&#93;.u = &#40;float&#41;&#40;&#40;column-1&#41; * 16&#41;;// / Alphabet->textureWidth;
			DisplayVertices&#91;0&#93;.v = &#40;float&#41;&#40;&#40;row-1&#41; * 16&#41;;// / Alphabet->textureHeight;
			DisplayVertices&#91;0&#93;.x = &#40;float&#41;&#40;BeginPos + &#40;16*i&#41;&#41;;
			DisplayVertices&#91;0&#93;.y = 253.0f;
			DisplayVertices&#91;0&#93;.z = 0.0f;

			DisplayVertices&#91;1&#93;.u = &#40;float&#41;&#40;&#40;column&#41; * 16&#41;;// / Alphabet->textureWidth;
			DisplayVertices&#91;1&#93;.v = &#40;float&#41;&#40;&#40;row-1&#41; * 16&#41;;// / Alphabet->textureHeight;
			DisplayVertices&#91;1&#93;.x = &#40;float&#41;&#40;BeginPos + &#40;16*&#40;i+1&#41;&#41;&#41;;
			DisplayVertices&#91;1&#93;.y = 253.0f;
			DisplayVertices&#91;1&#93;.z = 0.0f;

			DisplayVertices&#91;2&#93;.u = &#40;float&#41;&#40;&#40;column-1&#41; * 16&#41;;// / Alphabet->textureWidth;
			DisplayVertices&#91;2&#93;.v = &#40;float&#41;&#40;&#40;row&#41; * 16&#41;;// / Alphabet->textureHeight;
			DisplayVertices&#91;2&#93;.x = &#40;float&#41;&#40;BeginPos + &#40;16*i&#41;&#41;;
			DisplayVertices&#91;2&#93;.y = 269.0f;
			DisplayVertices&#91;2&#93;.z = 0.0f;

			DisplayVertices&#91;3&#93;.u = &#40;float&#41;&#40;&#40;column&#41; * 16&#41;;// / Alphabet->textureWidth;
			DisplayVertices&#91;3&#93;.v = &#40;float&#41;&#40;&#40;row&#41; * 16&#41;;// / Alphabet->textureHeight;
			DisplayVertices&#91;3&#93;.x = &#40;float&#41;&#40;BeginPos + &#40;16*&#40;i+1&#41;&#41;&#41;;
			DisplayVertices&#91;3&#93;.y = 269.0f;
			DisplayVertices&#91;3&#93;.z = 0.0f;
			
			/*sprintf&#40;sBuffer, "MessageLenght&#58; %i", MessageLength&#41;;	// strlen gebruiken voor betere formatting
			pspDebugScreenSetXY&#40;1, 5&#41;;
			pspDebugScreenPrintf&#40;sBuffer&#41;;
			sprintf&#40;sBuffer, "i&#58; %i", i&#41;;	// strlen gebruiken voor betere formatting
			pspDebugScreenSetXY&#40;1, 6&#41;;
			pspDebugScreenPrintf&#40;sBuffer&#41;;*/

			sceGuDrawArray&#40;GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices&#41;;

		&#125;

		sceGuEnable&#40;GU_DEPTH_TEST&#41;; 
		return 0;
	&#125;
what am i forgetting ?

Message is a char[50] but holding the sentence "press x to open chest" but it only renders the last "t" at the correct location on the screen, if i make the loop 1 shorter then it shows the "s" at the correct location.

Is there something i don't know about the drawarray function? or can't i reuse the vertex?
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

You are reusing the vertices in DisplayVertices for every character. Vertices passed into sceGuDrawArray() need to remain valid until the GE has executed the operation, otherwise you will overwrite live data. Easy way to solve this is grab memory from the running display list using sceGuGetMemory(), preferably for the entire message to minimize overhead in the list (each allocation from the display list incurs a 8 byte overhead).
GE Dominator
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Yes, just before i saw your post i figured that out. I didnot know the reason why my they should not be changed so now i know, it is good information :D

and i even used the get memory way you described :D

but thanks for the reply though, now i know why i had to make new vertices and could not reuse them. Were can one find this info ? the documentation i read does not give this information, it only gives info on the function and what the parameter are, not those limitations and extra info one should know.

greets ghoti
Post Reply