Are there any tutorials or articles on how an efficient lighting system can be done in Java, using LWJGL?
As far as I know, LWJGL supports 8 or 11 lights (I can't remember without looking into the code) and I am interested in how this can be used to actually make a proper use of them, to easily distribute them in the world and manage the lights. Maybe there is a library for this?
I am also interested in any techniques to do shadows using LWJGL.
LWJGL essentially gives you a java binding for OpenGL. And the number of light sources supported varies between hardware. To find out, your program needs to get GL_MAX_LIGHTS:
int lights = GL11.glGetInteger(GL1.GL_MAX_LIGHTS);
If you want to look up articles on lighting in LWJGL, just look up articles that cover the same topic using OpenGL.
Remember you can use the OpenGL site to get better explanations of all of the various functions. Just ignore the C-specific parts.
Lighning and the amoung mapping technologies (normal mapping, shadow mapping) are one of the most complex graphic topics in terms of calculation, ...
There are several tutorials online.
One good tutorial is for example:
http://learnopengl.com/#!Advanced-Lighting/Advanced-Lighting
It is not LWJGL but this is also not important as you mostly use the Vertex, Fragment and Geometry shader for the rendering and I've you go through all of the tutorials you will get a very good overview of quit advanced graphic topics. Most of the C code can be shipped easily to LWJGL.
I don't recommend you the various youtube channels (thebennybox, thinmatrix) for learning opengl (lwjgl) as you will just type everything down line for line by their tutorials. Of course you will get from them a good overview how certain things are working but don't code your game based on the tutorials.
Some other sources:
Very intense lighning tutorial: http://www.falloutsoftware.com/tutorials/gl/gl8.htm
Related
As an Java developer, I recently had idea of learning OpenGL. I fully understand, that Java isn't best language for computer graphics, but as I just want to learn basics and concepts (and not writting Minecraft 2), I think it will do just fine.
I have started by searching in google and github for some "hello worlds" that uses JOGL (Java OpenGL). I was extremly supprised, that well above 85% of those "hello worlds" had about 100-500 lines of code (that I mostly do not understand just yet) and also, nearly none of them used Maven/Gradle dependency, which caused me must trouble with setting libraries (including native) properly (Using Linux, not sure if this is important).
I am really looking for some trivial example, like just add Maven/Gradle dependency, write simple JavaFX window, that displays OpenGL sphere, so I could focus on OpenGL instead of configuring everything.
There were few examples for Android, but I would like to run it on laptop (easier development).
Am I missing something? Where should I look for it?
I fully understand, that Java isn't best language for computer graphics
Well, it depends, each language has its pros and vs.
For example Java allows you to get a running program very quick, but you don't have full control on the memory like c/c++.
It doesn't take time to compile and can be run even when some part of the code are full of errors.
But is getting somehow verbose compared to some newer jvm languages, such as kotlin, scala or groovy.
I have started by searching in google and github for some "hello worlds" that uses JOGL (Java OpenGL). I was extremly supprised, that well above 85% of those "hello worlds" had about 100-500 lines of code
Well, that is because rendering is not as trivial as you thought.
However if you like to have core classes very compact you can eliminate a lot of boilerplate code by delegating laborious and manual work to util classes and get an hello triangle below a hundred lines.
For example in this hello triangle of mine. you can:
avoid many default calls to glWindow in the main method
save all the constant variables in a static class
avoid initDebug()
cut down in half initBuffers()
init your shader programs in one line by movind initProgram() to utils
nearly none of them used Maven/Gradle dependency, which caused me must trouble with setting libraries (including native)
I feel you, I really do.
And exactly because of this, I started two organization on github, one called java-graphic to be API neutral and another one called java-opengl-labs for everything related to jogamp, in order to address some major problems of us java devs and converge all our single effort into a unified place.
I wish also to have available plenty of modern tutorials, tools, libraries and whatever, all of them under Maven/Gradle dependency, one click and I get everything set it up and ready to be used.
When I started learning OpenGL the situation was much worse, I am trying to change it, but it is an huge effort.
There are a lot of things to do:
writing new counterparts tools (major are assimp and bullet)
improving existing code
implementing Maven/Gradle
writing wikis
improving channels communications
...
If you (or anyone who is reading) can contribute then please, do not hesitate do that, you are very welcome :)
I am really looking for some trivial example, like just add Maven/Gradle dependency, write simple JavaFX window, that displays OpenGL sphere, so I could focus on OpenGL instead of configuring everything.
The simplest you get, it that hello triangle I linked you. Unfortunately it has no Maven/Gradle dependency yet, but it relies only on pure jogl.
There were few examples for Android, but I would like to run it on laptop (easier development)
Since you are also mentioning Android (and somehow also verbosity previously), let me suggest you to take a look to Kotlin... I recently started digging into it and it is a whole new level compared to java, I also wrote a small hello triangle just as a pure style exercise
Try taking a look at the JogAmp wiki, and the demos with available source code.
JogAmp Wiki: http://jogamp.org/wiki/index.php/Main_Page
JogAmp Demos: http://jogamp.org/jogl-demos/www/
I would also suggest reading the OpenGL Redbook, this will introduce a lot of core OpenGL concepts, but is made for Version 1.1 of OpenGL, still a good read, but some practices will be outdated.
Lastly I'd recommend reading The OpenGL Programming Guide - 8th Edition. It's basically like the redbook but for modern OpenGL. Here's a link for it on Amazon
Code from the redbook and the OpenGL programming guide are going to be in pseudo code or C/C++, but the concepts and API calls are all the same between Java and C/C++. The only major differences will be in window creation, but that should be covered in the JogAmp demos and wiki.
EDIT: I just noticed there's a 9th edition of The OpenGL Programming Guide, you may want to read that instead, the 8th edition covers OpenGL 4.3, and the 9th edition covers 4.5.
Unfortunately you won't find any simple or trivial example. Learning OpenGL is a very large undertaking, and it won't happen overnight. Learning to configure your libraries, and the core concepts of the OpenGL API will help you a lot in the long run.
I've noticed that using the Java libraries that are default built in, rendering the simplest graphics absolutely kills the FPS, and furthermore, looks ugly.
Now I was wondering if I could use JOGL or LWJGL libraries to use in my pre-existing program. (I'm making a game which renders cubes as planets, and you have to build planets.) Do I need to completely rewrite my code? Or can I just install these and render freely? And which one of the above is easier to understand, because I have limited knowledge in these libraries.
Btw, right now, I am using JFrames, does that need to go as well?
Also, what is OpenGL, is that good to use as well without rewriting code?
OpenGL is a standardized graphics interface for use between programs and your graphics card. A proprietary version of this by Microsoft is known as DirectX. LWJGL and JOGL are two different Java bindings to OpenGL libraries, both of which have native code they load in.
LWJGL is much more aimed towards gaming with OpenGL, where as JOGL is more worried about complete and perfect bindings to OpenGL/OpenCL. I would recommend LWJGL if you're just getting started.
You're going to have to rewrite your rendering code, yes. But assuming you designed your project well, you shouldn't need to rewrite the game logic. JFrames will probably also have to go, but I'm not completely sure about that.
Please don't turn this question into another "JOGL vs LWJGL" thread. Moreover, JOGL is used in several games including Poxnora and Salem (MMO). You'll have to learn OpenGL if you want to use any Java binding of this API anyway.
Finally, you can use GLG2D in order to get a better hardware acceleration with plain Swing, it would allow you to benefit of better performance only with a very few changes in your program. GLG2D relies on JOGL 2, you can find more information about it here: http://brandonborkholder.github.io/glg2d/
I'm trying to design a side scroller for android and a level editor for windows. A lot of the code between the two programs will be the same. The bit I'm currently working on is drawing textures.
What I currently have is a library that includes code related to loading and drawing the texture information. The bit that I'm stuck on is how would I incorporate OpenGL (for windows) and OpenGL ES (for android) into the library?
I thought about having an interface that includes all the drawing functions and then implementing that interface separately within each program (since one will use OpenGL and one OpenGL ES) but that still produces a lot of duplicated code (and kinda defeats the purpose of trying to create this shared library).
Is there a better way to approach this problem? Am I just over complicating this by trying to make it too flexible? I have been thinking about this for a few sdays now, so any input would be greatly appreciated!
Please ask if anything doesn't make sense!
OpenGL and OpenGL-ES are similar enough, that you can share large amounts of the codebase. Since you're probably going to target OpenGL-ES-2, you will then probably use OpenGL-3 on the desktop. OpenGL-3 has a lot of what OpenGL-ES-2 has. So I suggest you develop your code primarily for OpenGL-ES-2 and then only for the small differences toward OpenGL-3 you add alternative codepaths.
Anybody have some experience with the graphical languages which is primarily designed for drawing? My question is about an alternative to AutoCAD and/or similar drawing software in terms of writing code to create the drawing. I couldn't find any of those types of languages if exists, primarily designed for as programming engineering drawings.
For example: I want to be able to create cylinders, rectangle, circles etc given the size and want to be able to manipulate those with adding, subtracting, extruding and so on...Also some annotation features would be great.
Update: As far as I have made my research, I think creating some engineering-drawing library atop of blender (which is itself a nice animating tool) might be great. Does somebody knows of anything that is in progress or already exists in this field?
The LaTeX world has long history of attempts to express line art diagrams in the document source code. The current favourite seems to be TikZ.
Examples
"3D" tagged examples
However, it falls somewhat short of providing full CSG (Constructive Solid Geometry) support.
If you do want 3D and CSG, POV-Ray lets you create objects and scenes by editing good old text-file sources (reference, examples). But on the other hand, POV-Ray won't generate engineering-style line drawings so far as I know.
With regard to your updated question: be aware that Blender already has a very nice Python API (and the ability to get a Python shell in the app) which lets you get at virtually all the Blender state and is probably the easiest way to implement extension plugins for procedural modelling, applying effects and import/export to other formats. Maybe it would work for "drawings" too. Whether it's useful also depends how important you regard the Java aspect; I'm not aware of a Java API but I have written C++ apps which exported models in the form of python code to be executed by Blender.
I'm not aware of anything that most people would recognise as a programming language which was primarily designed for CAD and similar applications. I would hazard a guess that most of the well known CAD packages (commercial and open-source) are written in Fortran, C or C++. sure, they may use something else for GUIs and such like, but the hard-core comp-geom stuff is going to be in a classic, compiled-for-speed, programming language.
There are languages (eg LOGO) which provide native support for drawing operations, but I'm not aware that any of these have been successfully used in published CAD systems.
It is not, though, a coincidence that many introductory texts on object-oriented programming take their examples from the domain of drawings and shapes -- you know, a Shape is the super-type of a Circle and of a Rectangle and of a Polygon; all of them implement the Draw method, and so on. The rise of OO is intimately tied up with the rise of graphical programs.
Finally, you might be interested in Processing.
Hi! For the last 3 months I managed to get a grasp of JSE (I have never done programming before, I only have a background of HTML/CSS and some jQuery but very little).
For my final exam this year I am going to have to create a project and I've decided on a strategy game. My professor recommended me to make it 3D on the OpenGL platform (the game is going to be based on RISK - most of you may have heard of this type of game as it used to be very popular). I have no idea where to start or what resources should I read not even for an 2D game not to mention a 3D one.
Can you guys post some resources with what steps I should I follow for creating a game in Java, books or any other advice that could help? Thank you.
The main OpenGL library for Java is:
JOGL
If you go in at the OpenGL level, as suggested by others, you will have to learn a lot about low level 3D concepts. Whilst this may not be a bad thing (a deep understanding of a topic is always beneficial) it may hinder progress and you have limited time.
The one advantage to OpenGL is that there is a lot more general information, especially tutorials (Google It!), available online.
For general OpenGL tutorials, the Nehe tutorials are a classic resource and contain source code in Java as well as a plethora of other languages.
Tutorials 1-5
Nehe tutorials index (linked on the right)
Alternatives to JOGL
I would recommend using one of the more prominent Java 3D engines that do a lot of the graphical leg work for you and will allow you to focus more on the game construction and less on overcoming basic obstacles like loading model formats, writing your own scene management code etc.
These are the good 3D engines that I know of:
LWJGL - Lightweight Java Game Library (documentation)
JMonkeyEngine (documentation, tutorials for beginners)
Ardor3D (documentation)
The documentation for JMonkeyEngine is much more suitable and contains many more tutorials, so I would start there. LWJGL is similarly well documented, but is also fairly low level and, in this way, similar to JOGL. Ardor3D could be a better alternative for those more comfortable with 3D programming in general.
Java Game Development Community
Whichever technology you chose, I suggest getting involved with the Java game development community as there's lots of example projects and people experienced with programming 3D games. The best place I know of is:
Java-Gaming.org