Texture Loading in LWJGL3 | Coding a 2D Game Engine in Java #9

  Рет қаралды 19,331

GamesWithGabe

GamesWithGabe

Күн бұрын

Пікірлер: 80
@sai3
@sai3 3 жыл бұрын
Mybe we should call glActiveTexture(GL_TEXTURE0) first and then bind the texture?
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Yes, this is the correct way to do this, I have been correcting it in future videos, and I think I correct this in the render batching video :) Edit: I'm also pinning this for anyone watching this in the future
@lengors7327
@lengors7327 3 жыл бұрын
25:50 the "better" way to do that is to use the function "stbi_set_flip_vertically_on_load" before calling "stbi_load"
@LukaszWisniewskiWolfyDesign
@LukaszWisniewskiWolfyDesign 3 жыл бұрын
Hi Gabe awesome series. Just a note you can use stbi to flip the image verticaly before loading :) So before creating the buffer image you can say: stbi_set_flip_vertically_on_load(true); :D
@immanuelc885
@immanuelc885 3 жыл бұрын
I always wanted to learn how unity/godot/monogame etc. work now I know how complex, frustrating and fun it could be. PS I love u
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Haha thanks @Æ ! Yea I always wondered how Unity/Godot/Unreal worked too which is why I wanted to just start writing an engine and try to share what I learned with everyone :)
@rolpon2871
@rolpon2871 3 жыл бұрын
Great Tutorial! This helped me get texture loading down in lwjgl. Without you, I would spend lots of time looking for a clean and explained way for texture loading.
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Thanks Roblox Builders! I'm glad that the tutorial was able to help you out with textures. (To be honest they still confuse me a bit haha)
@brinklebros7136
@brinklebros7136 7 ай бұрын
im not even a 4th of the way through tis course and already my mind is blown. it would have taken me years to just do these 9 vids. it takes me about 2 days to wrap my head around just one. anyway finished number 9 with no hiccups this time.
@davidbergen9763
@davidbergen9763 4 жыл бұрын
I must have had a typo or "unseen character data" in the text field for the default.glsl file. So after copy and pasting your clean version, all is working well. thank you for a great series!
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
No problem David! And I'm glad you got it resolved pretty simply :D
@sai3
@sai3 3 жыл бұрын
Hey gabe, to deal with the problem that image is upside down, we can just call stbi_set_flip_vertically_on_load(true) before we call stbi_load() :D.
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Yea, this probably would have been the best solution haha
@pedrogabrielnogueira1068
@pedrogabrielnogueira1068 2 жыл бұрын
Dude, i love your channel
@alexandruantoci2691
@alexandruantoci2691 4 жыл бұрын
Nice video as always.
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Thanks Alexandru!
@basicallybrand
@basicallybrand 3 жыл бұрын
so much work just for a texture!
@Destroyer19941995
@Destroyer19941995 3 жыл бұрын
Really good tutorials
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Thanks :)
@lucasblotta9930
@lucasblotta9930 4 жыл бұрын
My png image was being displayed with black where alpha == 0. I added this to the end of LevelEditorScene.init() and it is now working. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Not sure if I've missed something in a previous video or how this is fixed afterwards
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Hey Lucas, that is totally fine and to be expected. In hindsight I probably should have mentioned that any images with alpha values would have this happen (and I tried to illustrate it a bit in the thumbnail), but I do cover blending in more depth in a future tutorial :)
@lastyhopper2792
@lastyhopper2792 2 жыл бұрын
yup, I'm pretty certain he didn't cover this transparency thingy here, since the image he was using is in jpg format.
@railroadOnTop
@railroadOnTop 2 жыл бұрын
my texture is still in the bottom left corner. what can i do? when i create new Camera(new Vector2f(-100,-100)); it fixes it but i dont think i should have negative values there
@luandkg
@luandkg 4 жыл бұрын
It's great !
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
:D
@ThePortugueseKnight
@ThePortugueseKnight Ай бұрын
Hey Gabe, i know this is not a recent video so maybe you don't remember it anymore, but as I've been following the series and trying to throw something together myself I noticed that in my IDE I don't get any of the code suggestions you get. I always have to fully type out all the methods and then they are recognized and imported. So my question is do you remember if you had to configure something different so you had those suggestions or if you remember ever encountering that problem at all? I definitely have suggestions on, the only things I don't get are lwjgl static methods, which are most of what I need here :(
@mwbgeometrydashpcaccount6372
@mwbgeometrydashpcaccount6372 2 жыл бұрын
When I test my image, I can still see it... BARELY! JUST THIS 1 LINE THINGY PART OF THE PICTURE!
@kian8770
@kian8770 3 жыл бұрын
When I run the program after following all of your steps, the java.exe returns -1073741819. I'm assuming this error is coming from C since GLFW is built with C. I've googled it and they told me to update my GPU drivers which I did and it is still returning the same thing. Now I'm assuming I did something wrong, do you know the solution to this?
@kian8770
@kian8770 3 жыл бұрын
Solved. I used the glVertexAttribPointer() twice with the same index.
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
@@kian8770 Nice! Sorry it took me so long to get back to you, but I'm glad you were able to resolve it. It can be very hard to debug these types of issues (I'm going through that right now haha)
@lordnarwhal
@lordnarwhal Жыл бұрын
yeeeesh... can someone let me know if this stuff gets simpler to work with later? i'm completely lost on all the glsl stuff. i don't really see it being feasible for me to work with this if it's this hard to just render an image. i don't understand it at all.
@Amitkumar-dv1kk
@Amitkumar-dv1kk 3 жыл бұрын
Mine is a just a black square and I have no idea why? Checked everything 3 times already, Just can't find anything.
@Tresla
@Tresla 3 жыл бұрын
When using VAOs, you don't need to call glEnableVertexAttribArray every time you render, only once when you initially set up the VAO. Calls to glEnableVertexAttribArray modify the state of the VAO object. So, all you need to do to render the VAO is bind it.
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Thanks Phil! I'll keep that in mind for future videos
@Tresla
@Tresla 3 жыл бұрын
@@GamesWithGabe also thanks for the videos, you've been real helpful :)
@JuddSamurai
@JuddSamurai 4 жыл бұрын
So I've been wanting to learn java for a while, and being someone who creates games with tkinter in python, this series has been amazing to to stumble across. And you channel in general. But I'm now lost, I understand the texturing and how it all works but it doesn't seem to want to work. I've checked your code against mine but to no avail. When ever I try to run it works fine however the texture doesn't, it seems to only be showing one colour from the texture, maybe just the one pixel of it. I then tried it with yours and it just appears white, probably the same thing happening. Do you know what is causing this and how it could potentially be fixed? I have messed around with alphas and stuff but that did nothing.
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Hey Judd! I'm glad the channel is helping you out! So your problem could lie in quite a few places, working with textures can be a pain haha. The first thing I would check is to make sure your shader is applying the proper texture coordinates. So instead of drawing the texture as the output color, do something like color = vec4(texCoords[0], texCoords[1], 0, 1) and see if that gives you the expected colors. If that's working correctly I would say make sure that if you're using an image with alpha, to use the open gl RGBA type, and if it has no alpha use RGB type. If the types match, I would say check out the actual data stb image is returning for the image, so make a completely white image and then make sure that you get a bunch of 255's back for the color. Let me know if any of this helps you out!
@JuddSamurai
@JuddSamurai 4 жыл бұрын
@@GamesWithGabe It didn't work with the coordinates but was still a colour from the texture so I messed around with the shader names and realised I was calling texcoords with different names. I changed it to be the same and it now works. Thank you though, as I though it was due to code elsewhere so that helped me on where to look.
@lucd9642
@lucd9642 3 жыл бұрын
Hi Gabe, great tutorial (thanks)! But I have a question. How would I make it so the image would be pixelperfect (so that it wouldn't stretch). When I take out the lines that make it stretch / shrink it only shows a black rectangle. Or will there be an easy/good way to do this once we abstract out the vertex array part?
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Hey Luc D! This is a good question (and something that's messed me up so many times haha), if you want the image to stretch you have to make sure to add glTextureParemeteri(GL_MAG_FILTER, GL_LINEAR) glTextureParemeteri(GL_MIN_FILTER, GL_LINEAR) to make it blurry or: glTextureParemeteri(GL_MAG_FILTER, GL_CLOSEST) glTextureParemeteri(GL_MIN_FILTER, GL_CLOSEST) to make it pixel perfect. I might have those gl calls slightly wrong, but you do need to set mag filter and min filter to stretch/shrink an image :)
@sihleebuthelezi9231
@sihleebuthelezi9231 3 жыл бұрын
Mine just uploaded the picture with blurry pixels, did I forget to remove something either than the noise in default.glsl?
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
This sounds like you have the texture uploaded with the parameter GL_TEXTURE_MAG_FILTER set to GL_LINEAR. If you find where you're loading textures, you can change the parameters to GL_NEAREST and that should make a picture become more pixelated as it gets magnified instead of getting blurry
@mirambikapatel5729
@mirambikapatel5729 2 жыл бұрын
i am having an error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.nio.ByteBuffer.position()" because "buffer" is null what should i do?
@YouTubeGetsWorseEveryUpdate
@YouTubeGetsWorseEveryUpdate Жыл бұрын
I had the same, problem for me was the path for the texture in LevelEditorScene was incorrect
@ade5324
@ade5324 Жыл бұрын
question: isn't it easier to render an image with directly manipulating pixels (if that's possible with modern day compters)
@ade5324
@ade5324 Жыл бұрын
turns out i can, its called software rendering.
@GamesWithGabe
@GamesWithGabe Жыл бұрын
Yep! And sometimes it's faster too, vector graphics is one area where GPU acceleration oftentimes is slower than CPU rendering. That's why most font libraries will rasterize the fonts (which are vector graphics) on the CPU. Same goes for SVG :)
@augischadiegils.5109
@augischadiegils.5109 4 жыл бұрын
Nice
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Thanks :D
@longschlong1095
@longschlong1095 4 жыл бұрын
When I try to upload my image it shows just a black square with a bit of color and when I try your image it stops working and crashes after 30 seconds. It only says that there was some error in main method. I guess I just made a typo somewhere.. Edit: I'm an idiot.. I forgot to change GL_RGBA to GL_RGB
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Hey Long I'm glad you got it solved! And don't worry I've done the same thing several times, and many similar things that have cost me way more time than I'd like to admit haha
@LawMasterTimmy
@LawMasterTimmy 3 жыл бұрын
Hello, I accidentally formatted my drive that had this very project, I had all the way to last episode. Do you have a github or something that has all the files that lead to last episode?
@GamesWithGabe
@GamesWithGabe 3 жыл бұрын
Oof, I've done that before! Every video has a link to the Github commit that contains the code up to that point, and this is the main Github link github.com/codingminecraft/MarioKZbin
@coldd721
@coldd721 2 жыл бұрын
Hello! I know this coment is years after the video release, but I was wondering if you needed to clear out the texture data from the GPU?
@GamesWithGabe
@GamesWithGabe 2 жыл бұрын
Hey Ultrasword! If you mean destroy the texture after you finish using it, then yes that is necessary. If you have some textures that you forgot to free, they will be automatically cleaned up once the program exits, but if you are switching to a new level or something you should definitely free it :)
@coldd721
@coldd721 2 жыл бұрын
@@GamesWithGabe ok Thanks!
@albertodent7920
@albertodent7920 4 жыл бұрын
I love your videos, but I'm having trouble with some of them because I'm using a Mac. I was able to figure out the VM settings on the last few videos, but I have no idea how to fix the error that is popping up now. It will not open the window 50% of the time, and it almost always prints out this message: Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. It seems to be failing to use the glTexImage2d function properly, and I have already changed RGB to RGBA and back. I've looked everywhere I can to figure out how to fix it, but I have no idea how. I know you don't use a mac, so you don't run into these issues, but if you know where I can look to figure these issues out, that would be awesome. Other than that I love your series though, you are a very thorough teacher!
@albertodent7920
@albertodent7920 4 жыл бұрын
Also, when it does load, the texture ends up upside down, and tiled and stretched at different lengths, so it definitely can access the image, and it's getting the colors right, so I don't know if there's something I'm missing on mac
@albertodent7920
@albertodent7920 4 жыл бұрын
Nevermind. I found how to fix it. You have to put: -Dsun.zip.disableMemoryMapping=true in the VM configurations
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
@@albertodent7920 Hey alberto sorry I wasn't able to help you out, but I'm glad you solved it! I'll keep this in mind in case anyone else runs into similar issues Also, if you run into more problems like this, it looks like this stack overflow thread has some helpful debugging techniques: stackoverflow.com/questions/51610420/deprecated-gradle-features-were-used-in-this-build-making-it-incompatible-with :)
@albertodent7920
@albertodent7920 4 жыл бұрын
@@GamesWithGabe Thanks!
@collinvoltz9381
@collinvoltz9381 2 жыл бұрын
Not to sound dumb, but do you need to add the image file directly to the IntelliJ file in order for it to be used?
@speedcuber7862
@speedcuber7862 Жыл бұрын
I have the same question so its a shame no one answered it :(
@Angle_KBe
@Angle_KBe Жыл бұрын
@@speedcuber7862 no you can just use the absolute path like C:\\user\\myimage.png
@allplaypixelatom3480
@allplaypixelatom3480 4 жыл бұрын
Project link but not GitHub pls
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
Hey @ALL PLAY PIXEL ATOM. Do you mean a link to like a JAR or something? I don't have that right now since the project is a WIP, I'll release one at the end of the series though :)
@allplaypixelatom3480
@allplaypixelatom3480 4 жыл бұрын
@@GamesWithGabe ok thanks can you make a video tutorial a but openGL ES 2.0 un native apps please sir
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
@@allplaypixelatom3480 I don't have any experience doing native apps with openGL ES yet, but if I do create some cross-platform apps using it in the future I will try and make videos about the process. It seems like it should be mostly similar to OpenGL, you just don't have all the functions that normal OpenGL provides
@allplaypixelatom3480
@allplaypixelatom3480 4 жыл бұрын
@@GamesWithGabe ok but you can find openGL ES on Android developer you can find some codes😊 and also thanks sir for replying me.
@GamesWithGabe
@GamesWithGabe 4 жыл бұрын
@@allplaypixelatom3480 no problem, and I'll try and check it out once I get some free time :)
@mwbgeometrydashpcaccount6372
@mwbgeometrydashpcaccount6372 3 жыл бұрын
you mistakenly spelled channels like channesl at 26:53
@liamandersson5462
@liamandersson5462 2 жыл бұрын
Okay, stop using asserts! Use logging instead. Asserts are not recommended for release!
Entity Component System | Coding a 2D Game Engine in Java #10
30:52
GamesWithGabe
Рет қаралды 28 М.
Texture Batching | Coding a 2D Game Engine in Java #13
33:40
GamesWithGabe
Рет қаралды 11 М.
Каха и лужа  #непосредственнокаха
00:15
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН
Ice Cream or Surprise Trip Around the World?
00:31
Hungry FAM
Рет қаралды 19 МЛН
Textures in OpenGL | How to Code Minecraft Ep. 4
25:38
GamesWithGabe
Рет қаралды 98 М.
How I animate 3Blue1Brown | A Manim demo with Ben Sparks
53:41
3Blue1Brown
Рет қаралды 1 МЛН
Batch Rendering in LWJGL3 | Coding a 2D Game Engine in Java #11
44:04
Making Minecraft from scratch in 48 hours (NO GAME ENGINE)
16:38
Resource Management in LWJGL3 | Coding a 2D Game Engine in Java #12
16:05
Game Camera OpenGL | Coding a 2D Game Engine in Java #7
23:48
GamesWithGabe
Рет қаралды 20 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
choosing a game engine is easy, actually
15:08
samyam
Рет қаралды 577 М.
Just enough assembly to blow your mind
29:31
Kay Lack
Рет қаралды 135 М.
Каха и лужа  #непосредственнокаха
00:15