Author Topic: UV Parameters of Polyvectors  (Read 4622 times)

Offline Uncle

  • Mr. Drawsprite
  • **
  • Posts: 75
    • View Profile
    • www.urbaninteractive.net
UV Parameters of Polyvectors
« on: 2009-Sep-01 »
Hi,

I've had a hunt around the forums and couldn't see anything related to this, but I was wondering if it was possible to be able to handle the UV parameters.  The idea being that you could make a nice single polyvectory and apply the texture multiple times to it.  Imagine I wanted to draw an area of grass, at the moment I would need to render say 30 tiles to cover the screen.  Wouldn't it be nice to render 1 polyvector and just change the UV parameter to repeat the texture 15 times on the x axis, and 15 times on the y axis.  Even better would then be the option to set the UV offsets.  This would then allow us to scroll the texture on polyvector. 

I can see a lot of practical uses for something this.

Cheers,


Andrew

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: UV Parameters of Polyvectors
« Reply #1 on: 2009-Sep-01 »
do you mean something like this?
makes a simple gras tile with black border to see the single tiles on the polyvector

Code: GLBasic [Select]
DRAWRECT 1, 1, 30, 30, RGB(0, 255, 0)
GRABSPRITE 0, 0, 0, 32, 32

GETSCREENSIZE sx, sy

col = RGB(255, 255, 255)

WHILE TRUE
        STARTPOLY 0
                POLYVECTOR 0, 0, 0, 0, col
                POLYVECTOR 0, sy, 0, sy, col
                POLYVECTOR sx, sy, sx, sy, col
                POLYVECTOR sx, 0, sx, 0, col
        ENDPOLY
        SHOWSCREEN
WEND
 

Offline Uncle

  • Mr. Drawsprite
  • **
  • Posts: 75
    • View Profile
    • www.urbaninteractive.net
Re: UV Parameters of Polyvectors
« Reply #2 on: 2009-Sep-01 »
Hi Quentin,

Nice demo, but that works fine if you only have one texture on your bitmap.  In your example you are creating a single texture 32 x 32.  Imagine your sprite had 2 images with a total size of 32 x 64... the first 32 x 32 (coord 0,0) being green grass, then second 32 x 32 (coords 64,0) being brown dirt.  Now the example you posted wouldn't work, because it would tile using both the green grass and the brown dirt.  If you supplied texture coordinates into the polyvector, it wouldn't repeat the pattern, but rather it would scale the texture to fit the mesh dimensions (which is good and we certainly like this functionality as it allows us to scale sprites easily). 

Just for some background info we are working on an iPhone framework and to keep speeds up we need to batch as much of the rendering as possible.  Therefore we use a single sprite sheet with multiple images.  Then we use polyvector to draw the images by supplying it the correct texture from the sprite sheet.  Being able to change the UV scale and UV positions using poly sprites should save some FPS, and allow us to make some pretty smart effects.

StuC_Ovine

  • Guest
Re: UV Parameters of Polyvectors
« Reply #3 on: 2009-Sep-01 »

I dont think you can repeat a sub-division of a texture as you are requesting


This works.  We will have to grabsprite the tile in question for the repeat to work.   Reading on forums it seems you can not repeat a sub divided texture.

Code: GLBasic [Select]
SETSCREEN 320,480,0
LIMITFPS 60


LOCAL sx = 320
LOCAL sy = 480

DRAWRECT 1, 1, 30, 30, RGB(0, 255, 0)
GRABSPRITE 0, 0, 0, 32, 32

GETSCREENSIZE sx, sy

col = RGB(255, 255, 255)

WHILE TRUE
        STARTPOLY 0
        glRepeat()
                POLYVECTOR 0, 0, 0, 0, col
                POLYVECTOR 0, sy, 0, sy, col
                POLYVECTOR sx, sy, sx, sy, col
                POLYVECTOR sx, 0, sx, 0, col
        ENDPOLY
        SHOWSCREEN
WEND

END





@FUNCTION dummy:
ENDFUNCTION



// here we need an inline block _outside_ of functions, that
// gives us some prototypes for glX calls.
INLINE
        } // end namespace __GLBASIC__ - see manual for INLINE

        #define GL_TEXTURE_2D 3553
        #define GL_TEXTURE_WRAP_S 10242
        #define GL_REPEAT 10497
        #define GL_TEXTURE_WRAP_T 10243

        // the functions are all >>extern "C" __stdcall<<
        extern "C"
        {
                void __stdcall glTexParameteri(float, float, float);
        }

        // reasuring the namespace
        namespace __GLBASIC__
        {
ENDINLINE

FUNCTION glRepeat:

        INLINE
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        ENDINLINE
       
ENDFUNCTION

 

StuC_Ovine

  • Guest
Re: UV Parameters of Polyvectors
« Reply #4 on: 2009-Sep-01 »

hmmm dont know why I posted that, its what glbasic does anyway :)


StuC_Ovine

  • Guest
Re: UV Parameters of Polyvectors
« Reply #5 on: 2009-Sep-01 »

I was expecting this to turn on and off the texture clamping but I guess GLbasic is doing a bit more under the hood ?

Code: GLBasic [Select]



SETSCREEN 320,480,0
LIMITFPS 60


LOCAL sx = 320
LOCAL sy = 480

DRAWRECT 1, 1, 30, 30, RGB(0, 255, 0)
GRABSPRITE 0, 0, 0, 32, 32

DRAWRECT 1, 1, 30, 30, RGB(255, 255, 0)
GRABSPRITE 1, 0, 0, 32, 32

GETSCREENSIZE sx, sy

col = RGB(255, 255, 255)

WHILE TRUE

        STARTPOLY 1
                glRepeat(FALSE)
                POLYVECTOR 150, 150, 0, 0, col
                POLYVECTOR 150, 200, 0, sy, col
                POLYVECTOR 200, 200, sx, sy, col
                POLYVECTOR 200, 150, sx, 0, col
        ENDPOLY
       
        STARTPOLY 0
                glRepeat(TRUE)                         
                POLYVECTOR 0, 0, 0, 0, col
                POLYVECTOR 0, 50, 0, sy, col
                POLYVECTOR 50, 50, sx, sy, col
                POLYVECTOR 50, 0, sx, 0, col
        ENDPOLY
        SHOWSCREEN
WEND

END



@FUNCTION dummy:
ENDFUNCTION



// here we need an inline block _outside_ of functions, that
// gives us some prototypes for glX calls.
INLINE
        } // end namespace __GLBASIC__ - see manual for INLINE

        #define GL_TEXTURE_2D 0x0DE1
        #define GL_TEXTURE_WRAP_S 0x2802
        #define GL_REPEAT 0x2901
        #define GL_TEXTURE_WRAP_T 0x2803
       
         #define GL_CLAMP_TO_EDGE 0x812F

        // the functions are all >>extern "C" __stdcall<<
        extern "C"
        {
                void __stdcall glTexParameteri(float, float, float);
        }

        // reasuring the namespace
        namespace __GLBASIC__
        {
ENDINLINE

FUNCTION glRepeat: Repeat = TRUE

        IF Repeat = TRUE
                INLINE
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                ENDINLINE
        ELSE
                DEBUG "OFF"
                INLINE
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
                ENDINLINE
        ENDIF
       
ENDFUNCTION


 

StuC_Ovine

  • Guest
Re: UV Parameters of Polyvectors
« Reply #6 on: 2009-Sep-01 »

My bad,  I was setting glTexParameteri with floats.

Turn the texture repeat off/on with    glRepeat(TRUE/FALSE).  Now Ive done it - its pretty pointless really :)

Heres a discussion on exactly you want todo

http://stackoverflow.com/questions/662107/how-to-use-glrepeat-to-repeat-only-a-selection-of-a-texture-atlas-opengl





Code: GLBasic [Select]




SETSCREEN 320,480,0
LIMITFPS 60


LOCAL sx = 320
LOCAL sy = 480

DRAWRECT 1, 1, 30, 30, RGB(0, 255, 0)
GRABSPRITE 0, 0, 0, 32, 32

GETSCREENSIZE sx, sy

col = RGB(255, 255, 255)

WHILE TRUE

        STARTPOLY 0
                glRepeat(FALSE)                         // turn off texture repeat
                POLYVECTOR 0, 0, 0, 0, col
                POLYVECTOR 0, sy, 0, sy, col
                POLYVECTOR sx, sy, sx, sy, col
                POLYVECTOR sx, 0, sx, 0, col
        ENDPOLY
       
       
        SHOWSCREEN
WEND

END

@FUNCTION dummy:
ENDFUNCTION



// here we need an inline block _outside_ of functions, that
// gives us some prototypes for glX calls.
INLINE
        } // end namespace __GLBASIC__ - see manual for INLINE

        #define GL_TEXTURE_2D 0x0DE1
        #define GL_TEXTURE_WRAP_S 0x2802
        #define GL_REPEAT 0x2901
        #define GL_TEXTURE_WRAP_T 0x2803
       
    #define GL_CLAMP_TO_EDGE 0x812F //0x2900

        // the functions are all >>extern "C" __stdcall<<
        extern "C"
        {
                void __stdcall glTexParameteri(int,int,int);
        }

        // reasuring the namespace
        namespace __GLBASIC__
        {
ENDINLINE

FUNCTION glRepeat: Repeat = TRUE

        IF Repeat = TRUE
                INLINE
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                ENDINLINE
        ELSE
                INLINE
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
                ENDINLINE
        ENDIF
       
ENDFUNCTION


 

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10711
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: UV Parameters of Polyvectors
« Reply #7 on: 2009-Sep-02 »
oh. I re-set that at the ENDPOLY call. My bad. I had to clamp because it looks bad sometines, else. But in a new version I will see if you use out-of-bounds u,v positions and enable wrapping then. Sorry for that.