OpenGL 3D Game Tutorial 23: Texture Atlases

preview_player
Показать описание
LWJGL tutorial series on how to create a 3D Java game with OpenGL!

Adding texture atlas support this week!

Models and Textures:

End of video music- Kai Engel, "Waking Stars":
Рекомендации по теме
Комментарии
Автор

even after all of those years it is still helpful thx

Yamkaze
Автор

Best opengl tutorials ever! Every thing is clear Great work!

nyancoti
Автор

Hey ! If any of you cannot get the ferns to render at all, it might be because you used super.loadint instead of loadfloat in the StaticShader class.

works :
public void loadNumberOfRows(int nb) {
super.loadFloat(location_numberOfRows, nb);
}

doesn't :
public void loadNumberOfRows(int nb) {
super.loadInt(location_numberOfRows, nb);
}

The reason "int" doesn't work is because the uniform "numberOfRows" is a float in GLSL (but an int in java), so you know...

Hope this helps someone

azerez
Автор

Modifying this for a 2D sprite system. Is working great!

DesertCookie
Автор

We can make it more flexible by not remembering or specifying sprite index, and not requite sheet to have square resolution by compute individual sprite's texture coordinate ideally at the time of packing to produce final sheet. The idea is making texture packer tool that provides both GUI or cli functionality to pack sprites into sheet + meta file (information about sprites are stored in this file i.e. offset x/y, size, texture coordinate, file name, sheet's resolution, number of sprite, etc), and expose API to allow devs to integrate and be able to read such meta file in the game code.

The equation to calculate each sprite's texture coordinate is quite straight forward, and not difficult as initial expect.
The idea is to convert from sprite vertex's texcoord attribute (as input in vertex shader) into the new range . It's linear conversion. Thus we need to find min & max of texcoord u & v for the target range we're going to convert to by using vertex's texcoord attribute as input.

The final equations is like this

new_texcoord.x = (clip_texture_uv.y - clip_texture_uv.x) * texcoord.x + clip_texture_uv.x;
new_texcoord.y = (clip_texture_uv.w - clip_texture_uv.z) * texcoord.y + clip_texture_uv.z;

in which clip_texture_uv is vec4 containing (min_u, max_u, min_v, max_v) values and accessed via x, y, z, and w respectively.

clip_texture_uv can be found easily by

clip_texture_uv.x = sprite.offset.x / sheet.size.width
clip_texture_uv.y = (sprite.offset.x + sprite.size.width) / sheet.size.width
clip_texture_uv.z = sprite.offset.y / sheet.size.height
clip_texture_uv.w = (sprite.offset.y + sprite.size.height) / sheet.size.height


After all thanks for great video! It allows me to dig deeper enough for this topic. Very useful.

haxpor
Автор

I'm loving your tutorials, you cover pretty much everything to help people get a proper understanding on what you're doing.. not many people do that. quick question, though. How frequently do you plan on uploading the next videos in this series? I'm excited to see what's next (Especially how to do it.) Also, could you maybe upload the source code to what's done so far? Sorry for Rambling on, It's 3:30 am here, and I'm tired. xD

zapixinc
Автор

You can also use load int in static shader...make sure uniform is int in vertex shader...

kundanborakb
Автор

if the offset calculation code doesn't work .
Try this :
auto factor = abs(1.0 / float(numRows));
//xoffset
auto column = ( textureIndex % numRows);
xOffset =factor*column;

//yOffset
auto row =(textureIndex / numRows);
yOffset =factor*row;


note:Above code is written in c++.
Thank you.

ajaykumar-qwqr
Автор

hey I haven't implemented this yet but I know I can i tested a very simple version but when someone asks about the animation just tell them to rig there object in blender make the animation and export every frame make an array list of all the exports in order and loop through them as needed(all this is just temporary until you cover it in the series) and use the set model method to update the objects animation because I know a lot of people keep asking about it and this would work temporarily

harleyracer
Автор

You could actually uniform load all the 3 values with one vec3. This is easier and propably also more efficient as it requires less uniform sendings. So just place offset in x and y and the number of rows in z. You can do the same for the fog(in one of previous tutorials) if you wish to uniform the gradient and density - they can use a vec2 where x is density and y is gradient.;)

AdriansNetlis
Автор

Why don't you use the texture arrays?

jacadev
Автор

Does not such atlases have negative effects on mipmapping?

mintDesktop
Автор

I think this kind the textureIndex will wrong, besause OpenGL texture Coords System (0, 0) is in left-bttom, (1, 1)is right-top, so Y axis will be different, getTextureOffsetY() may should be float offsetY = 1.0f - ((1.0f / numberOfRows) + ((float) row / (float) numberOfRows));

dreamtowards
Автор

Love the tutorials man.
Do you have any resources on how I could make my own map editor? I'm looking to send mapdata from server -> client. But I'm not sure what and how I should be sending.

ariosrsps
Автор

At 6:46 why did you load up a float instead of an int; the parameter was an int?

arsgaming
Автор

I'm getting just 2 of the 4 textures (in particular th first and the last), any ideas ?

mosen
Автор

So combining with multytexturing we can make terrain more then with 4 textures? Or, how to do it?

homelleon
Автор

Hey ThinMatrix, I love your videos and I'm thankful for the content you put out. I'm new to 3D game development; with a good foundation of Java development, what do you suggest I do to begin making games using LWJGL 3?

marinated
Автор

I get a problem when I debug that I have only the first texture of the png file
when I try to solve it I find I didn't add casting method to getTextureXOffset and getTextureYOffset

so check if you add it like that

public float getTextureXOffset(){
int column = textureIndex %
return (float) column /(float)
}

public float getTextureYOffset(){
int row = textureIndex /
return (float) row / (float)
}

ozcanshalak
Автор

first: great stuff!
second: are u going to cover ray picking? :)

Frekos