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
do you mean something like this?
makes a simple gras tile with black border to see the single tiles on the polyvector
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
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.
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.
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
hmmm dont know why I posted that, its what glbasic does anyway :)
I was expecting this to turn on and off the texture clamping but I guess GLbasic is doing a bit more under the hood ?
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
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
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
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.