Advice/Help on Using LWJGL to Make a 3D Game

Started by Type1Ninja, February 09, 2015, 21:39:20

Previous topic - Next topic

Type1Ninja

I'll cut right to the chase. A while ago, after making a 2D game using Java's Graphics 2D for rendering, I decided I was ready to make a game in 3D. I originally looked at Java 3D, but the tree graph and the process of manually posing a mesh using Java put me off (can you import blender files into lwjgl 3/OpenGL?). Eventually, I found lwjgl 3, but getting even a cube to show up is proving difficult (I'm using stable 3.0.0a - does that make a difference?). I have a basic understanding of OpenGL, but I have found very few helpful, up-to-date tutorials on lwjgl 3.
So, my question is: Should I downgrade to lwjgl 2, and follow the tutorials and examples for that, or should I stick with lwjgl 3? If I should stick with 3, how do I use it to render a cube using the recommended-and-not-deprecated OpenGL methods? Is there some other thing I should be using to do this? As a side note, are OpenGL rendering vertex coordinates relative to a static world origin, or are they relative to the viewer's position? Once I can render a single cube, or even a face of a cube, at specified world coordinates, I think I can do the rest of the game without any roadblocks as terrible as this one has been, but until that point, I am stuck.
One final piece of information which may be helpful is that my end goal with this whole 3D thing is to make a game with Minecraft-like worldgen and building. There are other, differentiating gameplay features of this, but that is the main reason I decided to stay away from game engines - after some research, they tend to lean towards static "levels" instead of procedurally generated terrain.

I think I have a basic understanding of lwjgl 3's example program that they posted under "get started" (http://www.lwjgl.org/guide). Advice on how to apply the "cube rendering" techniques to that piece of code would be very helpful.

Thanks in Advance,
      ~ Type1Ninja

Final Note: Should I be typing lwjgl in all caps, as in 'LWJGL,' or all lowercase, as in 'lwjgl'?

quew8

So the big difference between LWJGL2 and LWJGL3 is the window/context creation and handling stuff. LWJGL2 rolled it's own implementation whereas LWJGL3 uses the GLFW library. The OpenGL stuff where you actually render stuff is exactly the same.

So you can use that example code to create the window and follow any LWJGL2 tutorial to perform the rendering. In fact as it happens you can any OpenGL tutorial, whether they use LWJGL or are in another language entirely. In fact I recommend this one: http://arcsynthesis.org/gltut/ written for C. However, if you want something in Java written for LWJGL (and recently upgraded to LWJGL3) then here: http://goharsha.com/lwjgl-tutorial-series/ written by @SHC.

I believe that properly it is an acronym and so should be written in all capitals. I don't think anyone will complain if you don't. We're programmers, grammar is not our strong point (I apologize to all the programmers out there with impeccable grammar).

Type1Ninja

Thank you for the advice. I have seen both of those resources before, but I was not aware that tutorials for LWJGL 2 were applicable to LWJGL 3 in terms of rendering in OpenGL. I did know that OpenGL worked in every language, but, as a beginner, it is hard for me to translate C into Java.

So, I will reattempt the rendering of a square, rereading those tutorials. If it still doesn't work, I'll post again, perhaps next time posting my actual source code.
Thanks again! :D

Type1Ninja

Quote from: quew8 on February 10, 2015, 09:30:28
So the big difference between LWJGL2 and LWJGL3 is the window/context creation and handling stuff. LWJGL2 rolled it's own implementation whereas LWJGL3 uses the GLFW library. The OpenGL stuff where you actually render stuff is exactly the same.

So you can use that example code to create the window and follow any LWJGL2 tutorial to perform the rendering. In fact as it happens you can any OpenGL tutorial, whether they use LWJGL or are in another language entirely. In fact I recommend this one: http://arcsynthesis.org/gltut/ written for C. However, if you want something in Java written for LWJGL (and recently upgraded to LWJGL3) then here: http://goharsha.com/lwjgl-tutorial-series/ written by @SHC.

I believe that properly it is an acronym and so should be written in all capitals. I don't think anyone will complain if you don't. We're programmers, grammar is not our strong point (I apologize to all the programmers out there with impeccable grammar).

As I said, thank you for the previous help, but now I have more questions. :P
If I want to use LWGJL, do I need to write my own OpenGL shaders? Can I use somebody else's? If I can use other people's, where might I find them? Is there some major disadvantage to using other people's shaders? Is there any (non-deprecated) way to do this without writing shaders?
As before, thanks in advance for the help. :D

SHC

The only Non-Deprecated way of using OpenGL needs you to write shaders. If you don't want to do them, all you have to do is to use a library that does handle these for you, and in fact, finding such library is the first hard task, and instead, you can learn GLSL and use shaders which is the most easiest option. If you do still want to avoid them, I don't think you are ready for OpenGL, shaders in modern OpenGL are like the engine of a car. You can't start a car without it's engine, and you can render in OpenGL without shaders.

As a matter of self-promotion, I do aim to create a game engine that does that. It is called as SilenceEngine and it does what you want for a certain extent. You still need to understand how to specify vertices, colors, texture coordinates and pass them to my batcher. Currently, my engine handles collision detection, shape rendering, and model rendering with multiple materials and lights. Only thing for now is that it doesn't support animations.

But in my opinion, you should still read up on learning OpenGL, and you should learn GLSL (My engine uses default shaders, but you can specify if you want your own).

Cornix

I would suggest you have a look at libGDX, its a well known and well established java based engine that supports both 2D and 3D game creation.
It also handles context creation and resource management as well as cross platform support. Games created with libGDX can not only be started on desktop PC's but also on android tablets / phones as well as iOS devices.
libGDX even comes with a build in GUI library as far as I know.

Type1Ninja

Quote from: SHC on February 13, 2015, 08:33:36
The only Non-Deprecated way of using OpenGL needs you to write shaders. If you don't want to do them, all you have to do is to use a library that does handle these for you, and in fact, finding such library is the first hard task, and instead, you can learn GLSL and use shaders which is the most easiest option. If you do still want to avoid them, I don't think you are ready for OpenGL, shaders in modern OpenGL are like the engine of a car. You can't start a car without it's engine, and you can render in OpenGL without shaders.

As a matter of self-promotion, I do aim to create a game engine that does that. It is called as SilenceEngine and it does what you want for a certain extent. You still need to understand how to specify vertices, colors, texture coordinates and pass them to my batcher. Currently, my engine handles collision detection, shape rendering, and model rendering with multiple materials and lights. Only thing for now is that it doesn't support animations.

But in my opinion, you should still read up on learning OpenGL, and you should learn GLSL (My engine uses default shaders, but you can specify if you want your own).

Thanks for the response! I have just a few questions on it (as usual)...
If I wanted to make a game with your engine,  how would I do so? The other engines I've looked at have strange workings, with their own UIs and stuff... This is very confusing. That's part of why I wanted to stay away from game engines; they are very in depth in terms of development, but yours looks like what I want. :D I'm just not sure.
Also, you mentioned default shaders? Where would I find those, and how would I use them? At the moment, I don't want fancy effects; just very basic lighting + rendering a world (probably made of cubes...). The one thing I CAN do, after all, is specify vertices + colors + texture coordinates.
One last thing: What exactly do you mean by "doesn't support animation?" I can still have my 3D thingies move around, right? Can I pose 3D models, and/or import them from Blender (the 3D modeling software)?
Also, thanks for both the reply and the tutorial series; both have been very helpful. :D

Quote from: Cornix on February 13, 2015, 08:42:12
I would suggest you have a look at libGDX, its a well known and well established java based engine that supports both 2D and 3D game creation.
It also handles context creation and resource management as well as cross platform support. Games created with libGDX can not only be started on desktop PC's but also on android tablets / phones as well as iOS devices.
libGDX even comes with a build in GUI library as far as I know.
Thanks for the response; the reason I didn't look further into libGDX was the confusing and scary stuff about Android. It seemed like the focus was on Android as opposed to PC, which is not at all what I want. Plus, it seemed like it has its own UI, which isn't what I want; despite being a beginner, I like having lower level access to how my game works. The physics of games seems to be the only bit I can do with even adequate-ness; it's the 'game' part that I get stuck on. XD

Finally: It's been fantastic having other people give me answers instead of spending my weekend googling this stuff. That can be really depressing; this feels great. :D