Welcome! Log In Create A New Profile

Advanced

GRRLIB_SetPixelToTexImg *SOLVED*

Posted by LordAshes 
GRRLIB_SetPixelToTexImg *SOLVED*
March 08, 2010 02:40AM
I am trying to code a resize function. I have found that the Scale parameters in GRRLIB_DrawImg seem to work in increments of whole numbers (ie. 100%, 200%, 300%) but they don't allow for partial increments inbetween. They also don't seem to draw anything if the scale is less than 100%.

So my theory. Create an empty texture and then map the original texture to the empty one using the necessary scale. However, before I embark on that project I want to learn the basics of creating and empty texture and filling it. So I have written some code that should create a 255 by 255 texture which has a gradient (top left corner is black, top right is blue, bottom left is red and bottom right is purple).

Here is my code snippet:

int x, y;
u32 c;

GRRLIB_texImg MyTex;

MyTex = GRRLIB_CreateEmptyTexture(255,255);

for(y=0;y<255;y++)
{
for(x=0;x<255;x++)
{
c = 0;
c = c + y*0x1000000; // Set R
c = c + x*0x100; // Set B
c = c + 0xFF; // Set A

GRRLIB_SetPixelTotexImg(x,y,MyTex,c);
}
}
GRRLIB_FlushTex(MyTex);

However when I run this code it creates a square with the correct colors - somewhat - but the image has black stripes through it and the beginning of the line seems to shift.



I tried using 1->255 instead of 0 to 254 and even 0->255 but none of it makes any significant difference.

Can anyone point me in the direction of my error?



Edited 2 time(s). Last edit at 03/16/2010 03:59AM by LordAshes.
Re: GRRLIB_SetPixelToTexImg
March 08, 2010 05:50AM
Quote

Scale parameters in GRRLIB_DrawImg seem to work in increments of whole numbers (ie. 100%, 200%, 300%) but they don't allow for partial increments inbetween. They also don't seem to draw anything if the scale is less than 100%.

If this is the case for you then you are either using a REALLY old version of GRRLIB, or you are doing it wrong.

GRRLIB DrawImg (and DrawTile for that matter) can scale any increment... whole or not. and go less than 100% easily.

What version of GRRLIB do you have and how are you using the scaling?

GRRLIB_DrawImg(x, y, imagename, rotate, XZOOM, YZOOM, color)

XZOOM and YZOOM can be anything... 1 is normal... .5 is half...

1.5 is 150%...
1.44 is 144%
.34 is 34%
Re: GRRLIB_SetPixelToTexImg
March 08, 2010 05:59AM
Textures' width and height must be multiple of 4.
Your loop must run from 1 to X, where X is the size of your texture.
The scale parameter you wrote about works perfectly. I don't get your statements about it.
Re: GRRLIB_SetPixelToTexImg *SOLVED*
March 08, 2010 06:48AM
Okay...I guess I should have noted that I am implementing this code as a modification to an existing program which uses an earlier version of GRRLIB. Since the original program is not mine, I can not upgrade it to latest version and the user, due to the change in licenses between the eralier version and current version, does not want to upgrade (at least not at this time).

Thanks for the note about multiple of 4...I should have caught that myself. I will check to see if my problem is due to defining the texture as a 255 by 255 texture instead of 256 by 256 (which would be a multiple of 4).


SOLUTION:

Changing the texture so that it was a multiple of 4 did the trick. Thanks a lot for the advice.



Edited 1 time(s). Last edit at 03/08/2010 06:53AM by LordAshes.
Sorry, only registered users may post in this forum.

Click here to login