1
\$\begingroup\$

I recently learned how to create shaders and was looking to make a simple top down game, starting with a tilemap. The problem I encountered, Whilke I can store a vbo of all the blocks in a "chunk" of blocks, I can't specify what texture it should have... or at least I don't see how! I could just bind the texture using GL.BindTexture() function, but that would only allow me to use one texture in the whole chunk! I don't know how many textures I might render, it could certainly be more than 8! Is there a way to bind a texture inside a vertex shader?

I basicly would like to do something like "Display Lists" in earlier opengl versions... but I want to use modern opengl techinques as much as possible!

\$\endgroup\$
2
\$\begingroup\$

Solution 1: Texture Atlas where you can tweak the UV coords in your mesh to specify a subsection of the texture to use for a portion of your map. This solution requires that each "tile" of the map be a separate quad so you can control the UV coords of each corner... sharing verticies at the corners of a tile will not work right.

Solution 2: if you are doing more like terrain than a tile map, texture splatting uses one texture to control the blending of texture data from several other textures to decide what the final pixel color is... a simple version could use RGBA data from the splat map to blend the colors from 4 other texture maps to create the final output... more complicated systems sometimes use multiple vertex colors to blend colors from 4/8/12 textures, but due to limitations in the number of samplers allowed in a pixel shader, this tends to take multiple shader passes.

Number 1 is probably what you want for a true top down tile mapped game.. but maybe texture splatting will give you other ideas :)

\$\endgroup\$
  • \$\begingroup\$ I underestand what you mean with texture atlas and it's certainly more attractive than texture splatting... but I clearly have a huge limitation on textures if I wanted to render them with animations or slightly different textures (eg: a block that changes its borders according to its neighbours). Could I create an array that contains the gpu ids of my loaded textures and then call them in the shader? some sort of glBindTexture in the shader code itself? \$\endgroup\$ – Philippe Paré Sep 17 '14 at 2:28
  • \$\begingroup\$ Common solution would be to separate "static" and "dynamic" geometry. Lots of cheap static geometry and small amount of more expensive dynamic geometry. \$\endgroup\$ – Jari Komppa Sep 17 '14 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.