LWJGL 2D Breakout Tutorial – Environment Setup

Update: Just trying to get set up? Check out the streamlined setup tutorial LWJGL 2D Breakout Tutorial – Setup Summary.

So, I’ve been looking around for a good game engine that allows me to develop in Linux and ship to all sorts of platforms. I’ve finally settled on LWJGL, but there’s a lack of information out there for how to do, well, everything. So I figure I may as well take notes while I’m attempting to do stuff.

So, I’m starting right now. I’ve got gedit open, and I’m running in Ubuntu 12.04 x64 LTS. I am very familiar with development in eclipse, and I like Maven for the dependency management it supplies, so I’m going to use Eclipse with Maven[1].

First, we need java and maven.

sudo apt-get install openjdk-6-jdk openjdk-6-jre maven

download and install Eclipse Juno

http://www.eclipse.org/downloads/packages/eclipse-standard-43/keplerr

Now install the maven plugin for Eclipse m2e

maven_for_eclipse

Now we need to create a new maven project for breakout. For me, I put my projects into /home/midas/git/ and the new maven project will add the directories breakout-lwjgl/breakout. This whole path will be referred to as PROJECT_PATH (/home/midas/git/breakout-lwjgl/breakout) from here on, because it will probably be different for everyone.

new_maven_project

pick_maven_type

save_project_location

Ok, now open Eclipse so we can edit the pom.xml to set up our lwjgl dependencies.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>breakout-lwjgl</groupId>
  <artifactId>breakout</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>breakout</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <natives.version>0.0.6</natives.version>
    <lwjgl.version>2.8.4</lwjgl.version>
    <slick.version>274</slick.version>
    <junit.version>4.10</junit.version>
  </properties>

  <repositories>
    <repository>
      <id>mavenNatives</id>
      <name>Maven Natives Repository</name>
      <url>http://mavennatives.googlecode.com/svn/repo</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>slick</id>
      <name>slick</name>
      <url>http://slick.cokeandcode.com/mavenrepo</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.lwjgl.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>${lwjgl.version}</version>
    </dependency>
    <dependency>
      <groupId>slick</groupId>
      <artifactId>slick</artifactId>
      <version>${slick.version}</version>
    </dependency>
    <dependency>
      <groupId>java3d</groupId>
      <artifactId>vecmath</artifactId>
      <version>1.3.1</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
          </configuration>
        </plugin>
        <plugin>
          <groupId>com.googlecode.mavennatives</groupId>
          <artifactId>maven-nativedependencies-plugin</artifactId>
          <version>${natives.version}</version>
          <executions>
            <execution>
              <id>unpacknatives</id>
              <phase>generate-resources</phase>
              <goals>
              <!--suppress MavenModelInspection (this line is for IDEA) -->
                <goal>copy</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

This caused Eclipse to yell at me for the slick dependency, since that maven repo no longer exists. Awesome! Ok, so I’ll just git clone the slick2d repo from github and then copy the jar over. Hey, look! Someone made a slick2d-maven project!

cd /home/midas/git/
git clone https://github.com/nguillaumin/slick2d-maven.git
cd slick2d-maven
mvn clean install

Aww damn it. Apparently I’m missing a dependency for javaws.jar which only comes from Oracle. Ok, ok. I got this. Looks like WebUpd8 has a nice easy solution.[2]

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer

Awesome! Now let’s try recompiling the slick2d-maven project using our new java version.

JAVA_HOME='/usr/lib/jvm/java-6-oracle/';mvn clean install

That seemed to work! Now we’ve got a slick2d jar we can use in our repo. We’ll have to change the pom.xml file in the breakout repo a bit…

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>breakout-lwjgl</groupId>
	<artifactId>breakout</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>breakout</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<natives.version>0.0.6</natives.version>
		<lwjgl.version>2.8.4</lwjgl.version>
		<slick.version>2013.08-SNAPSHOT</slick.version>
		<junit.version>4.10</junit.version>
	</properties>

	<repositories>
		<repository>
			<id>mavenNatives</id>
			<name>Maven Natives Repository</name>
			<url>http://mavennatives.googlecode.com/svn/repo</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>

		<repository>
			<id>slick</id>
			<name>Slick2D</name>
			<url>file:${project.basedir}/repo</url>
		</repository>
	</repositories>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.lwjgl.lwjgl</groupId>
			<artifactId>lwjgl</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slick2d</groupId>
			<artifactId>slick2d-basic-game-archetype</artifactId>
			<version>${slick.version}</version>
		</dependency>
		<dependency>
			<groupId>java3d</groupId>
			<artifactId>vecmath</artifactId>
			<version>1.3.1</version>
		</dependency>
	</dependencies>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<configuration>
						<source>1.6</source>
						<target>1.6</target>
					</configuration>
				</plugin>

				<plugin>
					<groupId>com.googlecode.mavennatives</groupId>
					<artifactId>maven-nativedependencies-plugin</artifactId>
					<version>${natives.version}</version>
					<executions>
						<execution>
							<id>unpacknatives</id>
							<phase>generate-resources</phase>
							<goals>
								<!--suppress MavenModelInspection (this line is for IDEA) -->
								<goal>copy</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

Now create a “repo” folder inside our maven project and copy the .jar file from the maven cache.

cd PROJECT_PATH
mkdir repo
cd repo
cp ~/.m2/repository/org/slick2d/slick2d-basic-game-archetype/slick2d-basic-game-archetype-2013.08-SNAPSHOT.jar .

Sweet! At this point, in Eclipse you should be able to run maven clean and maven install on your project and have everything come up as success. Awesome! Our environment looks like it’s set up. Let’s run a Maven clean and then run the hello world app that Eclipse has generated for us.

maven_clean

run_causes_error

Ahh, whoops! Since we’re using Maven, we need to tell Maven to install (and compile) our .jar before we can run it. Just run Maven install, and then you should be good to go.

maven_install

Look! Running it makes the console say “Hello world!”

environment_success

Check out the next post in this series: LWJGL 2D Breakout Tutorial – OpenGL drawing and keyboard input

[1] http://www.lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_Maven
[2] http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

Advertisements
LWJGL 2D Breakout Tutorial – Environment Setup

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s