Textures in OpenGL

  Рет қаралды 175,103

The Cherno

The Cherno

Күн бұрын

Пікірлер: 365
@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 6 жыл бұрын
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 6 жыл бұрын
@@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 5 жыл бұрын
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 5 жыл бұрын
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 4 жыл бұрын
Hey man, you are the man.
@dawidlubczynski7502
@dawidlubczynski7502 4 жыл бұрын
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:-)
@DJNecktron
@DJNecktron 4 жыл бұрын
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!
@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))))
@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
@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
@hiderr6805
@hiderr6805 4 жыл бұрын
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
@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 4 жыл бұрын
You're right, dude! Png is tricky. Your words here helped me save tons of time.
@seba_mestre_ips
@seba_mestre_ips 6 жыл бұрын
Your couch has the most cinematic lighting ever
@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 3 жыл бұрын
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 3 жыл бұрын
Ha! knew it
@coopikoop
@coopikoop 2 жыл бұрын
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 Жыл бұрын
i had missing semicolons in shader files 😅
@theo-dr2dz
@theo-dr2dz Жыл бұрын
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.
@NoodleFlame
@NoodleFlame 3 жыл бұрын
in the fragment shader you can multiply the color by the call to texture: vec4 texColor = texture(u_Texture, v_TexCoord) * u_Color;
@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.
@ekhalips6972
@ekhalips6972 6 жыл бұрын
been searching for those kind of tutorials for 2 years, found Cherno few months ago, and learned so much, Thank You!
@Finkelfunk
@Finkelfunk 8 ай бұрын
"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!"
@the_zed6098
@the_zed6098 2 жыл бұрын
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 Жыл бұрын
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!
@diegosandoval2043
@diegosandoval2043 4 жыл бұрын
Everyone: Drawing Cherno: Drawering
@asarcagatay
@asarcagatay 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
@Kevin-f4h6l
@Kevin-f4h6l 8 ай бұрын
@@MGSncB *All Brits and Australians if they are not trying to sound American
@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.
@aryesegal1988
@aryesegal1988 6 жыл бұрын
Wow! a video half an hour long! NICEEE! :) Thanks, Cherno bruh!
@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 6 жыл бұрын
"I promise one day I'll do an episode to make a list of all the promised episodes". Just kidding. This man rocks
@Fobber92
@Fobber92 6 жыл бұрын
great episode mate! love the long videos too!
@MoMo-hh1zt
@MoMo-hh1zt 2 жыл бұрын
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!
@johnbarnhill386
@johnbarnhill386 6 ай бұрын
If your texture isn't showing, also make sure that your texCoord is being correctly sent to the fragment shader. You can test if its sampling from the texture at all by using an image that doesn't have the color at (0, 0) as black like I was doing
@lucaaaa6382
@lucaaaa6382 Жыл бұрын
If I could like this a million times I would. You have effectively become my teacher.
@merle17
@merle17 Жыл бұрын
Worked right outta the box, amazing video.
@adamodimattia
@adamodimattia 4 жыл бұрын
Wow, finally I thouroughly understood how texture sampling works exactly. You’re amazing man!
@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 6 жыл бұрын
Hot damn! Thanks dude!
@galenzhang3163
@galenzhang3163 5 жыл бұрын
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!
@iyappansriram9854
@iyappansriram9854 4 жыл бұрын
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 4 жыл бұрын
Thanks man, just recently had this issue.
@iyappansriram9854
@iyappansriram9854 4 жыл бұрын
@@TheRealFFS you're welcome😊
@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 5 жыл бұрын
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 4 жыл бұрын
last time I got this problem is cause I got glDraw parameters wrong
@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 2 жыл бұрын
Thank you! This worked for me.
@I_hate_HANDLES
@I_hate_HANDLES Жыл бұрын
thank you so much !! now i can go to eat junk food without worrying about the bug !! how
@osamaxz5720
@osamaxz5720 Ай бұрын
IDK if still someone watching this golden course but if your textures doesn't get rendered in the screen instead you got a black screen check the bind function specially the GLCall(glActiveTexture(GL_TEXTURE0 + slot)); I wrote it GLCall(glActiveTexture(GL_TEXTURE8 + slot)); by mistake so make sure to write GL_TEXTURE0 not GL_TEXTURE8
@TinoBurset
@TinoBurset 4 жыл бұрын
Fantastic content as usual! (Huge) Thanks for sharing your knowledge Yan! 🙌
@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_mafario
@Dr_mafario Жыл бұрын
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 Жыл бұрын
I had the same error. I forgot the relative path is based on where the vcxproj file is, and not the source code. Thanks
@ottaviarossini8020
@ottaviarossini8020 4 жыл бұрын
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 4 жыл бұрын
Did you found a solution for this problem? I have trouble like since the last 4 hours with exactly this "bug"...
@tobiaspfatrisch3473
@tobiaspfatrisch3473 4 жыл бұрын
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 😳
@yulozano4294
@yulozano4294 6 жыл бұрын
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);
@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.
@DragonBlazeXII
@DragonBlazeXII 9 ай бұрын
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.
@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 5 жыл бұрын
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 3 жыл бұрын
@@jakobhyer2316 you saved my life
@anoomage
@anoomage Жыл бұрын
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.
@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 Жыл бұрын
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 :)
@YagPatry
@YagPatry 4 ай бұрын
@@EECyrpys damn i really forgot a comma there, thanks man
@siminho6929
@siminho6929 4 жыл бұрын
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 4 жыл бұрын
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 3 жыл бұрын
@@siminho6929 I am pretty sure you won't see this comment, but I'd like to give you a kiss
@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
@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?
@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.
@thomasrouch3944
@thomasrouch3944 4 жыл бұрын
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.
@cili7800
@cili7800 4 ай бұрын
If you are getting a black screen, a good source of debugging might be the stbi_load function inside the Texture.cpp file. In my case, the problem was that it couldn't load the picture, even though vs saw it as a png file. had to run it through paint and save it in order to be usable.
@Cabre94
@Cabre94 2 ай бұрын
te amo loko
@nidalbizri
@nidalbizri 4 жыл бұрын
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 4 жыл бұрын
Ig you didn't bind your shader before that
@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 6 жыл бұрын
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 5 жыл бұрын
@@sizzlebae2060 is that Chitoge?
@sizzlebae2060
@sizzlebae2060 5 жыл бұрын
@@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
@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 3 жыл бұрын
I had this problem and your comment really helped me, Thanks :D
@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 2 жыл бұрын
you Sir, Are an angel
@johnraz99
@johnraz99 Жыл бұрын
Thank you!
@CharmingPotato14
@CharmingPotato14 4 жыл бұрын
stbi_set_flip_vertically_on_load(1) fixed my problem where textures were loading upside down. Thank you so much!
@theashbot4097
@theashbot4097 Жыл бұрын
What does v stand for? 26:30. Thank you!
@rishimenon5632
@rishimenon5632 4 жыл бұрын
26:50 The vertex shader runs 4 times because we have 4 vertices, so 4 coordinates are going 'out' of the vertex shader. But the fragment shader gets called for every single pixel. So what value is stored in the v_TexCoord inside the fragment shader ? (i mean which out of the four possible values). Im guessing the value will change obviously so when does the value change ?
@ed_iz_ed
@ed_iz_ed 4 жыл бұрын
Each fragment gets the interpolated values from the vertex shader, so the fragment in the middle gets the average of all values for example.
@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 4 жыл бұрын
usually before you go into matrices and animations, you have to do some math
@MaraisStephane
@MaraisStephane 6 жыл бұрын
So I had a bit of an issue here. Depending of the editor I was using (CLion or VS) I have different complaints with different issues but all related to the same point. On CLion my program was complaining about u_Color, not existing and on VS u_Texture was not existing. My code was matching 100% with Cherno's one. Turned out you NEED to remove shader.SetUniform4f("u_Color", ...); in order to have it working with no errors (you also need to remove the uniform vec4 u_Color; in the Basic.shader file. We are not using it anyway for now. if anyone knows why we can't have multiple uniforms at this stage, I'd really know why.
@jialeichen9506
@jialeichen9506 6 жыл бұрын
The compiler will optimize and get rid of the unused uniforms, so in this case u_Color doesn't really exist at run-time.
@MaraisStephane
@MaraisStephane 6 жыл бұрын
@@jialeichen9506 sure but why would an unused uniform prevent the code from being properly displayed?
@jialeichen9506
@jialeichen9506 6 жыл бұрын
@@MaraisStephane I'm not sure if this is answering your question but if you just leave the uniform unused in the shader, it wouldn't (I experimented with it a bit) prevent the code from properly rendering. However, if you still assign the output color of your frag shader to color = u_Color then it would be an error. (It might or might not be your issue, but that's as far as I know :)
@NotNazuh
@NotNazuh Жыл бұрын
If your having a problem where your texture is renderering but displaced, go back to VertexArray.cpp, head into AddBuffer and when you call GLCALL(glVertexAttribPointer()); change the last parameter in glVertexAttribPointer() to (const void*)offset. ex: GLCALL(glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (const void*)offset));
@YmanYoutube
@YmanYoutube 11 ай бұрын
OH my god thank you bro you saved my life! Do you have an idea why this causes a problem?
@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?
@cloudirs5
@cloudirs5 3 ай бұрын
For some reason I have to set the filepaths to include "OpenGLTutorial/res/shaders" or "OpenGLTutorial/res/textures" in order for it to work.
@Byynx
@Byynx Жыл бұрын
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.
@eggmeister6641
@eggmeister6641 3 жыл бұрын
screen black. how to fix?
@theantonlulz
@theantonlulz 3 жыл бұрын
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.
@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.
@sjscurrell187
@sjscurrell187 4 жыл бұрын
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 Жыл бұрын
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
@kumu2024
@kumu2024 Жыл бұрын
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.
@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 4 жыл бұрын
@@TGamingFull I was going to suggest setting your current working directory right in your IDE or build tool, but good job!
@sv2670
@sv2670 6 ай бұрын
Hey there! I'm on mac and cannot make this code work (black screen, error 1282 from the Draw function). I commented all the code in main and shader from this class and it works well, but adding the exact same code and gettting this error, has anybody have this issue?
@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?
@adrielbradley6677
@adrielbradley6677 Жыл бұрын
I didn't enable blending, but my image came out fine, any idea why?
@vijaylamkane5619
@vijaylamkane5619 4 жыл бұрын
I want to get image from X-ray scanner Data and display it using OpenGL windows in c# how can I achieve this
@giancedrick507
@giancedrick507 4 жыл бұрын
you have to deal with the x-ray scanner API yourself, convert the video/photo format with some library like FFmpeg, and finally display pixel data with OpenGL. I thought of this on the spot but the idea seems okay. :)
@theneuroware4057
@theneuroware4057 3 жыл бұрын
Very good tutorial! Thx!
@nickkane-dev
@nickkane-dev 4 жыл бұрын
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
@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!
@Levendo
@Levendo 4 жыл бұрын
I'm doing this on a mac, and I keep getting a black screen. -I checked everything. The code is literally the same. I wonder why it's not working. Is it because the png file I'm using isn't compatible with the library? Where can I find an image that works with this program?- Edit: found the reason. I accidentally set glBindTexture to 0 instead of m_RendererID :p
@BlackKillerGamer
@BlackKillerGamer 3 жыл бұрын
he actually wrote it with a 0 in the Texture constructor tho I had the same problem, changed it to m_RendererID and it worked
@kinochdotcom
@kinochdotcom 3 жыл бұрын
Doing a lot of debugging, I never found a time when m_RendererID was not 0, because we only ever make 1 instance of the Texture class. Found this doing some m_slot debugging. My problem was. I called glBindTexture() twice by mistake adding code to check if m_LocalBuffer actually was loading the image into memory.
@frosty7674
@frosty7674 3 жыл бұрын
Cherno: BEST programming laptop... Me sees price: *why does it even exist?*
@gower1973
@gower1973 4 жыл бұрын
My program compiles but no picture when it runs, if you look at the window behind its saying failed to compile the fragment shader even though its written exactly the same as Chernos, I get error C1060 incompatible type, C1056 invalid something, C0000 token color expecting , or ;
@gower1973
@gower1973 4 жыл бұрын
Nevermind I fixed it one line wasn`t written correctly in the fragment shader, I missed he had texture as a type and a variable name in the texColor line
@yavuzselimcagan5233
@yavuzselimcagan5233 2 жыл бұрын
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?
@iyappansriram9854
@iyappansriram9854 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
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
@disgust_jpeg1871
@disgust_jpeg1871 4 жыл бұрын
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
@stormsoendergaard3023
@stormsoendergaard3023 4 жыл бұрын
Can anyone explain to me why my texture is flipped by default, the stbi_set_flip_vertically_on_load(1); call flips it the wrong way?
@thatKurtis
@thatKurtis 4 жыл бұрын
You could have used a different file format or you made a slight "mistake" somewhere like flipping your verticies
@stormsoendergaard3023
@stormsoendergaard3023 4 жыл бұрын
@@thatKurtis I was flipping my vertices, thx
@thatKurtis
@thatKurtis 4 жыл бұрын
@@stormsoendergaard3023 I am shocked my poor explanation managed to help you
@ben-nh9sn
@ben-nh9sn 6 ай бұрын
14:25 "this is... this is..." had me weak
@chinmayanand896
@chinmayanand896 6 жыл бұрын
we like long videos dear....i always your confidence while you are telling something good.
@jangronowski8180
@jangronowski8180 4 жыл бұрын
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.
@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 Жыл бұрын
Did you ever find an answer to this?
@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?
@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.
@czdiejengco
@czdiejengco 5 ай бұрын
Can someone please explain to me what this called and what it does actually function(...) : something(something), something(something) {}
@puneethreddyk7975
@puneethreddyk7975 4 ай бұрын
This is called an initializer list.Basically it initializes the data members of a class.
@jasonbrown5752
@jasonbrown5752 4 жыл бұрын
Any reason why image would be distorted along a diagonal line corner to corner b-left to t-right? all code works to this point and it isn't an issue in the image file.
@MuscIeBomber2021
@MuscIeBomber2021 4 жыл бұрын
I'm having this same problem! Did you figure it out, by chance?
@MuscIeBomber2021
@MuscIeBomber2021 4 жыл бұрын
Nvm, just figured it out. I'm dumb as hell lol
@antopilo7418
@antopilo7418 4 жыл бұрын
@@MuscIeBomber2021 what was the solution
@MuscIeBomber2021
@MuscIeBomber2021 4 жыл бұрын
@@antopilo7418 I don't remember the exact situation anymore, but if your texture is distorted, it's most likely because your index buffer is incorrect.
@antopilo7418
@antopilo7418 4 жыл бұрын
@@MuscIeBomber2021 thanks I fixed it :)
@robtroman818
@robtroman818 6 жыл бұрын
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
@padonmurdock8576
@padonmurdock8576 4 ай бұрын
If you are copying the file path of your image and pasting into your program you will have backslashes in your file path "\" which is a line end in C++ change them to forward slashes "/" and you image should load properly.
@JustYesntMan
@JustYesntMan 5 жыл бұрын
how to update my render sizes on window resize ? right now they are hard coded as you know
@emanuelkokovics
@emanuelkokovics 3 жыл бұрын
No matter how I change positions[], it still seems to render just one small portion of the image (small part of bottom left corner). Any ideas, anyone, why? Any suggestions on how to solve this? So I tried another picture, and it seems like my canvas is divided into 4 small rectangles, and the picture is drawn on the right top one (well just a part of the picture (the left bottom corner)). It seems to not even matter what I put in the positions[] array! :(
@batuhanyigit4342
@batuhanyigit4342 3 жыл бұрын
I'm having the same problem here I can't seem to figure out why
@xardas4511
@xardas4511 2 жыл бұрын
I found a small solution. But it is not perfect. If you change the order of the position vales. (so firstly the texture coordinate and after 2 position coordinate). After that, I see the full image in the window top right (instead of the middle)
@xardas4511
@xardas4511 2 жыл бұрын
I found the solution. my error was in the shader. The location of texCoord should be 1 instead of 0. So the good result: layout(location = 0) in vec4 position; layout(location = 1) in vec2 texCoord;
@danielkrajnik3817
@danielkrajnik3817 4 жыл бұрын
10:52 the only correct origin point
@imcnx1563
@imcnx1563 3 жыл бұрын
What’s the difference between stb_image.h and stb_image_write.h?
@milo20060
@milo20060 2 жыл бұрын
Hmm... Fragment shader failed to compile with the following errors: ERROR: 0:7: error(#132) Syntax error: "uniform" parse error
@GamerCreativo2024
@GamerCreativo2024 5 жыл бұрын
I got a big memory leak, I don't know if in some part is necessary to unbind the texture, someone knows?
@evandrorodrigues7091
@evandrorodrigues7091 4 жыл бұрын
I'm getting the warning from Shader.cpp: "Warning: uniform 'u_Color' doesn't exist!" But everything seems to be working and texture displayed correctly, any ideas?
@Unifrog_
@Unifrog_ 4 жыл бұрын
I got this too. It goes away if you remove the uniform and dont set it in your program (since you are now getting the color from the texture) or if you use the uniform in the calculation of the color. Apparently the fragment shader compiler optimizes away uniforms that are declared but not used so you can no longer set them but otherwise the shader still works.
@imankalyanmaity
@imankalyanmaity 5 жыл бұрын
Though it's working, I'm getting 1 error: 'ERROR::uniformu_Colordoesn't exist'. And I had to give the absolute image path, the relative path didn't work. ... can anybody tell me why?
@JohnnyGintonic
@JohnnyGintonic 5 жыл бұрын
same here
@9y028
@9y028 5 жыл бұрын
Not sure but I think it is because u_Color isn't used in the fragment shader since we're getting the color from the texture. The compiler probably removes that uniform because it is unused or something. It's nothing to worry about
@mariovelez578
@mariovelez578 3 жыл бұрын
I get a breakpoint here: GLCall(glAttachShader(program, fs)); Anyone know how to fix it? thanks
@michaelbuckingham4030
@michaelbuckingham4030 3 жыл бұрын
Hey, I have the same issue. Did you ever manage to solve the problem?
@masterjj1
@masterjj1 3 жыл бұрын
I also have this issue
@masterjj1
@masterjj1 3 жыл бұрын
Just figured my error out. Turns out I forgot 2 semi colons inside of Basic.shader
@mariovelez578
@mariovelez578 3 жыл бұрын
@@masterjj1 Thanks I'll check it out
@nielsdaemen
@nielsdaemen 4 жыл бұрын
what about float textures for fluid simulation?
@cieloabatido
@cieloabatido 7 ай бұрын
it would be helpfull to have the code for all this project
@imankalyanmaity
@imankalyanmaity 5 жыл бұрын
No error, no warning, still getting a black screen, before and after the blending. 🤷‍♀️
@bidkonic
@bidkonic 5 жыл бұрын
It could be because you don't bind the texture?
@giancedrick507
@giancedrick507 4 жыл бұрын
@@bidkonic this is c++, it could be anything
@bayemil
@bayemil 4 жыл бұрын
are you solved problem?
@imankalyanmaity
@imankalyanmaity 4 жыл бұрын
@@bayemil yes, but forgot how!
@bayemil
@bayemil 4 жыл бұрын
@@imankalyanmaity oh ffff
Blending in OpenGL
12:37
The Cherno
Рет қаралды 69 М.
How Shaders Work in OpenGL
17:37
The Cherno
Рет қаралды 236 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
TEXTURES | Game Engine series
51:48
The Cherno
Рет қаралды 43 М.
Shader Abstraction in OpenGL
21:56
The Cherno
Рет қаралды 78 М.
Базовый курс C++ (MIPT, ILab). Lecture 14 (доп). OpenGL и Vulkan
2:01:58
Textures in OpenGL | How to Code Minecraft Ep. 4
25:38
GamesWithGabe
Рет қаралды 98 М.
I made it FASTER // Code Review
38:46
The Cherno
Рет қаралды 551 М.
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 160 М.
The Math of Computer Graphics - TEXTURES and SAMPLERS
16:59
FloatyMonkey
Рет қаралды 24 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 760 М.
Factorio teaches you software engineering, seriously.
21:27
Tony Zhu
Рет қаралды 2 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН