 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Feb 13, 2007 8:04 pm Post subject: Strange blitting of sprites |
|
|
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:
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: | int MessageEngine::RenderMessages() {
if (MessageAvailable == 0) return 1; // if there is no message return
MessageLength--;
if (MessageLength <= 0) { MessageAvailable = 0; return 2; }
int BeginPos = 240 - (MessageLength*8); // set the begin x value of the string for centering in the screen
for(int i=0;i<MessageLength;i++) { // loop through the char array and render every letter
// get the value of the char :D
int Char = (int)Message[i];
int row, column;
if (Char == 32) {
//space char
row = 4;
column = 8;
} else if (Char == 33) {
// !
row = 4;
column = 3;
} else if (Char == 45) {
// -
row = 4;
column = 5;
} else if (Char == 63) {
// ?
row = 4;
column = 4;
} else {
Char = Char - 96;
if (Char < 9) {
// get image from first row
row = 1;
column = Char;
}
else if (Char < 17) {
// get image from second row
row = 2;
column = Char - 8;
}
else if (Char < 25) {
// get image from third row
row = 3;
column = Char - 16;
}
else {
row = 4;
column = Char - 24;
}
}
sceGuTexMode(GU_PSM_8888, 0 ,0 ,0);
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuTexOffset(0.0f, 0.0f);
sceGuTexImage(0, Alphabet->textureWidth, Alphabet->textureHeight, Alphabet->textureWidth, (void*) Alphabet->data);
float u = 1.0f / ((float)Alphabet->textureWidth);
float v = 1.0f / ((float)Alphabet->textureHeight);
sceGuTexScale(u, v);
DisplayVertices[0].u = (column-1) * 16;
DisplayVertices[0].v = (row-1) * 16;
DisplayVertices[0].color = 0xffffffff;
DisplayVertices[0].x = BeginPos + (16*i);
DisplayVertices[0].y = 253;
DisplayVertices[0].z = 0;
DisplayVertices[1].u = (column) * 16;
DisplayVertices[1].v = (row) * 16;
DisplayVertices[1].color = 0xffffffff;
DisplayVertices[1].x = BeginPos + (16*(i+1));
DisplayVertices[1].y = 269;
DisplayVertices[1].z = 0;
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, DisplayVertices);
//blitImageToScreen((column-1) * 16 ,(row-1) * 16 ,16 , 16, Alphabet, BeginPos + (16*i), 253); // render the letters
}
return 0;
} |
greets ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Feb 13, 2007 9:40 pm Post subject: |
|
|
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: | int MessageEngine::RenderMessages() {
char sBuffer[256];
if (MessageAvailable == 0) return 1; // if there is no message return
MessageLifeLeft--;
if (MessageLifeLeft <= 0) { MessageAvailable = 0; return 2; }
sceGuDisable(GU_DEPTH_TEST);
sceGuTexImage(0, Alphabet->textureWidth, Alphabet->textureHeight, Alphabet->textureWidth, (void*) Alphabet->data);
int BeginPos = 240 - (MessageLength*8); // set the begin x value of the string for centering in the screen
int Char = 0;
int row, column;
for(int i=0;i<MessageLength-6;i++) { // loop through the char array and render every letter
// get the value of the char :D
Char = (int)Message[i];
if (Char == 32) {
//space char
row = 4;
column = 8;
} else if (Char == 33) {
// !
row = 4;
column = 3;
} else if (Char == 45) {
// -
row = 4;
column = 5;
} else if (Char == 63) {
// ?
row = 4;
column = 4;
} else {
Char = Char - 96;
if (Char < 9) {
// get image from first row
row = 1;
column = Char;
}
else if (Char < 17) {
// get image from second row
row = 2;
column = Char - 8;
}
else if (Char < 25) {
// get image from third row
row = 3;
column = Char - 16;
}
else {
row = 4;
column = Char - 24;
}
}
//sceGuTexMode(GU_PSM_8888, 0 ,0 ,0);
DisplayVertices[0].u = (float)((column-1) * 16);// / Alphabet->textureWidth;
DisplayVertices[0].v = (float)((row-1) * 16);// / Alphabet->textureHeight;
DisplayVertices[0].x = (float)(BeginPos + (16*i));
DisplayVertices[0].y = 253.0f;
DisplayVertices[0].z = 0.0f;
DisplayVertices[1].u = (float)((column) * 16);// / Alphabet->textureWidth;
DisplayVertices[1].v = (float)((row-1) * 16);// / Alphabet->textureHeight;
DisplayVertices[1].x = (float)(BeginPos + (16*(i+1)));
DisplayVertices[1].y = 253.0f;
DisplayVertices[1].z = 0.0f;
DisplayVertices[2].u = (float)((column-1) * 16);// / Alphabet->textureWidth;
DisplayVertices[2].v = (float)((row) * 16);// / Alphabet->textureHeight;
DisplayVertices[2].x = (float)(BeginPos + (16*i));
DisplayVertices[2].y = 269.0f;
DisplayVertices[2].z = 0.0f;
DisplayVertices[3].u = (float)((column) * 16);// / Alphabet->textureWidth;
DisplayVertices[3].v = (float)((row) * 16);// / Alphabet->textureHeight;
DisplayVertices[3].x = (float)(BeginPos + (16*(i+1)));
DisplayVertices[3].y = 269.0f;
DisplayVertices[3].z = 0.0f;
/*sprintf(sBuffer, "MessageLenght: %i", MessageLength); // strlen gebruiken voor betere formatting
pspDebugScreenSetXY(1, 5);
pspDebugScreenPrintf(sBuffer);
sprintf(sBuffer, "i: %i", i); // strlen gebruiken voor betere formatting
pspDebugScreenSetXY(1, 6);
pspDebugScreenPrintf(sBuffer);*/
sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices);
}
sceGuEnable(GU_DEPTH_TEST);
return 0;
} |
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? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Wed Feb 14, 2007 2:35 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Feb 14, 2007 3:46 am Post subject: |
|
|
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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
|
|
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
|