I am new to LWJGL and I am trying to create a 3d simple game (making a floor, and some blocks I can collide with), but everytime I load more stuff the images get darker on screen.
package npe.dungeonfighter;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class DungeonFighter{
public static void main(String[] args){
initGame();
initList();
gameLoop();
cleanUp();
}
static Floor floor;
static Camera cam;
private static void gameLoop(){
cam = new Camera(70f,(float)Display.getWidth()/(float)Display.getHeight(),0.3f,1000f);
while(!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
cam.useView();
glPushMatrix();{
glTranslatef(0,0,-10);
glCallList(1);
glEnd();
update();
Display.update();
}
glPopMatrix();
}
}
private static void draw(){
}
private static void update(){
cam.update();
}
private static void cleanUp(){
Display.destroy();
System.exit(0);
}
private static void initList(){
[b]//Images.init();[/b]
int list = glGenLists(1);
System.out.println(list);
glNewList(list,GL_COMPILE);{
glBegin(GL_QUADS);{
//Front face
glColor3f(1.0f,0,0);
glVertex3f(-1,-1,1);
glVertex3f(-1,1,1);
glVertex3f(1,1,1);
glVertex3f(1,-1,1);
//BackFace
glColor3f(0f,1f,0f);
glVertex3f(-1,-1,-1);
glVertex3f(-1,1,-1);
glVertex3f(1,1,-1);
glVertex3f(1,-1,-1);
//BottomFace
glColor3f(0f,0f,1f);
glVertex3f(-1,-1,-1);
glVertex3f(-1,-1,1);
glVertex3f(-1,1,1);
glVertex3f(-1,1,-1);
//TopFace
glColor3f(1.0f,1f,0f);
glVertex3f(1,-1,-1);
glVertex3f(1,-1,1);
glVertex3f(1,1,1);
glVertex3f(1,1,-1);
//LeftFace
glColor3f(0f,1f,1f);
glVertex3f(-1,-1,-1);
glVertex3f(1,-1,-1);
glVertex3f(1,-1,1);
glVertex3f(-1,-1,1);
//RightFace
glColor3f(1.0f,1f,1f);
glVertex3f(-1,1,-1);
glVertex3f(1,1,-1);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
}
glEnd();
}
glEndList();
}
private static void initGame(){
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.setTitle("Title!");
Display.create();
}catch (LWJGLException e){e.printStackTrace();}
}
}
This setup gives me this result:
http://imageshack.us/photo/my-images/849/3dgamep1.png/But if I get rid of the "//" infront of
//Images.init(); in the initLists() method, I get this result:
http://imageshack.us/photo/my-images/208/3dgamep2.png/As you can see the cube becomes visibly darker.
The Images.init() method just runs a static method in a differant class that gets textures:
package npe.dungeonfighter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Images{
static Texture floor;
public static void init(){
try {
floor=TextureLoader.getTexture("png",new FileInputStream(new File("res/floor.png")));
}catch(FileNotFoundException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}
}
}
I have no idea what I'm doing wrong. Thanks for any help!
EDIT: I found a post (after a bit of searching through the things- couldnt find one originaly) that said I needed to use glDisable(GL_TEXTURE2D);
I've done this and it works, but might I ask why this works?