Results 1 to 2 of 2
- 05-12-2012, 05:06 PM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Hey could anyone help with this code please its LWJGL
Hey I'm trying to create a menu for my game so i have my three buttons (which are just rectangles at the moment) but i want to wrap text to them. however when i run my program a window just flashes up then immediately closes.I'm not entirely sure why it does this so I have posted the two relevant classes in hope you can help me :D thanks , josh
Main Class
Menu ClassJava Code:package MainPackage; import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT; import static org.lwjgl.opengl.GL11.GL_MODELVIEW; import static org.lwjgl.opengl.GL11.GL_PROJECTION; import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glLoadIdentity; import static org.lwjgl.opengl.GL11.glMatrixMode; import static org.lwjgl.opengl.GL11.glOrtho; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.newdawn.slick.opengl.*; ; public class Main { public static enum State { INTRO, MAIN_MENU, GAME; } public State state = State.INTRO; public Main() { } public void start(){ try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setTitle("Maths"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } // Initialization code OpenGL glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glMatrixMode(GL_MODELVIEW); /* MAIN STUFF */ while (!Display.isCloseRequested()) { // Render glClear(GL_COLOR_BUFFER_BIT); Menu.draw(); if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { Display.destroy(); System.exit(0); } int mousex = Mouse.getX(); int mousey = 480 - Mouse.getY(); if (Menu.isInBounds(mousex, mousey) && Mouse.isButtonDown(0)) { Display.destroy(); System.exit(0); } if (Menu.isInBoundstwo(mousex, mousey) && Mouse.isButtonDown(0)) { Display.destroy(); System.exit(0); } if (Menu.isInBoundsthree(mousex, mousey) && Mouse.isButtonDown(0)) { Display.destroy(); System.exit(0); } // TESTING JUST PRINTS X & Y if (Mouse.isButtonDown(0)) System.out.println("X : " + mousex + "|| Y :" + mousey); Display.update(); Display.sync(60); } Display.destroy(); } public void render(){ switch(state){ case INTRO: break; case GAME: break; case MAIN_MENU: break; } } public void checkInput(){ switch(state){ case INTRO: break; case GAME: break; case MAIN_MENU: break; } } /* end of constructor */ public static void main(String[] args) { new Main().start(); } }
Java Code:package MainPackage; import static org.lwjgl.opengl.GL11.GL_MODELVIEW; import static org.lwjgl.opengl.GL11.GL_PROJECTION; import static org.lwjgl.opengl.GL11.GL_QUADS; import static org.lwjgl.opengl.GL11.glBegin; import static org.lwjgl.opengl.GL11.glEnd; import static org.lwjgl.opengl.GL11.glLoadIdentity; import static org.lwjgl.opengl.GL11.glMatrixMode; import static org.lwjgl.opengl.GL11.glOrtho; import static org.lwjgl.opengl.GL11.glVertex2i; 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; import static org.lwjgl.opengl.GL11.*; public class Menu { public static Texture play; // set OpenGL settings public Menu() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); play = loadTexture("play"); } //Button coordinate variables public static int x1; public static int x2; public static int y1; public static int y2; public static int x3; public static int x4; public static int y3; public static int y4; public static int x5; public static int x6; public static int y5; public static int y6; // Drawing Buttons static void draw() { play.bind(); /* PLAY BUTTON */ x1 = 170; x2 = 470; y1 = 200; y2 = 250; glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2i(x1, y1); // Upper-left glTexCoord2f(1,0); glVertex2i(x2, y1); // Upper-right glTexCoord2f(1,1); glVertex2i(x2, y2); // Bottom-right glTexCoord2f(0,1); glVertex2i(x1, y2); // Bottom-left glEnd(); /* Settings Button */ x3 = 170; x4 = 470; y3 = 300; y4 = 350; glBegin(GL_QUADS); glVertex2i(x3, y3); // Upper-left glVertex2i(x4, y3); // Upper-right glVertex2i(x4, y4); // Bottom-right glVertex2i(x3, y4); // Bottom-left glEnd(); /* Exit Button */ x5 = 170; x6 = 470; y5 = 400; y6 = 450; glBegin(GL_QUADS); glVertex2i(x5, y5); // Upper-left glVertex2i(x6, y5); // Upper-right glVertex2i(x6, y6); // Bottom-right glVertex2i(x5, y6); // Bottom-left glEnd(); } public static Texture loadTexture(String key){ try { return TextureLoader.getTexture("PNG", new FileInputStream(new File("C:/Users/joshua jackson/Documents/Program/Maths/res" + key + ".png"))); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } // checks if mouse is inside buttons returns true if it is /* PLAY BUTTON */ public static boolean isInBounds(int mousex, int mousey) { if (mousex > x1 && mousex < x2 && mousey > y1 && mousey < y2) { return true; } else { return false; } } /* Settings Button */ public static boolean isInBoundstwo(int mousex, int mousey) { if (mousex > x3 && mousex < x4 && mousey > y3 && mousey < y4) { return true; } else { return false; } } /* Exit Button */ public static boolean isInBoundsthree(int mousex, int mousey) { if (mousex > x5 && mousex < x6 && mousey > y5 && mousey < y6) { return true; } else { return false; } } }
-
Re: Hey could anyone help with this code please its LWJGL
Duplicate -- locking.
Similar Threads
-
LWJGL question
By Brandon's java thingy in forum Advanced JavaReplies: 4Last Post: 01-24-2012, 04:00 AM -
LWJGL Collison
By Brandon@JavaForums in forum Advanced JavaReplies: 4Last Post: 01-14-2012, 09:16 PM -
LWJGL help please
By Brandon@JavaForums in forum Advanced JavaReplies: 12Last Post: 12-31-2011, 10:19 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


LinkBack URL
About LinkBacks

Bookmarks