How to render textures in GLSL

How do you render textures in GLSL? I know a bit about shaders, but i only use them in game engines, which usually make it easier to input textures and then render them in the shader.

1 Like

I have never used any game engines or textures or shaders before for anything…but here’s two sources I found that might help! :grin:

(I think this is right)

and
LearnOpenGL - Textures.

1 Like

That’s for C/C++, and I’m not using a game engine right now, I’m using a Repl with the GLSL template

1 Like

ah ok, sorry! Let me try something else

1 Like

Sorry, I’m not very educated on this subject, I don’t want to give you any misleading information, you’ll have to ask someone else other than me, my apologies :sweat:

1 Like

It depends really.
What kind of API are you using?
Which graphics library?

If you are using stb_image.h library there is a good example here by how to use it:
https://subscription.packtpub.com/book/game-development/9781838986193/2/ch02lvl1sec14/loading-images-with-stb

Lighthouse3d have a good tutorial about it and a good library too. https://www.lighthouse3d.com/tutorials/glsl-tutorial/

A simple way to load texture data into a texture object would be:

GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);

// Set your texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

// Load image data here
int width, height, numChannels;
unsigned char* data = stbi_load("path_to_your_image.png", &width, &height, &numChannels, 0);

// Use loaded image data here
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);

stbi_image_free(data);
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.