OpenGL Tutorial 6 - Textures

preview_player
Показать описание
In this tutorial I'll teach you the basics of Textures in OpenGL.

*Source Code, Texture, and Exercises*

*stb Library*

*OpenGL Documentation*

*Discord Server*

*Patreon*

*Timestamps*
0:00 Types of Textures
0:15 stb Library
1:19 Square
1:35 Texture Sizes
1:58 Importing in an Image
2:40 Creating the Texture
3:04 Texture Units
3:40 Interpolation Types
4:32 Texture Mapping
5:48 Assigning the Image to the Texture
6:31 Errors
6:42 Mipmaps
7:11 Texture Coordinates
7:36 Vertex and Fragment Shaders
8:12 Finishing up
9:00 Texture Class
9:17 Comments & Ending

*References*

#opengl #opengltutorial #computergraphics #cpp #visualstudio
Рекомендации по теме
Комментарии
Автор

Best opengl tutorials, I hope your channel grows

unkownhedgehock
Автор

For those who didn't get a square after changing vertices and draw elements line, make sure you changed the VAO1.linkattrib() lines to:

VAO1.LinkAttrib(VBO1, 0, 3, GL_FLOAT, 8 * sizeof(float), (void*)0);
VAO1.LinkAttrib(VBO1, 1, 3, GL_FLOAT, 8 * sizeof(float), (void*)(3 * sizeof(float)));
VAO1.LinkAttrib(VBO1, 2, 2, GL_FLOAT, 8 * sizeof(float), (void*)(6 * sizeof(float)));

mackerel
Автор

If you're having a problem where the .txt file isn't turning into a proper .h file (it'll say something about not being able to find it when you try to compile). In the top left of the file explorer there are 4 tabs 'File' 'Home' 'Share' and 'View', click 'View' and make sure the check box named 'File name extenstions' is checked and then try naming it again.

zippyghost
Автор

Finally something for opengl that is up to date and nothings is a great repo great video man

thehardcorezombie
Автор

after this tutorial, I shall make my first 2d opengl game : )

dhruvagrawal
Автор

This is still the best OpenGL tutorial out there by far.

If you assume upper left corner is UV origin with positive U going to the right and positive V pointing down (like most other texture/image software) there is no need to flip image on load. Also be aware of your windings of vertices. CCW is default front face. CW is used in the tutorial. which isn't a problem until you use back face culling. You can define which is front or back but CCW is default front. This winding and UV direction stuff will help latter as it will allow you to make sense mathematically of the right hand rule and the vectors of normal mapping.

It's not a bad idea to use a test image with a grid and some text in it so it will be obvious if you have mirrored or stretched the image in some way by wrong UV coords. Especially on 3D models.. Blender has a great test pattern texture for this.

samuelpope
Автор

Amazing!
If you want use the .jpg extension for your texture image you must change the GL_RGBA to GL_RGB, cause the A is to Alpha channel.

Great video!

wladsoncedraz
Автор

Hint: you can use the last parameter of stbi_load to force the number of channels independently of the format (as long as the numbers make sense, I guess). 0 means "auto detect" from format.
This is useful if you want to have all your textures as PNGs (avoiding the dicey JPEG lossy compression...). When you want to ignore the alpha channel you can just set it to 3.

japedr
Автор

if someone has problems with loading the texture like me, change the line "unsigned char* bytes = stbi_load(image, &widthImg, &heightImg, &numColCh, 0);" last value to "STBI_rgb_alpha".
it worked for me

flapicat
Автор

Amazing video man, I have two questions:

1: Are you going to go over how to keep the scale of objects (like the triangle, or in this case popcat), independent of the window size? As in, not stretching out across the window?
2: Do you have some kind of roadmap or list of topics that you are going to go through? I'd love to know what you have in store for the future of this series.

Keep up the good work!

rommelrivera
Автор

I keep getting a "cannot find or open nvoglv64.pdb" error in VS2022. I hadn't had this error before this tutorial, and seems to be related to the stb library. However, I also recently upgraded my graphics card and forgot to uninstall drivers before hand, but I'm trying to avoid that as much as possible because it has a chance to cause system damage (when using DDU).
I also posted this on your discord just in case =)
Thanks for the help and I'm glad to say I've had no other errors besides this one that I couldn't fix, major props!

Sprunk
Автор

It's very important to give the same names in inputs(in) and output(out) between vertex and fragment shader, otherwise opengl could never know how to link them.

Byynx
Автор

Hi Victor! I have followed everything correctly up until you include the stb header file into stb.cpp. Visual studio is giving me an error when I try to include stb_image.h (#include <stb/stb_image.h>) Visual studio is saying that it is unable to open source file. Any ideas would be very helpful, thank you!

mitchellkelly
Автор

Victor eluded to this in the video, but for this to run correctly, you're texture size HAS to be a power of two. You will get a run-time error if it isn't. I had one that was 516x516. It was seg faulting, and I was scratching my head until I tried cropping the image to 512x512 based on his tip. Then it worked perfectly. So, I'd say it is more than a suggestion, it is a must.

brianrosenlof
Автор

what does 0 do for the second parameter of glUniform1i()? I looked the opengl document but it lacks the information of what it does.

yoonhakim
Автор

Hello Victor! Thank you for this series :) . But I am having hard time with an "exception thrown error (access violation)" at glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
when i comment it out lines that cause this, they just propagate to the next line.
Any ideas on what I might be doing wrong?

mackerel
Автор

I've got a problem - i cant get the texture to appear, just a black square with the dark blue backround - i have the texture in textures resource files folder and in the same place as the vs file itself as well, its a png file 1024x1024 size, colors were set to RGBA and the name is correct as well, i tried different images and still the same result

Greenlaser
Автор

I have a more complex texture and model (than a square). My texture is black (when displayed on the screen). I must have done some small mistake, but cant figure out what.

nomesa
Автор

Found that, the compiler requires


these lines

#define STB_IMAGE_IMPLEMENTATION
#include<stb/stb_image.h>

to be added
in order to bring the stbi_load() funtion
into Main.cpp

since I just changes location of the several scripts path direction into another one.

myelinsheathxd
Автор

Great video, there is lots of info here that i have never seen on many other channels 👌
Any chance you know how to do texture-arrays, or 3d-textures? I need to smoothly blend between one texture to the next based on a float value, but it needs 3 or more textures

blaarkies