You are not logged in.
working on a command for GRRLIB users to draw their Mii's
Basically, i've been disecting and tinkering with my new version of libmii and made it so you can draw your wii's using GRRLIB and all the sprites.
Using the raw data extracted from libmii, i can translate that into grrlib tiles and positions, rotations, and scales to build your mii.
So the code to build a mii is about 20 GRRLIB_DrawTile lines each with different SetHandle events to allow for the rotation and scale numbers that libmii grabs, to work and draw each feature (eyebrows, nose, mouth, hair, face shape, etc) in the correct spot.
This part works great, but since i can't apply an overall rotation or zoom to the final mii product since each texture has dif handles... i use Compo Start and CompoEnd to turn all that into an individual texture.
void GRRLIB_DrawMii(const f32 xpos, const f32 ypos, Mii mii, const f32 degrees, const f32 scaleX, const f32 scaleY, const u32 color, const int type) { GRRLIB_CompoStart(); Here go my 20+ drawtile events that build the mii. GRRLIB_CompoEnd(0, 0, img_mii); GRRLIB_DrawImg(xpos, ypos, img_mii, degrees, scaleX, scaleY, color); }
now i've got my build up mii parts stored in one texture called img_mii that i can then rotate, scale, put anywhere on the screen etc.
So i just send GRRLIB_DrawMii(20, 30, miis[2], 0, 1, 1, 0xFFFFFFFF, 1);
and it'll draw my 3rd mii in the system at the coord 20, 30 with 0 rotation, scale of 1, that color, and the last 1 is for something extra i'll do later.
works like a charm.
My problem... DRAWING 2 mii's or 10 mii's or 100 mii's.
what i would like to do is be able to do:
GRRLIB_DrawMii(20, 30, miis[2], 0, 1, 1, 0xFFFFFFFF, 1);
GRRLIB_DrawMii(20, 70, miis[5], 0, 1, 1, 0xFFFFFFFF, 1);
and that would just draw two mii's, but since each loop runs the Compo code over again and stores it in the same img file, my previous work gets overwritten.
If i didn't have to do the compstart part, this would obviously work and i would be able to draw a bunch of mii's
but without the compstart stuff, i can't scale and rotate completed face...
make sense? anyone have any ideas?
Last edited by mdbrim (2010-03-10 15:22:19)
Offline
Is img_mii created each time GRRLIB_DrawMii is called? Is it created with GRRLIB_CreateEmptyTexture?
Offline
img_mii is created outside of GRRLIB_DrawMii... and it is created with createemptytexture.
I made an attempt to put the createemptytexture inside the GRRLIB_DrawMii but it gave me a code dump about 6 seconds in so either that way is a no go or i wasn't doing it correctly
Offline
Just an idea like that. I think that img_mii is problem because it writes the new image over the old one.
Try to draw a rectangle the size of img_mii just after GRRLIB_CompoStart(). Before you draw anything else to test clearing the texture.
A better idea would be to use GRRLIB_ClearTex(img_mii) as the first line of GRRLIB_DrawMii.
Offline
yeah that's one problem, it keeps overwriting img_mii whenever i call GRRLIB_DrawMii
yeah but if it clears the texture, how do i end up drawing it?
Offline
mdbrim wrote:
yeah but if it clears the texture, how do i end up drawing it?
What I had in mind was something like this:
void GRRLIB_DrawMii(const f32 xpos, const f32 ypos, Mii mii, const f32 degrees, const f32 scaleX, const f32 scaleY, const u32 color, const int type) { GRRLIB_ClearTex(img_mii); // Clear previous version of img_mii GRRLIB_CompoStart(); Here go my 20+ drawtile events that build the mii. GRRLIB_CompoEnd(0, 0, img_mii); GRRLIB_DrawImg(xpos, ypos, img_mii, degrees, scaleX, scaleY, color); // Draw the Mii on the screen }
Would it be better to have a function like GRRLIB_CreateMiiTexture? It would a lot faster to use, no need to generate the texture each time. People will only need to call GRRLIB_DrawImg with there Mii texture.
Offline
yeah but if i clear the texture how would i draw more than one at a time?
Offline
Sorry I don't understand.
Calling this:
GRRLIB_DrawMii(20, 30, miis[2], 0, 1, 1, 0xFFFFFFFF, 1);
Will draw a texture on the screen. Once it's on the screen we don't care about clearing or not the texture! So we could call this without any problems:
GRRLIB_DrawMii(20, 70, miis[5], 0, 1, 1, 0xFFFFFFFF, 1);
Maybe you should paste more code.
Offline
Sorry man, i think i'm a little confused and taking you down with me!
I thought that the second time I run GRRLIB_DrawMii, it's going to do the CompoStart thing again which i thought, started fresh with a clear screen therefore it would erase my first rendering. so the result of your example would just draw the last GRRLIB_DrawMii
I'm at work now, i'll try what you have above when i get home. Thanks for the patience.. and the help man. I'll get there!
Last edited by mdbrim (2010-03-11 16:35:21)
Offline
i think mdbrim is right,
GRRLIB_DrawMii will compo start, draw shit, compo end, and draw it.
so each time you will call GRRLIB_DrawMii the screen will be cleared, then a mii will be draw.
i think you should have only this function
GRRLIB_PreCalcMii (compo start, draw shit, compo end)
Then draw the precalulated mii many times you want using GRRLIB_DrawImg
but i think all this already explained by crayon in an upper message.
Offline
NNN,
right, i've got that now, but if i want to draw multiple mii's (different ones) i can't do it that way unless i know ahead of time the max number of mii's i'm going to allow.
Cuz then i would just create that many empty textures, precalc each mii into a dif texture, and then display each mii when ready to use.
I guess i was trying to avoid having to set aside a certain number of empty mii textures, and then being limited to that number of mii's for the program.
Offline
i thought about that, but couldn't figure out the best way to do it. How would i draw say 3 mii's on the screen at once? I keep getting stack dumps and crashes the way i'm attempting it
Offline
i guess i can pass a texture name into GRRLIB_DrawMii and always clear and create... that way when i do another mii, i just pass a different texture name. Me goes to try!
Offline
that won't work because i still need to declare all of my empty textures up top before i can build them... so i'll still need to know how many mii's i'll have and set aside "static GRRLIB_texImg* blah" for each of them.
Offline
ok progress!
void GRRLIB_BuildMii(Mii mii, const int type, GRRLIB_texImg* tex) { GRRLIB_ClearTex(tex); GRRLIB_CompoStart(); build up mii number "mii" with some options "type" GRRLIB_CompoEnd(200, 160, tex); } int main() { while(1) { GRRLIB_BuildMii(1, 1, img_mii1); GRRLIB_BuildMii(2, 1, img_mii2); GRRLIB_DrawImg(0, 10, img_mii1, 0, 1, 1, 0xFFFFFFFF); GRRLIB_DrawImg(0, 200, img_mii2, 0, 1, 1, 0xFFFFFFFF);
problem is, i still need to know how many max mii's i'd allow so i can do all the "static GRRLIB_TexImg* img_mii1" and "img_mii1=create empty texture" stuff.
But it's a step closer!
Last edited by mdbrim (2010-03-12 07:55:59)
Offline
Could you paste the code where you alloc img_mii1 and free it. Just to understand the problem with the code dump.
Offline
i'm not getting the code dump anymore since i took the img_mii = create new texture out of the GRRLIB_BuildMii function.
BUt it was dumping when i had tex = GRRLIB_CreateNewTexture(200, 160); underneath the ClearTex(tex);
now i have img_mii1 =GRRLIB_CreateNewTexture(200, 160); up where the rest of textures are done.
but i also have to have img_mii2, img_mii3, etc.
It works, it would just be nice not to have to create 20 img_miiX = GRRLIB_Create new texture... what if the programer wanted to put 100miis... he'd need a 100 of those lines. Not THAT big a deal... but not the cleanest
Offline
mdbrim wrote:
i'm not getting the code dump anymore since i took the img_mii = create new texture out of the GRRLIB_BuildMii function.
BUt it was dumping when i had tex = GRRLIB_CreateNewTexture(200, 160); underneath the ClearTex(tex);
Were you using it like this ???
ClearTex(tex); tex = GRRLIB_CreateNewTexture(200, 160);
If yes, I don't see the point, if the opposite I don't see point either. I understand more C/C++ code than English, so I'll wait for the release of the code to make suggestion.
mdbrim wrote:
It works, it would just be nice not to have to create 20 img_miiX = GRRLIB_Create new texture... what if the programer wanted to put 100miis... he'd need a 100 of those lines. Not THAT big a deal... but not the cleanest
On my side I would be more clever and use a malloc with the total number of Miis I need.
Offline
well i won't be able to release it until i figure this part out...
If yes, I don't see the point, if the opposite I don't see point either.
yeah, the create new texture shouldn't be in there, i just thought i would be able to create textures on the fly with that code.
You would use malloc with the total number of Miis? I'll be trolling around irc throughout the day so maybe i'll see if i can get you to show me what you mean.
http://pastebin.com/qrDSeYr0
you can see lines 52 and 53
and lines 119 and 120
that's what i'm trying to aviod... having 20 lines of those if i want 20 mii's on screen at once.
Last edited by mdbrim (2010-03-12 15:49:58)
Offline
I don't understand why you have this code in your while loop, it should be called once before:
GRRLIB_BuildMii(miis[1], 1, img_mii); //build mii 1 into texture img_mii GRRLIB_BuildMii(miis[2], 1, img_mii2); //build mii 2 into texture img_mii2
Only the draw function is required in the loop.
Dynamic allocation could be tricky, you could simply used something like this:
GRRLIB_texImg *img_mii[100]; u8 i; for(i=0; i<100; i++) { img_mii[i] = GRRLIB_CreateEmptyTexture(180, 200); GRRLIB_BuildMii(miis[i + 1], 1, img_mii[i]); // Not sure about the +1, in you code you start at 1??? }
Add this code in the while to draw:
// Draw the first Mii GRRLIB_DrawImg(40, 10, img_mii[0], 0, 1, 1, 0XFFFFFFFF);
Offline
the reason the GRRLIB_BuildMii is in the loop is because i pass a variable that defines mood / animation.
So it updates the Mii with a happy face or sad face or closed eyes every random seconds for blinking.
Static Mii's that don't need to blink or change facial expression can be outside the loop... i just had those in there for a blinking test.
I'll try out that loop... thanks!
Offline
yeah, that code works perfect...
now i can tweak it to load up 12 mii's at a time (for menu type selection) or 10, or X.
now i can have a variable as how many mii's displayed at once, and not a ton of img_texfile declarations.
THANKS!
(yeah, inside the loop required for blinking and mood change type animations)
Offline
What about making a Class/Struct, and have the Draw function and the texture in that?
Then you can have an array of those objects.
You can then make a subroutine which loops trough all the objects and calls their Draw functions.
Offline