Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: bug on lightwave java game library

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool bug on lightwave java game library

    what's up eveeryone?
    I'm new into GUIs on java, and I've watched a video lesson on youtube teaching how to make some graphics interface with mouse and keyboard interacting.
    On the lesson's video, the code worked PERFECTLY and I wrote just the same as the video but in my pc it didn't work.
    It was supposed to move the box on the screen as we move it with the mouse and show a message "you clicked me" too. But in my pc the only thing that worked was the 'u clicked me' in the first loop and then, it didn't work anymore, and no dragging to.

    so, here is the link of the video lessons:
    #4 Input -- Java Game Development (LWJGL) - YouTube

    the part where it shows the working program on the video is at 18:00 mins of video, and here, is the code that I wrote EXACTLY as the video:

    import static org.lwjgl.opengl.GL11.*;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import org.lwjgl.opengl.*;
    import org.lwjgl.*;
    import org.lwjgl.input.Mouse;
    import org.lwjgl.input.Keyboard;
     
    public class InputDemo {
     
    	private List<Box> shapes = new ArrayList<Box>(16);
    	private boolean somethingIsSelected = false;
     
    	public InputDemo(){
    		try {
    			Display.setDisplayMode(new DisplayMode(640, 480));
    			Display.setTitle("input demo");
    			Display.create();
    		} catch (LWJGLException e){
    			e.printStackTrace();
    		}
     
    		shapes.add(new Box(15, 150));
    		shapes.add(new Box(100, 150));
    		//codigo de inicializar OPenGL
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		glOrtho(0, 640, 480, 0, 1, -1);
    		glMatrixMode(GL_MODELVIEW);
     
    		while(!Display.isCloseRequested()){
    			//render
    			glClear(GL_COLOR_BUFFER_BIT);
     
    			while(Keyboard.next()){
    				if(Keyboard.getEventKey()== Keyboard.KEY_C && Keyboard.getEventKeyState()){
    					shapes.add(new Box(15, 15));
     
    				}
     
    			}
     
     
    			if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
    				Display.destroy();
    				System.exit(0);
    			}
    			//mouse.get pega a coordenada do mouse
    			//mouse.getD pega quantos pixels o mouse se mecheu
    			int mousey = 480 - Mouse.getY();
    			int mousex =  Mouse.getX();
     
    			int dx = Mouse.getDX();
    			int dy = Mouse.getDY();
     
     
     
    			for(Box box: shapes){
    				if(Mouse.isButtonDown(0) && box.inBounds(Mouse.getX(), 480 - Mouse.getY()) && !somethingIsSelected){
    					somethingIsSelected = true;
    					box.selected = true;
    					System.out.println("You clicked me!");
    				}
    				if(Mouse.isButtonDown(1)){
    					box.selected = false;
    					somethingIsSelected = false;
    				}
    				if(box.selected){
    					box.update(Mouse.getDX(), Mouse.getDY());
    				}
    				//box.randomizeColors();
     
    				box.draw();
    			}
     
    			Display.update();
    			Display.sync(60);
    		}
    		Display.destroy();
    	}
     
    	private static class Box{
    		public int x,y;
    		public boolean selected = false;
    		private float colorRed, colorBlue, colorGreen;
     
    		Box(int x, int y){
    			this.x=x;
    			this.y=y;
    			Random randomGenerator = new Random();
    			colorRed = randomGenerator.nextFloat();
    			colorBlue = randomGenerator.nextFloat();
    			colorGreen = randomGenerator.nextFloat();
    		}
    		boolean inBounds(int mousex, int mousey){
    			if(mousex > x && mousex < x+50 && mousey > y && mousey < y+50){
    				return true;
    			}
    			else	
    				return false;
    		}		
    		void update(int dx, int dy){
    			x += dx;
    			y += dy;
    		}		
    		void randomizeColors(){
    			Random randomGenerator = new Random();
    			colorRed = randomGenerator.nextFloat();
    			colorBlue = randomGenerator.nextFloat();
    			colorGreen = randomGenerator.nextFloat();
    		}
    		void draw(){
    			glColor3f(colorRed, colorBlue, colorGreen);
    			glBegin(GL_QUADS);
    			glVertex2f(x, y);
    			glVertex2f(x+50, y);
    			glVertex2f(x+50, y+50);
    			glVertex2f(x, y+50);
    		glEnd();			
    		}	
    	}	
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new InputDemo();
     
    	}
     
    }
    Last edited by anon176; May 4th, 2012 at 08:59 AM. Reason: forgot the highlight stuff


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,342
    My Mood
    Hungover
    Thanks
    143
    Thanked 625 Times in 536 Posts

    Default Re: bug on lightwave java game library

    We can't run that code because it refers to classes we don't have (I don't think many people here are LWJGL developers), so we can't really help you as is. You could try putting together an SSCCE that eliminates the LWJGL references, or you could try following the more general advice here: http://www.javaprogrammingforums.com...t-println.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: bug on lightwave java game library

    Well, I'm just new into this GUI stuff. LWJGL was the first thing that I found on google to learn to deal with graphics and i've downloaded something like 500mb of lessons...
    anyway, what's an SSCCE afterall? I just wanna learn to use GUIs to make some games...

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: bug on lightwave java game library

    OK guys, forget about it, i've already solved the problem here (:

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,342
    My Mood
    Hungover
    Thanks
    143
    Thanked 625 Times in 536 Posts

    Default Re: bug on lightwave java game library

    Note that if you are just trying to create a gui, you might want to start with basic Swing. LWJGL is specific to game development.

    Also, it's light weight, not light wave.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Game Programming Tutorials - Slick2D library
    By worsewicked in forum Java Programming Tutorials
    Replies: 2
    Last Post: June 14th, 2013, 11:58 AM
  2. How to use GNU Crypto LIbrary in Matlab via Java Interface
    By divix in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 18th, 2012, 01:27 PM
  3. Using Protected Methods, in a Java Library
    By WACman in forum Object Oriented Programming
    Replies: 2
    Last Post: March 10th, 2011, 04:42 PM
  4. Replies: 0
    Last Post: May 3rd, 2010, 04:42 AM
  5. Replies: 1
    Last Post: October 7th, 2008, 07:35 AM

Tags for this Thread