You are not logged in.

#1 2009-05-05 22:53:51

atupac
Member

Creating Reflections for images.

Hi all!   I'm trying to learn to work with GRRLIB for WII needs^^

What i need is to create reflection for a PNG image (160x224). It's like "Mirroring" the image itself on the ground.

Those reflexions would appear on the ground and in front of the images, just like in ITunes...

So i'm looking for GRRLIB functions that does that, just like the following example made from gl lib:


Code:

#include <windows.h>        // Header File For Windows
#include <stdio.h>            // Header File For Standard Input/Output
#include <gl/gl.h>            // Header File For The OpenGL32 Library
#include <gl/glaux.h>        // Header File For The Glaux Library
#include <gl/glu.h>            // Header File For The GLu32 Library


HDC            hDC=NULL;        // Private GDI Device Context
HGLRC        hRC=NULL;        // Permanent Rendering Context
HWND        hWnd=NULL;        // Holds Our Window Handle
HINSTANCE    hInstance;        // Holds The Instance Of The Application
void DrawCube();
void DrawGround();
bool    keys[256];            // Array Used For The Keyboard Routine
bool    active=TRUE;        // Window Active Flag Set To TRUE By Default
bool    fullscreen=TRUE;    // Fullscreen Flag Set To Fullscreen Mode By Default

GLfloat    rot;                // X Rotation ( NEW )


GLuint    texture[2];            // Storage For One Texture ( NEW )

LRESULT    CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);    // Declaration For WndProc

AUX_RGBImageRec *LoadBMP(char *Filename)                // Loads A Bitmap Image
{
    FILE *File=NULL;                                    // File Handle

    if (!Filename)                                        // Make Sure A Filename Was Given
    {
        return NULL;                                    // If Not Return NULL
    }

    File=fopen(Filename,"r");                            // Check To See If The File Exists

    if (File)                                            // Does The File Exist?
    {
        fclose(File);                                    // Close The Handle
        return auxDIBImageLoad(Filename);                // Load The Bitmap And Return A Pointer
    }

    return NULL;                                        // If Load Failed Return NULL
}

int LoadGLTextures()                                    // Load Bitmaps And Convert To Textures
{
    int Status=FALSE;                                    // Status Indicator

    AUX_RGBImageRec *TextureImage[2];                    // Create Storage Space For The Texture

    memset(TextureImage,0,sizeof(void *)*1);               // Set The Pointer To NULL

    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if (TextureImage[0]=LoadBMP("cube.bmp"))
    {
        Status=TRUE;                                    // Set The Status To TRUE

        glGenTextures(1, &texture[0]);                    // Create The Texture

        // Typical Texture Generation Using Data From The Bitmap
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    }

    if (TextureImage[0])                                    // If Texture Exists
    {
        if (TextureImage[0]->data)                            // If Texture Image Exists
        {
            free(TextureImage[0]->data);                    // Free The Texture Image Memory
        }

        free(TextureImage[0]);                                // Free The Image Structure
    }
    if (TextureImage[1]=LoadBMP("ground.bmp"))
    {
        Status=TRUE;                                    // Set The Status To TRUE

        glGenTextures(1, &texture[1]);                    // Create The Texture

        // Typical Texture Generation Using Data From The Bitmap
        glBindTexture(GL_TEXTURE_2D, texture[1]);
        glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    }

    if (TextureImage[1])                                    // If Texture Exists
    {
        if (TextureImage[1]->data)                            // If Texture Image Exists
        {
            free(TextureImage[1]->data);                    // Free The Texture Image Memory
        }

        free(TextureImage[1]);                                // Free The Image Structure
    }
    return Status;                                        // Return The Status
}


void DrawGround()
{
   glPushMatrix();

      // Activate texture
       glBindTexture(GL_TEXTURE_2D, texture[1]);

      // Draw on the ground
      glBegin(GL_QUADS);
         glTexCoord2f(0.0, 0.0); glVertex3f(2.0f, -0.02f, 2.0f);
         glTexCoord2f(1.0, 0.0); glVertex3f(-2.0f, -0.02f, 2.0f);
         glTexCoord2f(1.0, 1.0); glVertex3f(-2.0f, -0.02f, -2.0f);
         glTexCoord2f(0.0, 1.0); glVertex3f(2.0f, -0.02f, -2.0f);
      glEnd();

   glPopMatrix();
}

Well, thanks in advance for helping mates!

Offline

 

#2 2009-05-06 17:17:23

atupac
Member

Re: Creating Reflections for images.

I guess it's too hard this question NoNameNo or Crayon!  lol

Any idea anybody!

PS: sorry if this question has already been asked, if so pls give link.

Last edited by atupac (2009-05-06 17:18:59)

Offline

 

#3 2009-05-06 18:20:14

Crayon
Bad Mother Fucker

Re: Creating Reflections for images.

Hi, all the GX stuff have been coded by NoNameNo and Xane, so for that function I can't really help you. Try asking the question at #grrlib on EFnet, maybe someone will help you there.

Offline

 

#4 2009-05-06 19:42:17

atupac
Member

Re: Creating Reflections for images.

Thanks Crayon for quick answer & advice. Will wait for NoNameNo or Xane advices so...

Though, i've found functions from GRRLIB for Textures that may could be useful:

- GX_CopyTex (void *dest, u8 clear);
- GX_PixModeSync ();
- GX_SetCopyClear (GXColor color,u32 zvalue);
- GX_SetCopyClamp (u8 clamp);


Will try &report ASAP. Hope there' a solution for Reflections...really need them.

Offline

 

#5 2009-05-06 23:40:07

DrTwox
Member

Re: Creating Reflections for images.

The effect you describe should be doable...

1) Make a copy of the image you want to 'reflect' (memcpy would do I suppose)
2) Flip the copied image vertically (GRRLIB 4.0 has a flipping function)
3) Apply some blur to the flipped image (GRRLIB 4.0 has a blur function)
4) Apply an alpha gradient to the blurred image (You will need to create a function for this)
5) Draw the new image below the original image and it should look like a reflection

Try to create the effect in an image editor (such as GIMP) to understand the steps required.

There probably is a way to achieve the same thing using GX functions, but the above should work... Post some screenshots of what you create!

Offline

 

#6 2009-05-07 09:32:14

NoNameNo
Administrator

Re: Creating Reflections for images.

hi, and sorry about my late answer wink

in fact, grrlib is a kind of a toolbox, so i think drtox is right. Try to be imaginative, learn how to use all you have in the toolbox, understand how reflexion work (in real life) and try to recode something similar.

go go go !!

Offline

 

#7 2009-05-08 00:19:40

atupac
Member

Re: Creating Reflections for images.

Hi all, thanksDrTwtox & NoNameNo for such contructive ideas!   I've found the libs i need: gl2gx.  I'll use GL, as the code for reflexions i posted above works.

Well, i added the "GL" file from the lib in "C:\devkitPro\libogc\include" an dtried to compile. Until now i got only minorr warning (unused variable), and an error i can't avoid dunno why!  Here is the compiling log:

Code:

pngu.c
gl.c
c:/lesson4/source/GL/gl.c: In function 'glEnd':
c:/lesson4/source/GL/gl.c:167: warning: unused variable 'mv'
c:/lesson4/source/GL/gl.c: In function 'glLightfv':
c:/lesson4/source/GL/gl.c:597: warning: unused variable 'defcolor'
c:/lesson4/source/GL/gl.c: In function 'glEnable':
c:/lesson4/source/GL/gl.c:739: warning: unused variable 'countlights'
glu.c
glut.c
linking ... lesson4.elf
glut.o: In function `glutGet':
c:/lesson4/source/GL/glut.c:208: multiple definition of `fb'
lesson4.o:c:/lesson4/source/lesson4.c:95: first defined here
collect2: ld returned 1 exit status
make[1]: *** [/c/lesson4/lesson4.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:20

And when i look at this error "c:/lesson4/source/GL/glut.c:208: multiple definition of `fb'", it takes me in this part of code from "glut.c":

Code:

int glutGet(GLenum type) {
    int retval = 0;
    switch(type)   // IT TAKES ME ON THIS LINE!!!
    {
    case GLUT_SCREEN_WIDTH: retval = rmode->viWidth; break;
    case GLUT_SCREEN_HEIGHT: retval = rmode->viHeight; break;
    }
    return retval;
}

Hope it speaks to you or so...

Last edited by atupac (2009-05-08 00:40:10)

Offline

 

#8 2009-05-08 03:19:57

atupac
Member

Re: Creating Reflections for images.

Oki solved that issue, just renaming 'fb' lol!

Back to code...

Last edited by atupac (2009-05-08 03:20:29)

Offline

 

#9 2009-05-08 04:24:41

atupac
Member

Re: Creating Reflections for images.

got new small embarassing issue about "glTexParameteri":

Code:

 
linking ... lesson4.elf
lesson4.o: In function `_loadGameImage':
c:/lesson4/source/lesson4.c:171: undefined reference to `glTexParameteri'
c:/lesson4/source/lesson4.c:172: undefined reference to `glTexParameteri'
collect2: ld returned 1 exit status
make[1]: *** [/c/lesson4/lesson4.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:21

Normally, this function exist for wii (gl2gx), don't understand why seems undefined!

thanks.

Offline

 

#10 2009-05-08 16:25:56

JustWoody
Member

Re: Creating Reflections for images.

I think this approach may be too complicated

You should be able to do all this just using standard GRRLIB functions, just follow DrTwox's suggestion and then for part 4 and 5 do something along these lines:

Treat the image as a tileset with one tile across and however many you fancy down, then draw each part of the tile below your image using the standard functions making it more transparent for each one

You could even offset each part of the tile horizontally using a sine function to make it look more like a reflection or to get it to wave around a bit

Last edited by JustWoody (2009-05-08 16:28:15)

Offline

 

#11 2009-05-08 18:14:14

atupac
Member

Re: Creating Reflections for images.

JustWoody, thanks for replying!  Will so  retry with grrlib, it seems easier than others lib to include...

Offline

 

Board footer

Powered by FluxBB