Skip to content

Instantly share code, notes, and snippets.

@DennisSangmo
Created July 8, 2012 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DennisSangmo/3072849 to your computer and use it in GitHub Desktop.
Save DennisSangmo/3072849 to your computer and use it in GitHub Desktop.
Texture error
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.AngelCodeFont;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import static org.lwjgl.opengl.GL11.*;
public class TextureError {
public Texture tex;
public TextureError(){
try {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
} catch (LWJGLException e) {
e.printStackTrace();
}
tex = loadTexture();
}
public void start(){
while(!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Display.sync(60);
renderTexture();
renderColoredRectangle();
Display.update();
}
Display.destroy();
}
private void renderTexture(){
tex.bind();
glBegin(GL_TRIANGLES);
glTexCoord2f(1, 0);
glVertex2i(150, 10);
glTexCoord2f(0, 0);
glVertex2i(10, 10);
glTexCoord2f(0, 1);
glVertex2i(10, 150);
glTexCoord2f(0, 1);
glVertex2i(10, 150);
glTexCoord2f(1, 1);
glVertex2i(150, 150);
glTexCoord2f(1, 0);
glVertex2i(150, 10);
glEnd();
}
private void renderColoredRectangle(){
glColor3f(255f, 0f, 255f);
glRecti(200, 200, 300, 300);
}
private Texture loadTexture() {
try {
return TextureLoader.getTexture("JPG", new FileInputStream(new File("img.jpg")));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args){
new TextureError().start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment