Textures in OpenGL

  Рет қаралды 165,915

The Cherno

The Cherno

Күн бұрын

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/opengl
stb_image ► github.com/nothings/stb/blob/...
Thank you to the following Patreon supporters:
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund
- Kerem Demirer
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K

Пікірлер: 350
@TheCherno
@TheCherno 6 жыл бұрын
Hope you guys enjoy this (slightly longer) video! We're definitely going to talk more about how textures work and what we can do with them in the future, this is more of an introductory video as well as an example. :) Also one little mistake I made was with the m_BPP member in the texture class; I keep saying that this is the *bits* per pixel however really it's storing the *bytes* per pixel, which in this case is 4 since our texture is RGBA.
@hamseiggeh6331
@hamseiggeh6331 6 жыл бұрын
TheChernoProject hello i want to know what is the framework.....thankz
@AmeshaSpentaArmaiti
@AmeshaSpentaArmaiti 6 жыл бұрын
There is no framework! This is as close to "made from scratch" as you're going to get.
@TheLavaBlock
@TheLavaBlock 6 жыл бұрын
Great work. Enjoyed it :)
@ratwalsh8794
@ratwalsh8794 5 жыл бұрын
May I ask you sir, I have gone over the code several times and it appears to be exactly like yours and I have no warnings or errors, yet the texture appears as a black square. Could this be a library or png related issue? if you have any idea how to fix, I would greatly appreciate the help. Thank you, Keep up the good work!
@sauravstark2687
@sauravstark2687 5 жыл бұрын
@@ratwalsh8794 Try checking if you have spelled the location of image correctly, it worked in my case. While we're at it does anyone know what to do with 'Warning u_Color not found' message?
@namhto94
@namhto94 4 жыл бұрын
Guys if your texture is not showing (like me...), make sure you are using glTexParameteri() and not glTextureParameteri() in the Texture constructor ! I just rewatched the full video to find what was wrong... Thanks for this great API OpenGL lol
@vishwasbhaskar1006
@vishwasbhaskar1006 4 жыл бұрын
Thanks man you really fixed my problem.
@mieyeombe3201
@mieyeombe3201 4 жыл бұрын
Thanks a lot! You helped me out
@gullideckel4902
@gullideckel4902 4 жыл бұрын
same problem. Thank you!
@isaiasdimitri4110
@isaiasdimitri4110 3 жыл бұрын
Hey man, you are the man.
@dawidlubczynski7502
@dawidlubczynski7502 3 жыл бұрын
Thankfully I read this comment. Thanks!
@ucmRich
@ucmRich 6 жыл бұрын
Time=23:07="Detailed in-depth video on [how the rasterization works] and how [texture sampling works]" ^--Yes Plz 0:-)
@cghost4yt
@cghost4yt 3 жыл бұрын
Just a small tip if you want stb_image to print out error messages: In the stb_image.cpp file after you have defined "STB_IMAGE_IMPLEMENTATION" you also define "STBI_FAILURE_USERMSG" and then in the Texture.cpp file you could do something similar to this: if (m_LocalBuffer) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer); glBindTexture(GL_TEXTURE_2D, 0); stbi_image_free(m_LocalBuffer); } else { std::cout
@the_zed6098
@the_zed6098 Жыл бұрын
If you're by any chance getting a solid color when you're using a texture, make sure that in the AddBuffer function in the VertexArray class that you're passing the index into glEnableVertexAttribArray(), so it'd be glEnableVertexAttribArray(i). Missed it, silly me.
@fappylp2574
@fappylp2574 Жыл бұрын
Woah, thanks. Would have never found that!
@olavschioett4101
@olavschioett4101 Жыл бұрын
thank you verry mouch i did the same thing
@quanta3968
@quanta3968 Жыл бұрын
u saved my life xd
@philip_love_you
@philip_love_you Жыл бұрын
Thanks bro, you saved my life. XD
@euvictorguedes
@euvictorguedes 11 ай бұрын
Had to log in to my account just to say how much I love you! Spent the entire afternoon viewing and reviewing the code, comparing and everything. Even ChatGPT couldn't figure out. Thank you so much!
@hiderr6805
@hiderr6805 3 жыл бұрын
I realy love how you explain everything! Thank you for all the videos on your channel!! I'm waiting for all the 'In depth videos ' XD
@DanipBlog
@DanipBlog 5 жыл бұрын
This is so awesome dude, thank you for making these series!! You don't know how much you're helping people!
@kristyii8008
@kristyii8008 5 жыл бұрын
Hey, looks like you succeed at this point, can you send me code please, mine just do not working, i will be very grateful))))
@ekhalips6972
@ekhalips6972 6 жыл бұрын
been searching for those kind of tutorials for 2 years, found Cherno few months ago, and learned so much, Thank You!
@DJNecktron
@DJNecktron 3 жыл бұрын
When the content of this entire series is basically everything I need for my Real Time Graphics course at university, just a bit of special requierments for the assignments. Very nice for getting knowledge, (both new and refreshed), for my further projects with OpenGL!
@Fobber92
@Fobber92 6 жыл бұрын
great episode mate! love the long videos too!
@Micha-mj7vg
@Micha-mj7vg 3 жыл бұрын
*Possible errors:* > You forgot to bind your shader before setting u_Texture > Program can't find your u_Color uniform because shader's compiler ignored it due to being useless ( do something like: --> color = u_Color * texColor; You got no errors and still black screen because you put somewhere "0" instead of "m_renderer_id" > You forgot to change the "f" letter while copying SetUniform1f function (propably not) > In VertexBufferLayout::Push you forgot to multiply "m_stride" by "count" ( example: m_stride += VertexBufferElement::getSizeOfType(SOME_GL_TYPE_IDK) * count )
@theantonlulz
@theantonlulz 2 жыл бұрын
I swear you are a life saver, I was look at Texture::bind for a while thinking that there was no way glBindTexture was always supposed to bind to 0, and once I changed it it worked.
@Micha-mj7vg
@Micha-mj7vg 2 жыл бұрын
Ha! knew it
@coopikoop912
@coopikoop912 Жыл бұрын
Another possible error: You decided to go to ms paint to draw a quick png file and it is black coloring on a transparent background. Call "glClearColor(1.0f, 1.0f, 1.0, 1.0f);" just before renderer.clear(); in your loop. This will make the background white so you can see it
@wrawler
@wrawler 8 ай бұрын
i had missing semicolons in shader files 😅
@theo-dr2dz
@theo-dr2dz 7 ай бұрын
It;s not necessary to have different names for the set_uniform functions (yes, I change the names, I don't like all those capital letters sprinkled all over the place). You can just make overloads with the same name. The compiler will select the right one based on the function parameters. Like: void set_uniform (const std::string& name, float f0, float f1, float f2, float f3); void set_uniform (const std::string& name, int i); Also, in the vertex array, nowadays we can use constexpr if instead of all those template specialisations. That looks a lot better and it costs nothing, the compiler wil figure it all out at compile time.
@TinoBurset
@TinoBurset 3 жыл бұрын
Fantastic content as usual! (Huge) Thanks for sharing your knowledge Yan! 🙌
@yannickmonjeamb3469
@yannickmonjeamb3469 6 жыл бұрын
This Videos was really great. I like your explanations and how clean your code is. I hope you start with the GameEngine Series soon. I'm verey exited.
@sebastianmestre2145
@sebastianmestre2145 6 жыл бұрын
Your couch has the most cinematic lighting ever
@merle17
@merle17 Жыл бұрын
Worked right outta the box, amazing video.
@diegosandoval2043
@diegosandoval2043 4 жыл бұрын
Everyone: Drawing Cherno: Drawering
@heyyare86
@heyyare86 4 жыл бұрын
I am not sure, it is like 'drawring'
@MGSncB
@MGSncB 3 жыл бұрын
That's how a lot of Brits and Australians speak.
@weewoo3768
@weewoo3768 2 жыл бұрын
I'm just glad I wasn't the only one distracted by this
@user-wc9cw1sn8n
@user-wc9cw1sn8n Ай бұрын
@@MGSncB *All Brits and Australians if they are not trying to sound American
@aryesegal1988
@aryesegal1988 6 жыл бұрын
Wow! a video half an hour long! NICEEE! :) Thanks, Cherno bruh!
@MoMo-hh1zt
@MoMo-hh1zt Жыл бұрын
Hi Cherno!Thanks for your video!It helps me solve a lots of problems with OpenGL.And I think it's the best video I have seen in OpenGL!A lots of gratitude for you!
@mathewmccloskey8242
@mathewmccloskey8242 6 жыл бұрын
Has anyone made a list of all the promised episodes?
@XxAl3X3IxX
@XxAl3X3IxX 6 жыл бұрын
About 20 promised videos just for this series
@Dodo17sky
@Dodo17sky 6 жыл бұрын
Look at his profile videos list! At his age I think he made a lot of episodes from what he promised. Just pe patient !
@erlemusv
@erlemusv 5 жыл бұрын
"I promise one day I'll do an episode to make a list of all the promised episodes". Just kidding. This man rocks
@anoomage
@anoomage 7 ай бұрын
I ran into a problem. My texture either wouldn't show up, either would show as a solid white square. I tried to follow advice from comments section but nothing helped. In fact... I tried some things on my own, like adding a normal field in my vertices, creating a Mesh class with a loader and a Window class, so the debugging was hard. I have a Vertex class and its instances are stored in a std::vector, and components are Position, Normal, TexCoords. So, in the vertex shader, the location of "vec2 texCoords" is 2, not 1 !!! Location 1 will be for normal. I think I did not understand this part at all but after hours of debugging, I think now I got it :') Location stands for VertexAttribPointer number.
@NoodleFlame
@NoodleFlame 2 жыл бұрын
in the fragment shader you can multiply the color by the call to texture: vec4 texColor = texture(u_Texture, v_TexCoord) * u_Color;
@theneuroware4057
@theneuroware4057 2 жыл бұрын
Very good tutorial! Thx!
@hermysfancy9514
@hermysfancy9514 3 жыл бұрын
For the flipped texture issue, you can also invert the 1s and 0s in the Y direction for the texture coordinates. So if your vertexBuffer starts like this : [-0.5,-0.5, 0.0, 0.0], [ 0.5,-0.5, 1.0, 0.0], [0.5, 0.5, 1.0, 1.0], [-0.5, 0.5, 0.0, 1.0] you change it to this: [-0.5,-0.5, 0.0, 1.0], [ 0.5,-0.5, 1.0, 1.0], [0.5, 0.5, 1.0, 0.0], [-0.5, 0.5, 0.0, 0.0] and the shader will read the texture upside down with no overhead as far as I can tell. Somebody correct me if this as some wacky downstream effect or something. I'm just some guy along for the ride hear.
@Kroschinsky
@Kroschinsky 2 жыл бұрын
if you do that the image will be draw upside down
@adamodimattia
@adamodimattia 4 жыл бұрын
Wow, finally I thouroughly understood how texture sampling works exactly. You’re amazing man!
@sssstupidkid1234
@sssstupidkid1234 6 жыл бұрын
Hey TheCherno, this is a verry good video.. are you planning to create a video on UBOs?
@lucaaaa6382
@lucaaaa6382 Жыл бұрын
If I could like this a million times I would. You have effectively become my teacher.
@nikoszervo
@nikoszervo 6 жыл бұрын
Cherno, you're really making a good job! I'm an advanced programmer but still its so difficult to learn opengl and the documentation is for those who have done graphics before. I hope next video be about matrices transformations! I really wanna see some motion on the screen and 3d graphics!!!
@giancedrick507
@giancedrick507 3 жыл бұрын
usually before you go into matrices and animations, you have to do some math
@DBbombed
@DBbombed 4 жыл бұрын
Just in case anyone else ran into this issue if you are trying to load a png with sdbi_load and it returned an empty image, At least in my case, it was because the png I was using was an indexed png and the stb_image header can not handle it just pull it into an image editor change the type and save the png again and it worked.
@juanx783
@juanx783 3 жыл бұрын
You're right, dude! Png is tricky. Your words here helped me save tons of time.
@chinmayanand896
@chinmayanand896 6 жыл бұрын
we like long videos dear....i always your confidence while you are telling something good.
@ldmdesign5610
@ldmdesign5610 2 жыл бұрын
These videos are awesome and doing it after going through half of the C++ ones is helping to see and practice using all that stuff over and over. Excited to try the game engine series soon too. Have to wonder though what has changed in 4 years since the videos were made.
@CharmingPotato14
@CharmingPotato14 3 жыл бұрын
stbi_set_flip_vertically_on_load(1) fixed my problem where textures were loading upside down. Thank you so much!
@YellCalum
@YellCalum 6 жыл бұрын
Hey, so you mentioned that most game engines use their own file formats for textures. I was wondering does this also apply to models, sounds, etc? and why? to keep the format similar to the internal one and improve loading times? Any file formats you would suggest not caring about intellectual property protection? also great video! 30 min videos are good :D
@sizzlebae2060
@sizzlebae2060 6 жыл бұрын
Interesting, I have never really thought about this
@blujay3639
@blujay3639 5 жыл бұрын
This was a long time ago, but I still believe that it warrants an answer. Many companies use proprietary (or their own unique) file formats for many reasons. One of these reasons is protection against piracy and/or modding. For instance, Nintendo uses file formats such as .mbn for 3D models in Super Smash Bros. for Nintendo 3DS, to at least slow down the development of texture/model hacks (took the hackers almost three years). Also, when you design the file format from scratch, you are less prone to bugs cropping up if you implement your own unique setup (it would be like designing a car from scratch, you would know where every part was whereas you would need a manual for doing the same thing but for a Toyota). This also plays into the fact that your group alone determines how the file format is created, meaning that there won't be very much variation (if any) in the format (look at the bitmap file format for a counter-example to this).
@koungmeng
@koungmeng 4 жыл бұрын
@@sizzlebae2060 is that Chitoge?
@sizzlebae2060
@sizzlebae2060 4 жыл бұрын
@@koungmeng yah
@bluescanfly1981
@bluescanfly1981 2 жыл бұрын
It applies to every asset. when making your own game / game engine you know what assets belong together - this lets you compress, pack or otherwise optimize the asset pipeline - this becomes particularly important across multiple platforms. The artists, designers on your team usually work with industry standard tools, however you often write plugins / exporters for these tools to produce your custom formats
@dogbreth7
@dogbreth7 6 жыл бұрын
I think a video on the rasterization process would be really awesome!
@gabrielguga7668
@gabrielguga7668 4 жыл бұрын
What is the reason to separately create .h and .cpp files of the same class when you can just Add > Class?
@sjscurrell187
@sjscurrell187 3 жыл бұрын
Hey The Cherno. I'm really enjoying you're OpenGL series. I'm slightly confused about how the interpolated texture coordinates are being passed from the vertex shader to the fragment/pixel shader. In your episode on shaders you mention the vertex shader is called once per vertex, and the fragment shader called once per pixel. That makes sense, , but what I don't understand is if that is the case would the texture coordinates passed to the fragment shader only ever be the values defined in the vertex buffer? Since the vertex shader only runs 6(?) times how does openGL know to interpolate the texture coordinates before passing them into the fragment shader? Hope that makes sense.
@EECyrpys
@EECyrpys 11 ай бұрын
Ye, I'm new at this, and at this point in the course it feels as if we don't really know exactly how the shaders work ;p
@nguyenvietducbg
@nguyenvietducbg Жыл бұрын
BIG THANK!!!
@iyappansriram9854
@iyappansriram9854 3 жыл бұрын
And if suppose you want to include stb_image.h in multiple files, you can make sure to #define STB_IMAGE_STATIC before including stb_image.h....... GREAT SERIES CHERNO!
@TheRealFFS
@TheRealFFS 3 жыл бұрын
Thanks man, just recently had this issue.
@iyappansriram9854
@iyappansriram9854 3 жыл бұрын
@@TheRealFFS you're welcome😊
@thomasrouch3944
@thomasrouch3944 3 жыл бұрын
If your IDE is automatically formatting your code, you could get a "expected primary-expression before ‘>’ token" error when compiling stb. Simply copy-paste-save the stb code outside the editor and you will be fine.
@chrspinto
@chrspinto 2 жыл бұрын
Here you set the texture coord for each vertex of the quad. How would you manage a complex surface which several triangles. What texture coord would i set for each of them?
@lisandroCT
@lisandroCT 6 жыл бұрын
Hey, Cherno! Really great content, thank you! Quick question? What happens if we call the unbind() method but it turns out we have changed the active texture before (binding another texture, for example), wouldn't that unbind that other texture slot?
@AmeshaSpentaArmaiti
@AmeshaSpentaArmaiti 6 жыл бұрын
Yes, it would! That's why you have to be careful and make sure you're unbinding the slot you bound to in the first place. You could store the slot the texture is currently in ("currently" because you can rebind slots easily). It's also helpful to unbind immediately after the texture is no longer needed, say, at the end of a draw call so you don't have to worry about that in the first place.
@lisandroCT
@lisandroCT 6 жыл бұрын
Jinzo Okami I thought about caching the slot but that wouldn't allow me to reuse the texture in different slots. What if I keep a texture binded and I don't ever use it again, does that affect the performance?
@AmeshaSpentaArmaiti
@AmeshaSpentaArmaiti 6 жыл бұрын
Lisandro Crespo if it does affect performance, it's not by much. The texture slots only get used when the shader accesses them. It would actually be less of a performance impact if you never unbound. Also, I can't think of a situation where you would want a single image in multiple slots. Unless you mean rebinding, in which case, just overwrite the current texture slot.
@JorneDeSmedt
@JorneDeSmedt 6 жыл бұрын
NVidia seems to have a lot of the features already enabled in their implementation of OpenGL. First the basic white shader, now blending... The only downside is that I can't actually confirm if everything also works on a system where those things aren't enabled by default.
@anonymoussloth6687
@anonymoussloth6687 3 жыл бұрын
Does this mean that the texture is now in gpu memory? So suppose we had to make changes to it alot (ex: Each frame in our application) would the texture be modified in the gpu or in the CPU and sent back and forth to the gpu?
@hiren07ec
@hiren07ec 3 жыл бұрын
if you are getting a weird error. Whenever you try to add a texture, the shape only takes on one color. This color seems to be the value of the top left pixel of the PNG Fixed it - in VertexArray.cpp, VertexArray::AddBuffer, inside for loop glEnableVertexAttribArray has to be called with "i". in previous video cherno used 0 so that it's not working
@drammsleo1624
@drammsleo1624 Жыл бұрын
Thank you! This worked for me.
@I_hate_HANDLES
@I_hate_HANDLES 8 ай бұрын
thank you so much !! now i can go to eat junk food without worrying about the bug !! how
@robtroman818
@robtroman818 5 жыл бұрын
When I try to load the texture file with stbi_load it does not load correctly and warns error reading characters in string I have tried different files and file formats but always get the same result
@GrandPoobah4
@GrandPoobah4 6 жыл бұрын
So I have followed along with all your code up to this point, but now I'm getting a weird error. Whenever I try to add a texture, the shape only takes on one color. This color seems to be the value of the top left pixel of the PNG. Is this a common issue/ is there an easy fix?
@GrandPoobah4
@GrandPoobah4 6 жыл бұрын
Fixed it - in VertexArray.cpp, glEnableVertexAttribArray has to be called with "i". Looks like reading the docs does help!
@archcisero3049
@archcisero3049 6 жыл бұрын
ThanX for this! Very logical and straightforward to see when you pointed it out but didn't notice right away! When push-function is called again (for making space for the u_Texturer floats) another element of the std::vector gets constructed and pushed to m_Elements. Hence it need to be enabled with glEnableVertexAttribArray. I believe Cherno used 0 not "i" at previous tuts when we were only dealing with the positions. Didn't see him change it in this one though so not sure how he got it working. I'm also running theese tuts in ArchLinux setup with Vscode so my push function differs slightly due to the template-specification problem for other envirnments/toolchains than VisualStudio-compiler/Windows.. Great tutorials Cherno! :-)
@FROMANUSSUM
@FROMANUSSUM 5 жыл бұрын
Hot damn! Thanks dude!
@galenzhang3163
@galenzhang3163 4 жыл бұрын
Wow!Wow!WoW!!!!!!!!!!!!!! Dude! Infinite Thank u to you! I almost bailed on this episode you saved me!
@funnymackerel9432
@funnymackerel9432 4 жыл бұрын
@@GrandPoobah4 You are a Superhero! Thnaks a lot!
@Betospin1
@Betospin1 5 жыл бұрын
I got a big memory leak, I don't know if in some part is necessary to unbind the texture, someone knows?
@beachforestmountain4269
@beachforestmountain4269 4 жыл бұрын
If you are having trouble with the texture not showing up, check that in the Basic.shader file you have the line "uniform sampler2D u_Texture;" and NOT "uniform sampler2d u_Texture;". (I had a lowercase "d" instead of an uppercase "D") I had to go through the whole video again to find my mistake.
@miles2354
@miles2354 Жыл бұрын
2 years later but thanks
@beachforestmountain4269
@beachforestmountain4269 Жыл бұрын
@@miles2354 No worries man.
@Babaelow
@Babaelow 5 жыл бұрын
What about ktx format? Is very easy to load too.
@Byynx
@Byynx Жыл бұрын
Case you're having access violation error in stbi_load() function, just creat int variables for each parameter after "width". Cast it if you need.
@jtaimneas
@jtaimneas 6 жыл бұрын
question: does u_Color do anything now? I keep the CMD screen open and see this "WARNING: uniform 'u_Color' doesn't exist!"
@SasisaPlays
@SasisaPlays 5 жыл бұрын
U can blend texture with u_color by multiplication. Example: frag_color = texture(tex, uv) * u_color;
@username17234
@username17234 4 жыл бұрын
When the shader compiler detects that a uniform will never be used, it might choose to stripe it off the code. So when you're trying to set that uniform up from your main application, it's not finding it. To fix it, either remove the references you made to it in the main app, or use it (even if banally) in the shader.
@giancedrick507
@giancedrick507 3 жыл бұрын
last time I got this problem is cause I got glDraw parameters wrong
@ilyosbeknajmiddinov6754
@ilyosbeknajmiddinov6754 2 жыл бұрын
hello bro help me this string while cout Warning: uniform 'u_Color' doesn't exist! how can I fix this pls help and 2 errors C4430 C2143
@adrielbradley6677
@adrielbradley6677 6 ай бұрын
I didn't enable blending, but my image came out fine, any idea why?
@nickkane-dev
@nickkane-dev 3 жыл бұрын
holy shit, I just wasted a ton of time debugging code that worked perfectly fine when the problem was my shader code. Opengl didn't throw an error for me. Make sure to check the names of your out parameter vs your in parameter of your vertex and fragment shaders. I feel pretty dumb right now lol
@JustYesntMan
@JustYesntMan 5 жыл бұрын
how to update my render sizes on window resize ? right now they are hard coded as you know
@nielsdaemen
@nielsdaemen 4 жыл бұрын
what about float textures for fluid simulation?
@ressley1685
@ressley1685 3 жыл бұрын
you are the best!
@awuuwa
@awuuwa 2 жыл бұрын
Make a tutorial on how to use bindless textures
@DragonBlazeXII
@DragonBlazeXII 2 ай бұрын
If anyone is experiencing issues with textures appearing as a single color, ensure that in the VertexArray.cpp file, on the line where it states "offset += element.count * VertexBufferElement::GetSizeOfType(element.type);", you are multiplying element.count by VertexBufferElement::GetSizeOfType(element.type) instead of adding as I mistakenly did.
@theashbot4097
@theashbot4097 6 ай бұрын
What does v stand for? 26:30. Thank you!
@fahdv2597
@fahdv2597 6 жыл бұрын
I subscribed 4 seconds in the video
@QIZI94
@QIZI94 6 жыл бұрын
I think it would be better to make coordinates as uniforms, for example when you want to use it for sprites.
@yulozano4294
@yulozano4294 5 жыл бұрын
if you don't see anything on your screen, it's might because you have to push to your layout 2 times. layout.Push(2); layout.Push(2);
@yavuzselimcagan5233
@yavuzselimcagan5233 Жыл бұрын
If VertexShader is called 4 times in this case, which out v_TexCoord is passed to FragmentShader? of 4? And which pixels look out for which vertex's outputs?
@ottaviarossini8020
@ottaviarossini8020 3 жыл бұрын
Hey, I am still facing some trouble with the textures. Somehow the rectangle takes only the left bottom most part of my texture. Any ideas? Could they have changed sth in the libraries? Maybe my PNG is faulty? ( created it with the export tool of Illustrator)
@tobiaspfatrisch3473
@tobiaspfatrisch3473 3 жыл бұрын
Did you found a solution for this problem? I have trouble like since the last 4 hours with exactly this "bug"...
@tobiaspfatrisch3473
@tobiaspfatrisch3473 3 жыл бұрын
Found the solution in the comments: VertexArray.cpp: glEnableVertexAttribArray(0) has to be changed to glEnableVertexAttribArray(i)
@spitfxre
@spitfxre 3 жыл бұрын
@@tobiaspfatrisch3473 i love you thanks dude
@dgmullin1
@dgmullin1 2 жыл бұрын
This happened to me and it was because I forgot to change the second layout in Basic.shader to "layout(location = 1)" so it was reading the position coordinates as texture coordinates 😳
@Ta5taturta5t3
@Ta5taturta5t3 6 жыл бұрын
Why is glActiveTexture() not called in the constructor before binding the Texture?
@Bundas102
@Bundas102 4 жыл бұрын
It doesn't matter which slot it binds to, because you don't want to use it for rendering there.
@tomkohler1609
@tomkohler1609 Жыл бұрын
@@Bundas102 It does matter, because it will break any texture binding in the current active texture slot. Same goes for the Unbind function: texture1.bind(0); // bind texture1 in slot 0 texture2.bind(1); // bind texture2 in slot 1 texture1.unbind(); // which texture will be unbound now?
@TheTruock
@TheTruock 2 жыл бұрын
Probably you also want to remove the "u_color" uniform handling in the code, since it will be probably get deleted from the shader during the compilation of it. Otherwise you can try to combine the texture together with the blinking effect with a line like this color = texColor * u_color;
@killcode6717
@killcode6717 Жыл бұрын
you Sir, Are an angel
@johnraz99
@johnraz99 Жыл бұрын
Thank you!
@jangronowski8180
@jangronowski8180 3 жыл бұрын
I'm confused about the vertex buffer layout. If the stride is two floats and the offset is 0 should the texture cords be interpreted as positions aka the 0.0 and 0.0 being positions? What's separating positions and textures?
@Byynx
@Byynx Жыл бұрын
With the TexCoordinates attributte now the total Vertex stride is 4 * sizeof(float). 2 float for position and 2 floats for texCoords. And yes texcoords beggins at coord (x0.y0) and ends at (x1,y1). Like a screen coordinates but between 0 and 1.
@kumu2024
@kumu2024 5 ай бұрын
The problem with this tutorial is that the texture coordinate is written manually to the vertex of the shape. I cannot figure out how to calculate the textur coordinates for shapes that might be loaded dynamically? how would you calculate that? All tutorials assumes that you have a 3x3 vertices ..etc. and they add the texture coordinate to that array. I cannot figure out how to do that.
@ameerhamza8300
@ameerhamza8300 4 жыл бұрын
I am not getting the intellisense dropdown of glew.h in any other file except Application.cpp, can anyone help me? EDIT: Intellisense is only working in main function, If I make main function in any other file like Texture.cpp it works there EDIT2: The problem seems to be that whenever I make a "GLLog" call, I cannot see intellisense in the function where GLLog is called in any line after that call, any line before that call still shows the dropdown.
@imcnx1563
@imcnx1563 3 жыл бұрын
What’s the difference between stb_image.h and stb_image_write.h?
@VoidAshen
@VoidAshen 3 жыл бұрын
hey but my render was already blended without doing anything
@zlugio803
@zlugio803 6 жыл бұрын
Hey Cherno, are you going to do a internet library series? Obviously for c++
@giancedrick507
@giancedrick507 3 жыл бұрын
usually he specializes in graphics programming, but I would love someone to use boost
@TheMightyPunion
@TheMightyPunion Жыл бұрын
why do my textures appear in the top right of the square
@testedpugtato9687
@testedpugtato9687 Жыл бұрын
Im getting kind of a weird error. The image is rendering perfectly, but only for one of the two triangles. For the other one, the color is being stretched from the top of the triangle all the way down. Any clues as to why this is happening?
@EECyrpys
@EECyrpys 11 ай бұрын
I managed to recreate this by "mistyping" one of the values in the positions array (the ones he added in this video), so if you get this behavior, that is the first place to check :)
@cloudbeta614
@cloudbeta614 Жыл бұрын
Hello! My vertexArray (The shape of my vertices) is black when i try to render the texture... I tried to copy everything you write but it still does not work, no matter what is do! What should i do? I tried version 3.3 and version 4.6. Didnt work any way!
@eggmeister6641
@eggmeister6641 3 жыл бұрын
screen black. how to fix?
@gwd_0050
@gwd_0050 3 жыл бұрын
I have gone through the video 2 times now and still got a black screen. any ideas for what could be wrong? Edit: fixed it. third re-watch is the charm. filepath was naturally wrong with one letter
@chrspinto
@chrspinto 2 жыл бұрын
What version of OpenGL are you using?
@iyappansriram9854
@iyappansriram9854 3 жыл бұрын
Hey Cherno! I tried implementing STB_Image to my openGL project. Worked Great! But when I tried to abstract it into something like a texture class, I get a linker error saying i have redefined STB image functions. Any tips on how to avoid that? I dont think i can rewrite the entire STB_image.h to have a .cpp file of its own. Thank you, much appreciated!
@iyappansriram9854
@iyappansriram9854 3 жыл бұрын
And i know STB image explicitly says for me to include it in one file. But the header is getting circled around. I don't know what to do...
@iyappansriram9854
@iyappansriram9854 3 жыл бұрын
figured it out. I was including stb_image.h in multiple files. Made its own CPP file and defined STB_IMAGE_STATIC before including stb_image.h
@nidalbizri
@nidalbizri 3 жыл бұрын
Why include shader.SetUniform1i("u_Texture",0); it has no effect on the final result and produces an error message that "u_Texture" is not found !?
@advayg
@advayg 3 жыл бұрын
Ig you didn't bind your shader before that
@darthvader8469
@darthvader8469 4 жыл бұрын
Oyea. Alfin texturas :'3
@darthvader8469
@darthvader8469 3 жыл бұрын
xdddddd
@SohailSiadat
@SohailSiadat Жыл бұрын
Can you explain more about why game engines use their own format? Do you mean each use their custom format? Or there are industry standard file format suitable for their use (eg mipmapping, certain encoding and size needs etc) makes them suitable for standard implementations.
@adrielbradley6677
@adrielbradley6677 6 ай бұрын
Did you ever find an answer to this?
@Byynx
@Byynx 11 ай бұрын
Guy's it's very important to give the same names in inputs(in) and outputs(out) variables between vertex and fragment shader, otherwise opengl could never know how to link them.
@ablender5750
@ablender5750 5 жыл бұрын
My texture is displaying weirdly, no matter what I do with the texture coordinates in the vertices the images bottom left (0, 0) is always in the centre of the screen. And likewise the top right of the image (1, 1) is always at the top right of the window, but cut off if the geometry doesn't cover it. Does anyone know why this could be?
@faizahmed4922
@faizahmed4922 4 жыл бұрын
I have also the same issue, can anyone help
@jimmykonings2127
@jimmykonings2127 4 жыл бұрын
I have this exact problem as well. Did you (or anyone else) find a solution for it already?
@jakobhyer2316
@jakobhyer2316 4 жыл бұрын
I know i am very late, but i fixed it by checking the VertexArray.cpp It turned out that i was resetting the offset every loop, so like this Bind(); vb.Bind(); const auto& elements = layout.GetElements(); for(int i = 0; i < elements.size(); i++) { const auto& element = elements[i]; unsigned int offset = 0; GLCall(glEnableVertexAttribArray(i)); GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (const void*)offset)); offset += element.count * VertexBufferElement::GetSizeOfType(element.type); } But it should be like this Bind(); vb.Bind(); const auto& elements = layout.GetElements(); unsigned int offset = 0; for(int i = 0; i < elements.size(); i++) { const auto& element = elements[i]; GLCall(glEnableVertexAttribArray(i)); GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (const void*)offset)); offset += element.count * VertexBufferElement::GetSizeOfType(element.type); }
@experimentators8699
@experimentators8699 4 жыл бұрын
@@jakobhyer2316 i tried this but it doesn't seem to work...
@Bolicubo
@Bolicubo 2 жыл бұрын
@@jakobhyer2316 you saved my life
@olavschioett4101
@olavschioett4101 Жыл бұрын
nice haircut, looking good
@__mk_km__
@__mk_km__ 6 жыл бұрын
Why not a good ol' pnglib for png decoding?
@zaca211
@zaca211 6 жыл бұрын
Just FYI. If anyone is getting a black screen after creating a PNG in GIMP. Try a different image. It seems to not like the image files exported with GIMP. Hope this helps someone.
@valrossenOliver
@valrossenOliver 6 жыл бұрын
Same with Krita. Export settings incorrect?
@afterlife1578
@afterlife1578 Жыл бұрын
If someone's getting a black screen and tried all the other solutions from the comments, mine was an embarrassing mistake, I miswrote the path to the image, so check if the full path is correct when calling the texture constructor.
@dr_mafarioyt4313
@dr_mafarioyt4313 6 ай бұрын
Im so glad this comment is here. Following the tutorial makes finding errors look pretty simple, and after making this mistake I now know why debugging OpenGL can be a pain sometimes. Really wish OpenGL gave *some* kind of error for messing up the path, but oh well Edit: For context, I named my image "Heh" but called it "Huh" in the file path. Dumb mistake and I shouldnt have named it that, but still
@JJnnaatt
@JJnnaatt 5 ай бұрын
I had the same error. I forgot the relative path is based on where the vcxproj file is, and not the source code. Thanks
@disgust_jpeg1871
@disgust_jpeg1871 3 жыл бұрын
Idk if i missed it or not but if your texture's not showing up try adding "glBindTexture(GL_TEXTURE_2D, m_RendererID)" in your Bind function for the texture class, fixed it for me
@justaskaulakis8202
@justaskaulakis8202 3 жыл бұрын
bruh what did u put before?
@disgust_jpeg1871
@disgust_jpeg1871 3 жыл бұрын
@@justaskaulakis8202 Idk probably nothing because i am brain dead
@siminho6929
@siminho6929 3 жыл бұрын
Hey Guys :) It seems that the code does not working in my case. I am always getting a white rectangle....I checked the Texture.cpp, the Shader file and also the glEnableVertexAttribArray(i). I also debugged the code and there is no error while reading the png-file and so on. Can someone help me?
@siminho6929
@siminho6929 3 жыл бұрын
Okay i found the problem after 2 hours of searching....In VertexArray.cpp the offset wasn't calculated correct, the element count was added with the size of type instead of multiplied... Maybe this helps someone :)
@rajasbondale6512
@rajasbondale6512 2 жыл бұрын
@@siminho6929 I am pretty sure you won't see this comment, but I'd like to give you a kiss
@theantonlulz
@theantonlulz 2 жыл бұрын
I'm just getting a black screen, I followed the code exactly and I'm getting nothing but "Warning: uniform 'u_Color' doesn't exist!", which goes away if I simply assign the color as we did before the texture. VS finds the image just fine, the buffer is not null, I even printed the dimensions of the image and they are correct, I have no idea where the problem could possibly be. Edit: fuck me, I'd gone over the video 3 times and didn't notice I called glBindTexture inside Texture::bind on 0 instead of m_RendererID.
@reimeytal2734
@reimeytal2734 3 жыл бұрын
Is the texture super dark for anyone else?
@Finkelfunk
@Finkelfunk Ай бұрын
"Hey what's up guys, I know this intro is confusing but I will make a detailed video explaining it - my name is the Cherno and I should probably make another video on why I am called Cherno. Anyway, today we are using OpenGL - which I really should be making a video about - to render a texture. Now I will make detailed videos about rendering and textures in the future so look out for those!"
@milo20060
@milo20060 Жыл бұрын
Hmm... Fragment shader failed to compile with the following errors: ERROR: 0:7: error(#132) Syntax error: "uniform" parse error
@Oaisus
@Oaisus 6 күн бұрын
I keep getting intimidated by how quickly he can type out code and then promptly remembering that I'm watching at 2x speed
@rubenbezuidenhout1493
@rubenbezuidenhout1493 6 жыл бұрын
Game engine series?
@mayankshigaonker7725
@mayankshigaonker7725 4 жыл бұрын
Hey could anybody help me. I a problem sort of. its that I have to declare my indecies as 0, 2, 4, 4, 6, 0 to get the proper image to be displayed. This is not a problem but just wanted to know why i have to do this rather than doing the normal thing which is 0, 1, 2, 2, 3, 0.
@zink10craft70
@zink10craft70 4 жыл бұрын
I think this is because of your vertex position format. I think you specified a type double the size of your actually wanted size, or somehow messed up when setting the values in the vertex buffer.
@themakabrapl2248
@themakabrapl2248 2 жыл бұрын
I had this problem and your comment really helped me, Thanks :D
@TGamingFull
@TGamingFull 6 жыл бұрын
I can't seem to load a PNG file into the program, when I load one file I get a total white mess with a few blue pixels. When I load another file I get an "Access violation reading location" error. I can't seem to figure out what I am doing wrong, I have checked that everything is typed correctly from this video.
@TGamingFull
@TGamingFull 6 жыл бұрын
Nevermind I figured out the problem, I had parsed a GL_UNSIGNED_INT instead of GL_UNSIGNED_BYTE in the glTexImage2D function, which resulted in some strange errors.
@giancedrick507
@giancedrick507 3 жыл бұрын
@@TGamingFull I was going to suggest setting your current working directory right in your IDE or build tool, but good job!
@giancedrick507
@giancedrick507 3 жыл бұрын
I recommend looking up the glsl specs and the OpenGL documentation thoroughly by example. learn a bit of calculus too 3blu1brown gotcha covered :)
@frosty7674
@frosty7674 2 жыл бұрын
Cherno: BEST programming laptop... Me sees price: *why does it even exist?*
Blending in OpenGL
12:37
The Cherno
Рет қаралды 65 М.
I made the same game in Assembly, C and C++
4:20
Nathan Baggs
Рет қаралды 627 М.
小路飞姐姐居然让路飞小路飞都消失了#海贼王  #路飞
00:47
路飞与唐舞桐
Рет қаралды 54 МЛН
The magical amulet of the cross! #clown #小丑 #shorts
00:54
好人小丑
Рет қаралды 21 МЛН
КИРПИЧ ОБ ГОЛОВУ #shorts
00:24
Паша Осадчий
Рет қаралды 6 МЛН
路飞关冰箱怎么关不上#海贼王 #路飞
00:12
路飞与唐舞桐
Рет қаралды 7 МЛН
I Rewrote This Entire Main File // Code Review
16:08
The Cherno
Рет қаралды 89 М.
I tried coding my own graphics engine
4:23
Garbaj
Рет қаралды 180 М.
Modern OpenGL Tutorial - Compute Shaders
11:27
Victor Gordan
Рет қаралды 52 М.
Textures in OpenGL | How to Code Minecraft Ep. 4
25:38
GamesWithGabe
Рет қаралды 94 М.
Creating Tests in OpenGL
22:46
The Cherno
Рет қаралды 39 М.
UNLIMITED textures in your Shaders! (OpenGL tutorial)
4:03
Low Level Game Dev
Рет қаралды 6 М.
小路飞姐姐居然让路飞小路飞都消失了#海贼王  #路飞
00:47
路飞与唐舞桐
Рет қаралды 54 МЛН