A few beginner lwjgl questions

Started by 8Keep, June 23, 2012, 23:56:56

Previous topic - Next topic

8Keep

I am new to lwjgl, and java. I am fluent in c# and game development for around 4 years now.

I have some questions though:

1. I want to use lwjgl and slick-util libraries, unless I need the full slick for some questions I have later on.
Bitmap fonts. I know about ttf fonts, but how can I load a .png and turn it into a font that can be used to draw strings?

2. I want to use spritesheets, how can I draw only a section of a texture, I think I have seen something like this with openGL in the past.

3. How can I load textures and other things such as xml and the bitmap font (above) from outside the project? When I distribute my game I want to be able to just distribute a .zip file with everything in it, the lib and natives folder, the .exe or .jar, and a "resources: folder that will have all the game data in it like graphics, so players can make their own graphics if they want to.

4. How can I load xml files? Does java have build in xml classes like c# or do I use a library?

5. I want to make a TextureRenderer static class with a draw method that will take these parameters:

public static void draw(Texture texture, int x, int y, Rectangle sourcerectangle, float rotation, Color color)

The sourcerectangle will be a rectangle of what part of the texture to draw, the rotation is oobviously rotation, and the color will be a class for drawing an image in a color.

Is this possible? I am coming from xna, so I'm not used to opengl so this would be a lot easier for me.

6. Actually installing eclipse and java. I just downloaded the jdk 1.6 version from the website and put the variable to the bin folder in the "PATH" system variable, I have windows 7. I installed the eclipse version that had the most downloads, it was this one: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr2 and I installed the 64 bit one. Is that the right one?

I downloaded lwjgl and the slick-util zip folders.
This is how I make a new project, is this right?
Make a new folder in documents folder on my computer called "My Java Game"
Open eclipse and set workspace to that folder.
Make a new java project.
Go to the folder and make a folder called "lib"
Where i downloaded lwjgl, go to lwjgl-2.8.4\lwjgl-2.8.4\jar folder and put jinput.jar, lwjgl.jar and lwjgl-util.jar into the lib folder.
Same as above but for the slick-util folder i put jogg-0.0.7.jar, jorbis-0.0.15.jar slick-util.jar into the lib folder in "My Java Game" folder. I noticed the slick-util folder also has a lwjgl.jar in it, do I put that in there as well (it will replace the other one from when I downloaded lwjgl from lwjgl.org) They are different sizes, so they are obviously different .jars.
Then when i downloaded lwjgl go into the natives folder and copy all the windows dlls into my natives folder in my bin folder. What do I do with all the files from the other OS's in lwjgl?
After all that I open up eclipse again and in the workspace in the new java project i right click and hit properties and add the slick-util and lwjgl and lwjgl-util and jinput .jars to the libraries thing.

7. Should I use the java 7 or java 6? How do I choose which one the game will need? What is the difference between the jdk and jre?

8. How would I do a 2d camera?

9. I know this is an opengl question, but what do glMatrixMode and glShadeModel do?

10. About the lib folder and natives folder, is it possible to have one download for all OS's and have separate folders for windows/linux/macosx/solaris and in code or something use a different one depending on which OS the current system is?



Yea, thats a lot to read and a lot of questions, if anyone knows the answers to any of them it would help out a lot :)

Daslee

4. User JDom library for reading and writing xml's.

6. For this one how to setup project I think you can find in youtube. But anyway here is how you must setup:
Open eclipse, set workspace
Click File>New>Java Project
Name it and click finish
Go to your workspace folder and then go inside project folder, there create lib folder. In lib folder create 2 folders: jars and natives
In jars folders put: lwjgl.jar, lwjgl_util.jar from LWJGL you downloaded. And put slick-util.jar from Slick
Now go to natives folder and here put all .dll files from downloaded LWJGL/native/windows
In eclipse right click on your project in package explorer and click Properties
In Properties window right side click Java Build Path and choose Libraries tab.
Click Add JARs, then expand your project/lib/jars folder and add all .jar files
When you added, you must see that added .jar files in Properties window, so expand lwjgl.jar
Click on "Native library location: " and in right side of Properties window click "Edit..."
And now select your project folder in workspace and then lib/natives folder for example:
"C:\Users\USER\Documents\workspace\LWJGL Game\lib\natives"

And you're done

7. I actually do not know which version you should use, but I have both 6 and 7. JDK - Java Development Kit needed for developing Java applications. JRE - Java Runtime Environment needed to run java application (I think).

8. You should look here: http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_1_(The_Display) I started developing my game 3D game from this code, only 31 lines and now my code is almost 600 lines, and others classes in my project have much lines but I didn't count them.

9. Quote from google:
glMatrixMode â€" specify which matrix is the current matrix (http://www.opengl.org/sdk/docs/man/xhtml/glMatrixMode.xml)
glShadeModel â€" select flat or smooth shading (http://www.opengl.org/sdk/docs/man/xhtml/glShadeModel.xml)

Sorry for my bad English.  :-\

CodeBunny

In regards to #6 and #10: I've made a jar file that includes all the LWJGL jars and natives, and has a 1-line call that:

  • extracts the appropriate native files from within the jar, and places them in the "application directory" directory of the appropriate operating system
  • Sets the library path property of the JVM, allowing lwjgl to be loaded from that location.

All you have to do is call that one line and LWJGL is automatically loaded, and you can start calling Display.create(), etc. If the libraries are already at the given location, it doesn't waste time re-extracting them, and the library path is set immediately and the game can start immediately.

This allows you to do a couple of things:

  • Easily integrate LWJGL in all your products (you just include the jar and call it).
  • Not worry about "installation" or launching your program with command-line flags; everything the program needs is coded into it, so it can be launched like a regular jar file. Just get the file to a user and it works when he runs it.
  • Share a "native file cache" between all your LWJGL applications. If you include the jar file with multiple projects, it tries to use the same directory for each one, resulting in the minumum of files on the user's computer.
  • Easily upgrade your LWJGL version: I create updated versions of the library for each major release of LWJGL, and all you have to do is replace the jar. The native files for separate versions are kept separate, so programs using the 2.8.4 version are independent from those using 2.8.3.

Do you want a copy? Sorry if I'm pushing this too hard, but it's made my life a lot easier and I really like how manages deployment.

8Keep

Quote from: Daslee on June 24, 2012, 08:47:52
4. User JDom library for reading and writing xml's.

6. For this one how to setup project I think you can find in youtube. But anyway here is how you must setup:
Open eclipse, set workspace
Click File>New>Java Project
Name it and click finish
Go to your workspace folder and then go inside project folder, there create lib folder. In lib folder create 2 folders: jars and natives
In jars folders put: lwjgl.jar, lwjgl_util.jar from LWJGL you downloaded. And put slick-util.jar from Slick
Now go to natives folder and here put all .dll files from downloaded LWJGL/native/windows
In eclipse right click on your project in package explorer and click Properties
In Properties window right side click Java Build Path and choose Libraries tab.
Click Add JARs, then expand your project/lib/jars folder and add all .jar files
When you added, you must see that added .jar files in Properties window, so expand lwjgl.jar
Click on "Native library location: " and in right side of Properties window click "Edit..."
And now select your project folder in workspace and then lib/natives folder for example:
"C:\Users\USER\Documents\workspace\LWJGL Game\lib\natives"

And you're done

7. I actually do not know which version you should use, but I have both 6 and 7. JDK - Java Development Kit needed for developing Java applications. JRE - Java Runtime Environment needed to run java application (I think).

8. You should look here: http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_1_(The_Display) I started developing my game 3D game from this code, only 31 lines and now my code is almost 600 lines, and others classes in my project have much lines but I didn't count them.

9. Quote from google:
glMatrixMode â€" specify which matrix is the current matrix (http://www.opengl.org/sdk/docs/man/xhtml/glMatrixMode.xml)
glShadeModel â€" select flat or smooth shading (http://www.opengl.org/sdk/docs/man/xhtml/glShadeModel.xml)

Sorry for my bad English.  :-\


Thank you! But what is the lwjgl.jar in the slick-util zip for? It is different from the one in the official lwjgl, it is a different sized file.
Does anyone else know if I should use java 7 or 6, do most people now have java 7 so its safe to use it?
In your answer for number 8 the last parenthesis is outside the link, but i got it and thank you.
Now I sort of understand the opengl methods, but I dont really get what each matrixmode does and when to use them.
Your English is not bad at all.

8Keep

Quote from: CodeBunny on June 24, 2012, 13:21:09
In regards to #6 and #10: I've made a jar file that includes all the LWJGL jars and natives, and has a 1-line call that:

  • extracts the appropriate native files from within the jar, and places them in the "application directory" directory of the appropriate operating system
  • Sets the library path property of the JVM, allowing lwjgl to be loaded from that location.

All you have to do is call that one line and LWJGL is automatically loaded, and you can start calling Display.create(), etc. If the libraries are already at the given location, it doesn't waste time re-extracting them, and the library path is set immediately and the game can start immediately.

This allows you to do a couple of things:

  • Easily integrate LWJGL in all your products (you just include the jar and call it).
  • Not worry about "installation" or launching your program with command-line flags; everything the program needs is coded into it, so it can be launched like a regular jar file. Just get the file to a user and it works when he runs it.
  • Share a "native file cache" between all your LWJGL applications. If you include the jar file with multiple projects, it tries to use the same directory for each one, resulting in the minumum of files on the user's computer.
  • Easily upgrade your LWJGL version: I create updated versions of the library for each major release of LWJGL, and all you have to do is replace the jar. The native files for separate versions are kept separate, so programs using the 2.8.4 version are independent from those using 2.8.3.

Do you want a copy? Sorry if I'm pushing this too hard, but it's made my life a lot easier and I really like how manages deployment.

Yes please! That is exactly what I was looking for!

CodeBunny


8Keep

Quote from: CodeBunny on June 24, 2012, 19:57:59
Here's where it's hosted: http://www.minds-eye-games.com/projects/misc/lwjgl-wrapper-library/

If you have any problems, let me know.

Its very good. I havent tried it yet, but I will tomorrow.



Can anyone answer my other questions?

CodeBunny

#1 You probably are interested in AngelCode Fonts as implemented by Slick.

#7 You should probably use Java 6, though java 7 has technically some performance improvements, simply because more people have J6 installed already.

Part of the problem is that there aren't "good" answers to some of your questions. For example, on #5, this is certainly possible, but (to me at least) it's a very bad way to structure your rendering, and isn't what you "should" be doing.

My overall reaction to your posts is that you should probably just use Slick since it handles most of this stuff for you. OpenGL is kind of complicated, and unless you take a decent amount of time learning its ups and downs, you probably won't make the greatest utilization of it. If you do decide to go for it, my only suggestion would be to look through OpenGL tutorials.

8Keep

Quote from: CodeBunny on June 25, 2012, 11:57:59
#1 You probably are interested in AngelCode Fonts as implemented by Slick.

#7 You should probably use Java 6, though java 7 has technically some performance improvements, simply because more people have J6 installed already.

Part of the problem is that there aren't "good" answers to some of your questions. For example, on #5, this is certainly possible, but (to me at least) it's a very bad way to structure your rendering, and isn't what you "should" be doing.

My overall reaction to your posts is that you should probably just use Slick since it handles most of this stuff for you. OpenGL is kind of complicated, and unless you take a decent amount of time learning its ups and downs, you probably won't make the greatest utilization of it. If you do decide to go for it, my only suggestion would be to look through OpenGL tutorials.

I used to do a lot of directx stuff, but recently ive been doing xna and now java. I am very familiar with game programming, i just needed to know the correct syntax for opengl because its really similar to directx from what ive heard.

I still dont know how to make a 2d camera. The opengl translation methods do something like that, but would it be easier to just have aa camera position variable and whenever I draw something in the map, add the cameras position?

Also, is glBegin taxing in any way? Should i begin and end every time I draw something? Or begin at thte begining of the draw part of the game loop and end at the end of it?

CodeBunny

From my limited experience with XNA, OpenGL is a lot more low-level, and requires you to be much more aware of what calls you are making. But the overall logic is the same. You're just calling things a bit differently.

No, no, never do a camera that way. The proper way to make your camera is to modify the projection matrix so that vertices get transformed to the appropriate screen locations. If you're doing 2D, you can set the initial scene with an ortho transform, and then use glTranslate/glRotate/etc. Camera "zoom" is handled by scaling the projection matrix. If you're doing 3D, use gluLookAt (I think that's the call, I do 2D stuff) to position your camera.

glBegin/glEnd are "heavy" calls and should be minimized. It's a good idea to package your geometry into single calls as much as possible. That said, you can't make a lot of calls while between a glBegin/glEnd, so you can't combine everything.

8Keep

Should I now draw things that are off the screen? And how do I do that? Do I compare each draw call and see if its less than the camera position and not greater than the camera position plus the screen height and width?

CodeBunny

I'm not 100% sure what you're asking... Camera culling is a very useful strategy that you should always use; the particular math you want to use is dependent on what's best for your game. Certain data structures (tilemaps, scenegraphs) lend themselves to different techniques.