You are not logged in.

#1 2009-04-23 21:04:49

mnta
Member

Trying to paint something on an image..

Im trying to draw something on paintbuffer and then put it in the front. What I am trying to make is some sort of drawing application so the line must stay so i can draw another line, or whatever i decide to implement.

The code compiles. Problem is, im not drawing ANYTHING..

Any clues or another angle of approach? Or guides for that matter.. Thank you in advance..

Code:

int main() 
{    
                u32 wpaddown;
    u32 wpadheld;
    u32 wpadup;
        
    ir_t ir1;
    
    paintBuffer = GRRLIB_CreateEmptyTexture(MAX_HORZ_PIXELS, MAX_VERT_PIXELS);
    

    GRRLIB_Init();
    
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    
    while(1) 
                {
        
        WPAD_ScanPads();
        WPAD_SetVRes(0, MAX_HORZ_PIXELS, MAX_VERT_PIXELS);
        
                                wpaddown = WPAD_ButtonsDown(0);
        wpadheld = WPAD_ButtonsHeld(0);
        wpadup = WPAD_ButtonsUp(0);
        
        WPAD_IR(WPAD_CHAN_0,&ir1);
    
        if (wpaddown & WPAD_BUTTON_A)
        {    
            int i;
            for(i = ir1.x;i < 100;i++)
            {
                GRRLIB_SetPixelTotexImg(ir1.x+i,ir1.y, paintBuffer, 0x000000FF);
            }
        }
        
        GRRLIB_FlushTex(paintBuffer);
        
        if(wpaddown & WPAD_BUTTON_HOME) {
                                  exit(0);
                                }
        
        GRRLIB_DrawImg(ir1.x, ir1.y, pointer, 0, 1, 1, 0xFFFFFFFF);
        GRRLIB_Render();
        GRRLIB_DrawImg(0, 0, paintBuffer, 0, 1, 1, 0xFFFFFFFF);
        
        
        
    }
    GRRLIB_Exit(); 
    free(pointer.data);
    free(paintBuffer.data);
    return 0;
}

Last edited by mnta (2009-04-23 22:57:33)

Offline

 

#2 2009-04-23 22:10:23

Crayon
Bad Mother Fucker

Re: Trying to paint something on an image..

The last parameter for GRRLIB_SetPixelTotexImg is color:

Code:

 * @param x Specifies the x-coordinate of the pixel in the texture.
 * @param y Specifies the y-coordinate of the pixel in the texture.
 * @param tex The texture to set the color to.
 * @param color The color of the pixel in RGBA format.

Try setting another color than transparent:

Code:

#define GRRLIB_BLACK   0x000000FF
#define GRRLIB_MAROON  0x800000FF
#define GRRLIB_GREEN   0x008000FF
#define GRRLIB_OLIVE   0x808000FF
#define GRRLIB_NAVY    0x000080FF
#define GRRLIB_PURPLE  0x800080FF
#define GRRLIB_TEAL    0x008080FF
#define GRRLIB_GRAY    0x808080FF
#define GRRLIB_SILVER  0xC0C0C0FF
#define GRRLIB_RED     0xFF0000FF
#define GRRLIB_LIME    0x00FF00FF
#define GRRLIB_YELLOW  0xFFFF00FF
#define GRRLIB_BLUE    0x0000FFFF
#define GRRLIB_FUCHSIA 0xFF00FFFF
#define GRRLIB_AQUA    0x00FFFFFF
#define GRRLIB_WHITE   0xFFFFFFFF

Offline

 

#3 2009-04-23 22:56:55

mnta
Member

Re: Trying to paint something on an image..

Thanks for the quick reply but this is a copy-paste error..  I had removed it to insert a RGBA value instead of the global variable i had in order to make it more readable here on the forum..

My original code is

Code:

GRRLIB_SetPixelTotexImg(ir1.x+i, ir1.y, paintBuffer, BLACK);

This is not the problem.. even if i insert 0x000000FF in GRRLIB_SetPixelTotexImg i get no line..

Any other clues..

Last edited by mnta (2009-04-23 22:57:56)

Offline

 

#4 2009-04-24 06:04:31

Crayon
Bad Mother Fucker

Re: Trying to paint something on an image..

One thing you could try is to put the FlushTex function in the if. No need to flush if nothing was drawn.

Code:

        if (wpaddown & WPAD_BUTTON_A)
        {    
            int i;
            for(i = ir1.x;i < 100;i++)
            {
                GRRLIB_SetPixelTotexImg(ir1.x+i,ir1.y, paintBuffer, 0x000000FF);
            }
            GRRLIB_FlushTex(paintBuffer);
        }

I don't know if it's better, but for IR you could use validated values:

Code:

        if ((wpaddown & WPAD_BUTTON_A) && (ir1.valid))
        {    
            int i;
            for(i = ir1.x;i < 100;i++)
            {
                GRRLIB_SetPixelTotexImg(ir1.x+i,ir1.y, paintBuffer, 0x000000FF);
            }
            GRRLIB_FlushTex(paintBuffer);
        }

Offline

 

#5 2009-04-24 17:55:58

mnta
Member

Re: Trying to paint something on an image..

I will try this. Thanks..

A slightly connected question; doess GRRLIB_FlushTex(variable) improve performance when using a lot of images?

Offline

 

#6 2009-04-24 20:19:00

Crayon
Bad Mother Fucker

Re: Trying to paint something on an image..

mnta wrote:

A slightly connected question; doess GRRLIB_FlushTex(variable) improve performance when using a lot of images?

GRRLIB_FlushTex is used to write the contents of a texture in the data cache down to main memory. For performance the CPU holds a data cache where modifications are stored before they get written down to main memory.

You should call it once after modifying a texture with a bunch of GRRLIB_SetPixelTotexImg. You don't need to call it after using a texture, like when you use GRRLIB_DrawImg. When loading the texture you don't need to call it because it's already called in the code.

Offline

 

Board footer

Powered by FluxBB