Results 1 to 13 of 13
Thread: LWJGL help please
- 12-25-2011, 02:29 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
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!
- 12-27-2011, 08:06 AM #2
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
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.
- 12-29-2011, 06:23 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: LWJGL help please
Thanks! ill take a look
- 12-29-2011, 07:20 AM #4
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
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
- 12-30-2011, 03:28 AM #5
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
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:
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();Java Code:while(running) { update(); //change values(positions), check input, etc.. render(); //here you would draw everything once again, but after you update }
- 12-30-2011, 09:27 PM #6
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
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.
- 12-30-2011, 11:24 PM #7
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
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.
- 12-30-2011, 11:27 PM #8
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
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)
- 12-31-2011, 12:28 AM #9
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
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 thanksLast edited by Brandon@JavaForums; 12-31-2011 at 12:35 AM.
- 12-31-2011, 01:59 AM #10
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
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(); } }
- 12-31-2011, 02:54 AM #11
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
Re: LWJGL help please
thank you that seems simple enough i will give it a try
- 12-31-2011, 09:26 AM #12
Member
- Join Date
- Dec 2011
- Posts
- 11
- Rep Power
- 0
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
- 12-31-2011, 10:19 AM #13
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 2
Similar Threads
-
Can't figure out how to create a keyboard class for lwjgl
By falconfetus8 in forum New To JavaReplies: 1Last Post: 11-27-2011, 12:39 AM -
LWJGL Collision Detection
By Furyright in forum Java 2DReplies: 1Last Post: 10-09-2011, 06:48 AM -
lwjgl help PLEASE!
By Brandon in forum New To JavaReplies: 1Last Post: 10-06-2011, 06:11 AM -
LWJGL: Camera + Block Collision
By Aaron in forum New To JavaReplies: 6Last Post: 11-14-2010, 09:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks