Thomas Allen avatar Thomas Allen committed 80461bb

Changed the Sprite class to render quad vertices in the correct order.

Comments (0)

Files changed (3)

src/com/xardov/lwjgl/testbed/Sprite.java

-package com.xardov.lwjgl.testbed;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-
-import org.lwjgl.opengl.GL11;
-import org.newdawn.slick.opengl.Texture;
-import org.newdawn.slick.opengl.TextureLoader;
-import org.newdawn.slick.util.ResourceLoader;
-
-public class Sprite 
-{
-	Texture bodyTexture;
-	
-	public float x, y; 
-	private int width, height;
-	
-	public Sprite(int x, int y)
-	{
-		this.x = x;
-		this.y = y;
-	}
-	
-	public void loadImage(String filePath, int width, int height) throws IOException
-	{		
-		bodyTexture = TextureLoader.getTexture("PNG", Main.class.getClassLoader().
-														getResourceAsStream(filePath));
-		
-		this.width = width;
-		this.height = height;
-	}
-	
-	public void render()
-	{
-		GL11.glPushMatrix();
-		
-		bodyTexture.bind();
-		
-		GL11.glBegin(GL11.GL_QUADS);
-		{
-			GL11.glColor3f(1.0f, 1.0f, 1.0f);
-			
-			GL11.glTexCoord2f(0, 0);
-			GL11.glVertex2f(x, y);
-			
-			GL11.glTexCoord2f(1, 0);
-			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), y);
-			
-			GL11.glTexCoord2f(0, 1);
-			GL11.glVertex2f(x, y - bodyTexture.getTextureHeight());
-			
-			GL11.glTexCoord2f(1, 1);
-			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), 
-							y - bodyTexture.getTextureHeight());
-		}
-		GL11.glEnd();
-		
-		drawHitbox(0, 0, x + bodyTexture.getWidth(), y - bodyTexture.getHeight());
-		
-		GL11.glPopMatrix();
-	}
-	
-	private void drawHitbox(float x1, float y1, float x2, float y2)
-	{
-		GL11.glBegin(GL11.GL_LINES);
-		{
-			GL11.glColor3f(1.0f, 0.0f, 0.0f);
-			
-			GL11.glVertex2f(x1, y1);
-			GL11.glVertex2f(x2, y2);
-		}
-		GL11.glEnd();
-	}
-}

src/com/xardov/terrain/gen/Main.java

 	
 	public Map map = new Map();
 	
-	Sprite sprite;
+	Tile tile;
 	
 	public void init()
 	{
 		
 		GL11.glMatrixMode(GL11.GL_PROJECTION);
 		GL11.glLoadIdentity();
-		GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
+		GL11.glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
 		GL11.glMatrixMode(GL11.GL_MODELVIEW);
 		
-		map.init();
+		//map.init();
 		
-		sprite = new Sprite(0, 20);
-		try {
-			sprite.loadImage("assets/graphics/alien.png", 43, 29);
-		} catch (Exception e) {
-			// TODO: handle exception
-		}
+		tile = new Tile(5, 20);
 		
 		while(!Display.isCloseRequested())
 		{
 	
 	public void render()
 	{
-		map.render();
-		sprite.render();
+		//map.render();
+		tile.render();
 	}
 	
 	public static void main(String[] args) 

src/com/xardov/terrain/gen/Sprite.java

 			GL11.glTexCoord2f(1, 0);
 			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), y);
 			
-			GL11.glTexCoord2f(0, 1);
-			GL11.glVertex2f(x, y - bodyTexture.getTextureHeight());
-			
 			GL11.glTexCoord2f(1, 1);
 			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), 
-							y - bodyTexture.getTextureHeight());
+							y + bodyTexture.getTextureHeight());
+			
+			GL11.glTexCoord2f(0, 1);
+			GL11.glVertex2f(x, y + bodyTexture.getTextureHeight());
+			
 		}
 		GL11.glEnd();
 		
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.