Hello Guest

A few beginner lwjgl questions

  • 11 Replies
  • 9431 Views
A few beginner lwjgl questions
« on: June 23, 2012, 23:56:56 »
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 :)
« Last Edit: June 24, 2012, 00:01:19 by 8Keep »

*

Offline Daslee

  • ***
  • 126
Re: A few beginner lwjgl questions
« Reply #1 on: June 24, 2012, 08:47:52 »

Re: A few beginner lwjgl questions
« Reply #2 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.

Re: A few beginner lwjgl questions
« Reply #3 on: June 24, 2012, 18:12:12 »

Re: A few beginner lwjgl questions
« Reply #4 on: June 24, 2012, 18:13: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!

Re: A few beginner lwjgl questions
« Reply #5 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.

Re: A few beginner lwjgl questions
« Reply #6 on: June 25, 2012, 02:08:03 »
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?

Re: A few beginner lwjgl questions
« Reply #7 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.

Re: A few beginner lwjgl questions
« Reply #8 on: June 25, 2012, 20:27:33 »
#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?

Re: A few beginner lwjgl questions
« Reply #9 on: June 25, 2012, 20:53:19 »
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.

Re: A few beginner lwjgl questions
« Reply #10 on: June 27, 2012, 21:47:01 »
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?

Re: A few beginner lwjgl questions
« Reply #11 on: June 27, 2012, 22:59:43 »
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.