get stuck all time

Hello,
i use LWJGL(opengl) and i learn from this tutorial:http://www.youtube.com/watch?v=7G_xtkvyleM
from the beginning everything worked just fine until now:(
i dont know why every time i play this mini game(mine craft 2d) , the window is black and everything get stuck.
why is that happening ?
is that a problem with my processor(intel coreTM 2) ?
or maybe its the display adapters(NVIDIA GeForce 9500 GT)?
help please ! ty.
and if you wanna see my code just ask.

Yes, we would like to see your code. It’s kind of hard to diagnose a disease over a phone when you’re told the symptom of the patient is “something is wrong”… :wink: From what you did tell us however, I’d say that this is most likely not a hardware problem.

Also, if you really want an answer quickly I recommend that you create at least one thread in each sub-forum on JGO. The sub-forum topics are just recommendation, so if you’re really important anything goes. Also consider spamming private messages to Riven (our glorious leader) and pretty much anyone else if your problem is REALLY urgent.
[/joke] :wink:

I am Riven, and I endorse this message.

fine , here’s the classes:
BLOCK class:


package mineCraft2d;


import static mineCraft2d.World.BLOCK_SIZE;
import static org.lwjgl.opengl.GL11.*;


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 Block
{


	private BlockType type = BlockType.AIR;
	private float x;
	private float y;
	private Texture texture = null;
	
	public Block(BlockType type, float x, float y) {
		super();
		this.type = type;
		this.x = x;
		this.y = y;
		try 
		{
			this.texture = TextureLoader.getTexture("PNG",new FileInputStream(new File(type.location)));
		} catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	public void draw()
	{
		texture.bind();
		glLoadIdentity();
		glTranslatef(x,y,0);
		glBegin(GL_QUADS);
		glTexCoord2f(0,0);
		glVertex2f(0,0);
		glTexCoord2f(1,0);
		glVertex2f(BLOCK_SIZE,0);
		glTexCoord2f(1,1);
		glVertex2f(BLOCK_SIZE,BLOCK_SIZE);
		glTexCoord2f(0,1);
		glVertex2f(0,BLOCK_SIZE);
		glEnd();
		glLoadIdentity();
	}
	public BlockType getType() {
		return type;
	}


	public void setType(BlockType type) {
		this.type = type;
	}


	public float getX() {
		return x;
	}


	public void setX(float x) {
		this.x = x;
	}


	public float getY() {
		return y;
	}


	public void setY(float y) {
		this.y = y;
	}
	
}


BlockGrid class:


package mineCraft2d;


import static mineCraft2d.World.*;


public class BlockGrid 
{
	private Block[][] blocks = new Block[BLOCKS_WIDTH][BLOCKS_HEIGHT];
	
	public BlockGrid()
	{
		
		for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
		{
			for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
			{
				blocks[i][j] = new Block(BlockType.AIR,i * BLOCK_SIZE,j * BLOCK_SIZE);
			}
		}
		
	}
	
	public void setAt(int x , int y , BlockType b)
	{
		blocks[x][y] = new Block(b,x * BLOCK_SIZE,y * BLOCK_SIZE);
	}
	public Block getAt(int x , int y)
	{
		return blocks[x][y];
	}
	public void draw()
	{
		for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
		{
			for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
			{
				blocks[i][j].draw();
			}
		}
	}
	
	
}


blockType class:


package mineCraft2d;


public enum BlockType
{


	STONE("res/stone.png") , AIR("res/air.png") , GRASS("res/grass.png") , DIRT("res/dirt.png");
	public final String location;
	
    BlockType(String location)
	{
		this.location = location;
	}
	
}

Boot class:


package mineCraft2d;




import static org.lwjgl.opengl.GL11.*;


import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.*;


public class Boot 
{
	BlockGrid grid;
	
	public Boot()
	{
		try
		{
			Display.setDisplayMode(new DisplayMode(640,480));
			Display.setTitle("Minecraft 2D");
			Display.create();
		}catch(LWJGLException e)
		{
			e.printStackTrace();
			
		}
		
		grid = new BlockGrid();
		grid.setAt(10,10,BlockType.STONE);
		
		
		//initialization code OpenGL
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0,640,480,0,1,-1);
		glMatrixMode(GL_MODELVIEW);
		glEnable(GL_TEXTURE_2D);
		
		while(!Display.isCloseRequested())
		{
			glClear(GL_COLOR_BUFFER_BIT);
			
		   input();
		   grid.draw();
			
			Display.update();
			Display.sync(60);
			
		}
		
		Display.destroy();
		
	}
	
	private void input()
	{
		int mousex = Mouse.getX();
		int mousey = 480 - Mouse.getY() - 1;
		boolean mouseClicked = Mouse.isButtonDown(0);
		if(mouseClicked)
		{
			int grid_x = Math.round(mousex / World.BLOCKS_WIDTH);
			int grid_y = Math.round(mousex / World.BLOCKS_HEIGHT);
			grid.setAt(grid_x, grid_y, BlockType.STONE);
		}
		
	}
	
	public static void main(String[] args)
	{
		
		new Boot(); 
		
		
	}
}

World class:


package mineCraft2d;






public class World 
{


	public static final int BLOCK_SIZE = 32;
	public static final int BLOCKS_WIDTH = 24 , BLOCKS_HEIGHT = 20;
	
	
}

that’s it.:slight_smile:

For starters…

Change this:

   public void draw()
   {
      for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
         {
            ...
         }
      }
   }

To this:

   public void draw()
   {
      for(int i=0 ; i<BLOCKS_WIDTH; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT; j++)
         {
            ...
         }
      }
   }

it didnt help:(
another suggestions ?

http://www.jeffwofford.com/?p=843

I have been wanting a similar article to show to my friend for ages! I was really close to finally writing something similar :stuck_out_tongue:
Thank you!

@OP
Rarely will anyone look through all your code and figure out what the problem is. You should at least have some sense of where the bug might occur, but just dumping it all on us will not help you very much :confused: