[LWJGL] Using multiple libraries

I started using LWJGL and on their site I noticed that slick.util, OpenGL, and OpenAL were available for use. Just incase, I added the slick_util and lwjgl_util. If I’m mainly using LWJGL, what is the point for slick_util, lwjgl_util, and other libraries. I understand why OpenGL, but are there certain methods you take from them?

Not sure what your asking…

But I think what you mean is what each library does.
LWJGL is an OpenGL wrapper for Java. It was originally made for another programming language, but it basically lets you you use the openGL methods. (Like glBind() and glEnd()).

Mainly, how to use the LWJGL classes, we import all the static methods from LWJGL using a simple import:

import static org.lwjgl.opengl.GL11.*; //GL11 is OpenGL 1.1, there are other OpenGL versions, but we only need the methods that were with openGL 1.1

Importing from static means you have all the methods with static from “GL11”.

Slick_Util is all of the cool things from slick, but just without the slick game framework. Like texture loading, and font loading.

LWJGL_Util has some cool utility methods. Pretty much everything in the org.lwjgl.util package.

So I can call slick methods with it?

Not really, slick loads the textures into openGL for you, making it easier than you making your own texture loader / font renderer.
You still have to do the openGL stuff. Just that textures, fonts, ect, can be handled by slick.

Slick (Not slick_util) is a game engine, it handles game levels, tile maps, drawing images, and “high level” game stuff.

Hopefully you’re using more than just OpenGL 1.1 :wink:

@OP I think the only thing you would use slick_util for is textures. You can load textures easily and then bind them, get tex coords, and other stuff. SHC put out a great article (EDIT: can’t find it now, maybe he took it down. The code is here though) on loading your own textures. It’s all I use now. lwjgl_util has classes like Matrix4f and Vector3f.

I have used slick recently. So with the Texture loading I’d just be able to call slick-utils’ or slicks’ Texture class?

Example:

texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/image.png"));

I researched the definition of a texture to understand, and apparently it’s needed to load an image?
Anyways, if I’m wrong does Opengl have its’ own texture loading class or image loading class?

OpenGL has a way to handle them, but not to load it from a file / initialize them.

Ok thank you. I’m just working on understanding that matrix stuff.
Here’s my code if your interested in helping

import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class Rendering {
	public void start() {
		try {
			Display.setDisplayMode(new DisplayMode(800, 600));
			Display.setTitle("Game");
			
			Display.create();
		} catch (LWJGLException e) {
			e.printStackTrace();
			System.exit(0);
		}
               // What is the purpose of PROJECTION
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, 640, 480, 0, 1, -1);

              //What is the purpose of MODELVIEW?
		glMatrixMode(GL_MODELVIEW);
		
		
		while(!Display.isCloseRequested()) {
			Display.update();
			//What does the parameters of glCLear do?
			glClear(GL_COLOR_BUFFER_BIT);
			
			glBegin(GL_LINES);
			glVertex2i(100, 100);
			glVertex2i(200, 200);
			glVertex2i(300, 200);
			glVertex2i(30,  60);
			glVertex2i(340, 202);
			glVertex2i(304,  260);
			
			glEnd();
		}
		Display.destroy();
	}

	public static void main(String[] args) {
		Rendering r = new Rendering();
		r.start();
	}

}

OpenGL doesn’t have a way to handle them. It has a way to buffer the data to the graphics card to be sampled, but you will still have to write all the texture code yourself.

OP, what’s wrong with your code? You would get more answers if you were specific.

Nothing is wrong, I just don’t understand certain parts where I commented

That’s what I meant by handle, I’m trying to simplify things as much as I can.

// What is the purpose of PROJECTION
glMatrixMode(GL_PROJECTION);  

Projection is the matrix that handles pixels, and openGL’s canvas points to your java2D knowledge . (To simplify it, opiop65 :point:)


//What is the purpose of MODELVIEW?
glMatrixMode(GL_MODELVIEW);

Modelview is the games “model” matrix. It handles sending models to the graphics card through glBegin(); and glEnd(); (Even know glBegin(); is deprecated (old), we use it for testing purposes).

//What does the parameters of glCLear do?
glClear(GL_COLOR_BUFFER_BIT);

Basically clears all the colors on the screen to have a fresh start for the next frame in your game.

[quote=“Spacebeans,post:11,topic:48431”]

Now I understand a lot better. Does the tutorial you showed me teach you why it is “old” and it’s used for testing

No, he just explains how to use it. People today use a complicated system called buffer objects. Which he also teaches you about.

Sadly enough, I think that SHC took his tutorials down. I’ve not been able to access any of them, I tried to yesterday to view an old way of creating a perspective projection for reference (not glu-related).

Nearly double posted to show this. :persecutioncomplex:
Then I remembered: The edit button.

Anyways, check this link out, it explains a bunch on model, view, and projection matrices. It also contains a link to a great matrix math site that explains rotation/translation/other transformation matrices very well. You may not be interested in the math part, but it’s certainly good to know.
http://lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices

They’re supposedly here (his site), but it’s down, has been for a while.

The tutorial you recommended is great. Also I don’t know who your talking about when you explained the SHC.

SHC is a member of this forum, if you search his name you will find him.

Thanks so much everyone. I’ll actually have a basic sandbox game (preAlpha stage) done by tonight or early in the morning :o . I’ll try to post it once I figure out how to make the lwjgl game an executable.

It’s actually easier than you think. Exporting as a jar is trivial, but if you simply try to run it, you’ll find you get an LWJGL not found in classpath, or something along those lines. This is also trivial to fix:
You need to add a switch to the java command to add the natives to the run.

On Linux, you make a .sh file with the command


java -Djava.library.path="LinuxNatives/" -jar game.jar //LinuxNatives being the directory with the, well linux natives.

Same on Windows, but with a .bat or whatever you may use, I haven’t had Windows in over a year so I’m not much of an expert on that. Except, you’d use the WindowsNatives -or whichever directory includes them- directory instead.
Same for Mac, just with its executable file type and natives.

Edit:
Or you can just look at this official link here: http://lwjgl.org/wiki/index.php?title=Distributing_Your_LWJGL_Application
This explains everything for applets, desktop, and the like.

There’s a nifty tool for this: JarSplice

I also made a lib (as have others) which does more or less the same thing: http://www.java-gaming.org/topics/lwjgl-slick-how-do-you-distribute-a-game-without-jarsplice/32835/msg/307812/view.html#msg307812 although it’s not well tested, so you should probably use JarSplice. JarSplice (and others like Launch4J) can also wrap a jar into a windows executable, should you need that, but a jar is fine most things.