Textures in OpenGL

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 มิ.ย. 2024
  • 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

ความคิดเห็น • 352

  • @TheCherno
    @TheCherno  6 ปีที่แล้ว +132

    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 ปีที่แล้ว +2

      @@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 ปีที่แล้ว +252

    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

  • @ucmRich
    @ucmRich 6 ปีที่แล้ว +60

    Time=23:07="Detailed in-depth video on [how the rasterization works] and how [texture sampling works]"
    ^--Yes Plz 0:-)

  • @DanipBlog
    @DanipBlog 5 ปีที่แล้ว +9

    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))))

  • @DJNecktron
    @DJNecktron 3 ปีที่แล้ว +7

    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!

  • @cghost4yt
    @cghost4yt 3 ปีที่แล้ว +25

    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

  • @hiderr6805
    @hiderr6805 3 ปีที่แล้ว +5

    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

  • @diegosandoval2043
    @diegosandoval2043 4 ปีที่แล้ว +22

    Everyone: Drawing
    Cherno: Drawering

    • @heyyare86
      @heyyare86 4 ปีที่แล้ว +2

      I am not sure, it is like 'drawring'

    • @MGSncB
      @MGSncB 3 ปีที่แล้ว +2

      That's how a lot of Brits and Australians speak.

    • @weewoo3768
      @weewoo3768 2 ปีที่แล้ว +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

  • @Fobber92
    @Fobber92 6 ปีที่แล้ว +3

    great episode mate! love the long videos too!

  • @sebastianmestre2145
    @sebastianmestre2145 6 ปีที่แล้ว +19

    Your couch has the most cinematic lighting ever

  • @ekhalips6972
    @ekhalips6972 6 ปีที่แล้ว +7

    been searching for those kind of tutorials for 2 years, found Cherno few months ago, and learned so much, Thank You!

  • @aryesegal1988
    @aryesegal1988 6 ปีที่แล้ว +6

    Wow! a video half an hour long! NICEEE! :)
    Thanks, Cherno bruh!

  • @Micha-mj7vg
    @Micha-mj7vg 3 ปีที่แล้ว +29

    *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 ปีที่แล้ว +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 ปีที่แล้ว +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 9 หลายเดือนก่อน

      i had missing semicolons in shader files 😅

    • @theo-dr2dz
      @theo-dr2dz 8 หลายเดือนก่อน

      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 4 ปีที่แล้ว

    Fantastic content as usual! (Huge) Thanks for sharing your knowledge Yan! 🙌

  • @yannickmonjeamb3469
    @yannickmonjeamb3469 6 ปีที่แล้ว +26

    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.

  • @merle17
    @merle17 ปีที่แล้ว

    Worked right outta the box, amazing video.

  • @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!

  • @the_zed6098
    @the_zed6098 ปีที่แล้ว +21

    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 ปีที่แล้ว +3

      Woah, thanks. Would have never found that!

    • @olavschioett4101
      @olavschioett4101 ปีที่แล้ว +2

      thank you verry mouch i did the same thing

    • @quanta3968
      @quanta3968 ปีที่แล้ว +2

      u saved my life xd

    • @philip_love_you
      @philip_love_you ปีที่แล้ว +2

      Thanks bro, you saved my life. XD

    • @euvictorguedes
      @euvictorguedes 11 หลายเดือนก่อน +2

      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!

  • @hermysfancy9514
    @hermysfancy9514 3 ปีที่แล้ว +4

    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

  • @NoodleFlame
    @NoodleFlame 2 ปีที่แล้ว +2

    in the fragment shader you can multiply the color by the call to texture: vec4 texColor = texture(u_Texture, v_TexCoord) * u_Color;

  • @lucaaaa6382
    @lucaaaa6382 ปีที่แล้ว

    If I could like this a million times I would. You have effectively become my teacher.

  • @DBbombed
    @DBbombed 4 ปีที่แล้ว +6

    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.

  • @adamodimattia
    @adamodimattia 4 ปีที่แล้ว +18

    Wow, finally I thouroughly understood how texture sampling works exactly. You’re amazing man!

  • @theneuroware4057
    @theneuroware4057 2 ปีที่แล้ว

    Very good tutorial! Thx!

  • @YellCalum
    @YellCalum 6 ปีที่แล้ว +11

    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 ปีที่แล้ว +3

      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 ปีที่แล้ว +1

      @@koungmeng yah

    • @bluescanfly1981
      @bluescanfly1981 2 ปีที่แล้ว +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

  • @sssstupidkid1234
    @sssstupidkid1234 6 ปีที่แล้ว

    Hey TheCherno, this is a verry good video.. are you planning to create a video on UBOs?

  • @mathewmccloskey8242
    @mathewmccloskey8242 6 ปีที่แล้ว +106

    Has anyone made a list of all the promised episodes?

    • @XxAl3X3IxX
      @XxAl3X3IxX 6 ปีที่แล้ว +6

      About 20 promised videos just for this series

    • @Dodo17sky
      @Dodo17sky 6 ปีที่แล้ว +9

      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 ปีที่แล้ว +9

      "I promise one day I'll do an episode to make a list of all the promised episodes". Just kidding. This man rocks

  • @sjscurrell187
    @sjscurrell187 4 ปีที่แล้ว +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

  • @nikoszervo
    @nikoszervo 6 ปีที่แล้ว +2

    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

  • @JorneDeSmedt
    @JorneDeSmedt 6 ปีที่แล้ว +3

    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.

  • @iyappansriram9854
    @iyappansriram9854 3 ปีที่แล้ว +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 ปีที่แล้ว +1

      Thanks man, just recently had this issue.

    • @iyappansriram9854
      @iyappansriram9854 3 ปีที่แล้ว

      @@TheRealFFS you're welcome😊

  • @chinmayanand896
    @chinmayanand896 6 ปีที่แล้ว

    we like long videos dear....i always your confidence while you are telling something good.

  • @lisandroCT
    @lisandroCT 6 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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.

  • @thomasrouch3944
    @thomasrouch3944 3 ปีที่แล้ว +1

    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.

  • @anoomage
    @anoomage 8 หลายเดือนก่อน +1

    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.

  • @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.

  • @nguyenvietducbg
    @nguyenvietducbg ปีที่แล้ว +1

    BIG THANK!!!

  • @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?

  • @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.

  • @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?

  • @CharmingPotato14
    @CharmingPotato14 3 ปีที่แล้ว +1

    stbi_set_flip_vertically_on_load(1) fixed my problem where textures were loading upside down. Thank you so much!

  • @beachforestmountain4269
    @beachforestmountain4269 4 ปีที่แล้ว +3

    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.

  • @jtaimneas
    @jtaimneas 6 ปีที่แล้ว +17

    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 ปีที่แล้ว +3

      U can blend texture with u_color by multiplication. Example: frag_color = texture(tex, uv) * u_color;

    • @username17234
      @username17234 4 ปีที่แล้ว +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 ปีที่แล้ว +13

    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 9 หลายเดือนก่อน +2

      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

  • @ottaviarossini8020
    @ottaviarossini8020 3 ปีที่แล้ว +5

    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 ปีที่แล้ว +2

      Did you found a solution for this problem?
      I have trouble like since the last 4 hours with exactly this "bug"...

    • @tobiaspfatrisch3473
      @tobiaspfatrisch3473 3 ปีที่แล้ว +2

      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 ปีที่แล้ว +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 😳

  • @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?

  • @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?

  • @dogbreth7
    @dogbreth7 6 ปีที่แล้ว +1

    I think a video on the rasterization process would be really awesome!

  • @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

  • @ilyosbeknajmiddinov6754
    @ilyosbeknajmiddinov6754 2 ปีที่แล้ว +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

  • @yulozano4294
    @yulozano4294 5 ปีที่แล้ว +1

    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);

  • @testedpugtato9687
    @testedpugtato9687 ปีที่แล้ว +3

    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 หลายเดือนก่อน +1

      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 :)

  • @JustYesntMan
    @JustYesntMan 5 ปีที่แล้ว

    how to update my render sizes on window resize ? right now they are hard coded as you know

  • @TheTruock
    @TheTruock 2 ปีที่แล้ว +4

    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 ปีที่แล้ว +3

      you Sir,
      Are an angel

    • @johnraz99
      @johnraz99 ปีที่แล้ว +2

      Thank you!

  • @QIZI94
    @QIZI94 6 ปีที่แล้ว

    I think it would be better to make coordinates as uniforms, for example when you want to use it for sprites.

  • @fahdv2597
    @fahdv2597 6 ปีที่แล้ว

    I subscribed 4 seconds in the video

  • @darthvader8469
    @darthvader8469 4 ปีที่แล้ว +1

    Oyea. Alfin texturas :'3

  • @adrielbradley6677
    @adrielbradley6677 6 หลายเดือนก่อน

    I didn't enable blending, but my image came out fine, any idea why?

  • @GrandPoobah4
    @GrandPoobah4 6 ปีที่แล้ว +26

    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 ปีที่แล้ว +19

      Fixed it - in VertexArray.cpp, glEnableVertexAttribArray has to be called with "i". Looks like reading the docs does help!

    • @archcisero3049
      @archcisero3049 6 ปีที่แล้ว +1

      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!

  • @Ta5taturta5t3
    @Ta5taturta5t3 6 ปีที่แล้ว +2

    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?

  • @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!

  • @nielsdaemen
    @nielsdaemen 4 ปีที่แล้ว

    what about float textures for fluid simulation?

  • @ablender5750
    @ablender5750 5 ปีที่แล้ว +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 ปีที่แล้ว +5

      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

  • @zaca211
    @zaca211 6 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      Same with Krita. Export settings incorrect?

  • @kumu2024
    @kumu2024 6 หลายเดือนก่อน

    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.

  • @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.

  • @ressley1685
    @ressley1685 3 ปีที่แล้ว

    you are the best!

  • @siminho6929
    @siminho6929 3 ปีที่แล้ว +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 3 ปีที่แล้ว +5

      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 ปีที่แล้ว +3

      @@siminho6929 I am pretty sure you won't see this comment, but I'd like to give you a kiss

  • @TGamingFull
    @TGamingFull 6 ปีที่แล้ว +1

    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!

  • @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. :)

  • @Babaelow
    @Babaelow 5 ปีที่แล้ว

    What about ktx format? Is very easy to load too.

  • @nidalbizri
    @nidalbizri 4 ปีที่แล้ว +11

    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 ปีที่แล้ว +3

      Ig you didn't bind your shader before that

  • @iyappansriram9854
    @iyappansriram9854 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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

  • @mayankshigaonker7725
    @mayankshigaonker7725 4 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      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

  • @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.

  • @Oaisus
    @Oaisus 26 วันที่ผ่านมา

    I keep getting intimidated by how quickly he can type out code and then promptly remembering that I'm watching at 2x speed

  • @theashbot4097
    @theashbot4097 7 หลายเดือนก่อน

    What does v stand for? 26:30. Thank you!

  • @zlugio803
    @zlugio803 6 ปีที่แล้ว +2

    Hey Cherno, are you going to do a internet library series? Obviously for c++

    • @giancedrick507
      @giancedrick507 4 ปีที่แล้ว

      usually he specializes in graphics programming, but I would love someone to use boost

  • @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.

  • @frosty7674
    @frosty7674 2 ปีที่แล้ว +1

    Cherno: BEST programming laptop...
    Me sees price: *why does it even exist?*

  • @gower1973
    @gower1973 3 ปีที่แล้ว

    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 3 ปีที่แล้ว

      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

  • @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?

  • @imcnx1563
    @imcnx1563 3 ปีที่แล้ว

    What’s the difference between stb_image.h and stb_image_write.h?

  • @bies_moron4404
    @bies_moron4404 6 ปีที่แล้ว

    Nice

  • @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

  • @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

  • @Finkelfunk
    @Finkelfunk 2 หลายเดือนก่อน

    "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!"

  • @chrspinto
    @chrspinto 2 ปีที่แล้ว

    What version of OpenGL are you using?

  • @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.

  • @fluffycow19
    @fluffycow19 6 ปีที่แล้ว

    i love you.

  • @olavschioett4101
    @olavschioett4101 ปีที่แล้ว

    nice haircut, looking good

  • @deesrexcoding3564
    @deesrexcoding3564 3 ปีที่แล้ว +3

    Basically forgot the 'A' in RGBA annnnnnnd weirdest things start happening xDTook me like an hour finding a FREAKING 'A'!!!

    • @Cuito65
      @Cuito65 3 ปีที่แล้ว

      Dude! Thanks for that! I literally did the same exact thing!

  • @awuuwa
    @awuuwa 2 ปีที่แล้ว

    Make a tutorial on how to use bindless textures

  • @cieloabatido
    @cieloabatido 16 วันที่ผ่านมา

    it would be helpfull to have the code for all this project

  • @emanuelkokovics
    @emanuelkokovics 2 ปีที่แล้ว

    I tested the code with (.png, .jpg), it kinda works, only it renders a small left bottom corner of the image (no matter the type or size of the picture). Is it just the positions[] vector that needs to be adjusted? Also I still get, Warning: unfiorm 'u_Color' doesn't exist!

    • @BetaNegative
      @BetaNegative 2 ปีที่แล้ว

      I had the same problem. For me, in the vertex shader's main(), I forgot to add
      v_TexCoord = texCoord; at 26:40

  • @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 3 ปีที่แล้ว

      I'm having this same problem! Did you figure it out, by chance?

    • @MuscIeBomber2021
      @MuscIeBomber2021 3 ปีที่แล้ว

      Nvm, just figured it out. I'm dumb as hell lol

    • @antopilo7418
      @antopilo7418 3 ปีที่แล้ว

      @@MuscIeBomber2021 what was the solution

    • @MuscIeBomber2021
      @MuscIeBomber2021 3 ปีที่แล้ว +1

      @@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 3 ปีที่แล้ว +1

      @@MuscIeBomber2021 thanks I fixed it :)

  • @theantonlulz
    @theantonlulz 2 ปีที่แล้ว +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.

  • @rishimenon5632
    @rishimenon5632 4 ปีที่แล้ว +2

    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.

  • @gabrielguga7668
    @gabrielguga7668 4 ปีที่แล้ว +2

    What is the reason to separately create .h and .cpp files of the same class when you can just Add > Class?