Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default LWJGL help please

    hi i was just wondering how do you translate objects in lwjgl w/0 translating the entire thing ive tried use GL11.glLoadIdentity(); but that
    stops everything from moveing. is there any way somebody could help i will show you the code im currently useing


    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);


    while(!Display.isCloseRequested())
    {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPT H_BUFFER_BIT);

    GL11.glColor3f(1.0f, 0, 0);

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(0,0);
    GL11.glVertex2f(0+100,0);
    GL11.glVertex2f(0+100,0+100);
    GL11.glVertex2f(0,0+100);
    GL11.glEnd();

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glTranslated(1.0f, 0, 0);
    GL11.glColor3f(0,1.0f,0);

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(200,0);
    GL11.glVertex2f(200+100,0);
    GL11.glVertex2f(200+100,0+100);
    GL11.glVertex2f(200,0+100);
    GL11.glEnd();

    Display.update();
    }

    any help given will be grate thank you!

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    Try reading this:
    7. OpenGL Rotation and Translation (Version 2.0) | Swiftless Tutorials
    You need to really get your head around keeping track of rotations and translations.

  3. #3
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    Thanks! ill take a look

  4. #4
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    well i read through it and i figured out how to translate seprate things but they don't keep moving they just move and stop

  5. #5
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    What is probably happening is that you move something once but never again.
    Have you implemented a "game loop" that updates the game each frame?

    A very simple implementation could be:

    Java Code:
    while(running) {
        
        update(); //change values(positions), check input, etc..
        render(); //here you would draw everything once again, but after you update
    
    }
    In an update method you could choose to increment a value each time through the loop and then render your graphics based on the variables you did something to in update();

  6. #6
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    I have done something actually like that but when I do GL11.glPushMatrix() and then GL11.glPopMatrix() it freezes up again. so I went over the reading and found that I was pushing it between states so I tried adding another while loop between the push and pop but then it cant draw everything else because it stops at the second while loop and doesn't know what to do. should I use threads?
    Last edited by Brandon@JavaForums; 12-30-2011 at 09:30 PM.

  7. #7
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    NOOOOOOOOOOOOOOOOO. You don't need more than one thread unless you really need it.

    By that i mean, you have a multiplayer server for a game, etc...
    Threads just complicate stuff and use unnecessary power for tasks can accomplish, you will be amazed at how much a single thread can do.

  8. #8
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    okay lets start from scratch, please post ALL of your code, if there irrelevant parts you can leave them out but if we see your code then we can find out exactly what going on.
    (P.S. I know you posted it above, but all of it! and use code tags)

  9. #9
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    but i restated i just want to know how to use different states i could post to you what i usually do to start it off but i restarted so it is completely different but this is kinda along the lines of what i did

    public class mkDisplay()
    {

    public static void initGL()
    {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0,Display.getWidth(),Display.getHeigh t(),0,-1,1);
    GL11.glMatrixMode(GL11.GL_MODLEVIEW);
    }

    public static void initDisplay()
    {
    try{
    Display.setDisplayMode(new DisplayMode(800,600));
    Display.create();
    }catch(LWGJLException e)
    {
    e.printStackTrace();
    }
    }

    public static void render()
    {
    while(!Display.isCloseRequested)
    {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    GL11.glPushMatrix();

    GL11.glTranslated(1,0,0);

    GL11.glBegin(GL11.glQuads);
    GL11.glVertex2d(50,50);
    GL11.glVertex2d(100,50);
    GL11.glVertex2d(100,100);
    GL11.glVertex2d(50,100);
    GL11.glEnd();

    GL11.glPopMatrix();

    Display.update();

    if(Keyboard.isKeyDown(Keyboard.KEY_F11) && !Display.isFullScreen())
    {
    try{
    Display.setDisplayMode(Display.getDesktopDisplayMo de())
    Display.setFullScreen(true);
    }catch(LWGJLException e){
    e.printStackTrace
    }
    }

    if(Keyboard.isKeyDown(Keyboard.KEY_F11) && Display.isFullScreen)
    {
    try{
    Display.setDisplayMode(new DisplayMode(800,600));
    }catch(LWGJLException e){
    e.printStackTrace
    }
    }
    }
    }

    public static void main(String args[])
    {
    initDisplay();
    initGL();
    Render();
    }
    }

    if you could post the code that you would use that would be grate thanks
    Last edited by Brandon@JavaForums; 12-31-2011 at 12:35 AM.

  10. #10
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    Please carefully read over how i did this and think about what is happening each time through my loop:

    Java Code:
    public class Display [
    	
    	public static final int WIDTH = 50;
    	public static final int HEIGHT = 50;
    	public int xPos;
    	public int yPos;
    	
    	public Display() {
    		initDisplay();
    		initGL();
    		mainLoop();
    	}
    	
    	public static void initGL() {
    		//This is fine, keep the same
    	}
    	
    	public static void initDisplay() {
    		//This is fine, keep the same
    	}
    	
    	public void update() {
    		//This is where you change stuff each time through the loop
    		//e.g. Position
    		xPos++; //Increment xPos 
    		yPos++; //"       " yPos
    	}
    	
    	public void render() {
    		//This draws a quad based on the current position and width
    		//It allows for change if position very easily
    		glBegin(GL_QUADS);
    			glVertex2i(xPos, yPos); //Top Left
    			glVertex2i(xPos + WIDTH, yPos); //Top Right
    			glVertex2i(xPos + WIDTH, yPos + HEIGHT); //Bottom Right
    			glVertex2i(xPos, yPos + HEIGHT); //Bottom Left
    		glEnd();
    	}
    
    	public void mainLoop() {
    	
    		while (!Display.isCloseRequested) {
    			
    			glClear(GL_COLOR_BUFFER_BIT);
    			
    			update(); //Translate objects position
    			render(); //Render that object after changing its position
    			
    			Display.update();
    		}
    		Display.destroy();
    	}
    	
    	public static void main(String[] args) {
    		new Display();
    	}
    }

  11. #11
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    thank you that seems simple enough i will give it a try

  12. #12
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: LWJGL help please

    wow it relay works and i can finaly continue with my game ive also found a way to simplify it thanks alot

  13. #13
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: LWJGL help please

    Thats ok.
    As long as you know whats going on and why stuff is or isn't working, thats good.

    And BTW what are you making?

Similar Threads

  1. Can't figure out how to create a keyboard class for lwjgl
    By falconfetus8 in forum New To Java
    Replies: 1
    Last Post: 11-27-2011, 12:39 AM
  2. LWJGL Collision Detection
    By Furyright in forum Java 2D
    Replies: 1
    Last Post: 10-09-2011, 06:48 AM
  3. lwjgl help PLEASE!
    By Brandon in forum New To Java
    Replies: 1
    Last Post: 10-06-2011, 06:11 AM
  4. LWJGL: Camera + Block Collision
    By Aaron in forum New To Java
    Replies: 6
    Last Post: 11-14-2010, 09:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •