package main.apis.parabola;import org.lwjgl.opengl.Display;import static org.lwjgl.opengl.GL11.*;import org.lwjgl.util.vector.Vector3f;import main.apis.parabola.Display.DisplayManager;import main.apis.parabola.Lines.Line;public class Main{ public static Vector3f [ ] xPoints; public static Vector3f [ ] yPoints; public static Line [ ] Lines; public static final int SIZE = 10; public static boolean notDrawn; public static boolean notInit; public static int sizeMid; public static void main ( String [ ] args ) { DisplayManager.CreateDisplay ( ); notInit = true; notDrawn = true; do { if ( notInit ) { Initialisation.InitArray ( ); notInit = false; } // Sets the clear colour to Red glClearColor ( 1.0f , 0 , 0 , 1.0f ); // Uses the clear colour for clearing the buffer glClear ( GL_COLOR_BUFFER_BIT ); if ( notDrawn ) { int i = 0; for ( Line line : Lines ) { // Makes sure the first index (0) isn't accessed if ( i == 0 ) { i ++ ; continue; } line.Draw ( ); } notDrawn = false; } DisplayManager.UpdateDisplay ( ); } while ( ! Display.isCloseRequested ( ) ); } }
package main.apis.parabola.Display;import org.lwjgl.LWJGLException;import org.lwjgl.opengl.ContextAttribs;import org.lwjgl.opengl.Display;import org.lwjgl.opengl.DisplayMode;import org.lwjgl.opengl.GL11;import org.lwjgl.opengl.PixelFormat;public class DisplayManager{ private static final int WIDTH = 800; private static final int HEIGHT = 600; private static final int FPS_MAX = 60; /** * Creates the Display window */ public static void CreateDisplay ( ) { // Sets the OpenGL context to OpenGL 3.2 ContextAttribs attribs = new ContextAttribs ( 3 , 2 ).withForwardCompatible ( true ) .withProfileCore ( true ); try { Display.setDisplayMode ( new DisplayMode ( WIDTH , HEIGHT ) ); Display.setTitle ( "==Parabola=Test==" ); Display.create ( new PixelFormat ( ) , attribs ); } catch ( LWJGLException e ) { e.printStackTrace ( ); } // Binds the CoOrdinate system to the window with the centre (0,0) GL11.glViewport ( 0 , 0 , WIDTH , HEIGHT ); } /** * Maintains renders to the display */ public static void UpdateDisplay ( ) { Display.sync ( FPS_MAX ); Display.update ( ); } /** * Cleans up the display resources from memory and closes the display */ public static void CloseDisplay ( ) { Display.destroy ( ); } /** * <b>USE FOR DEBUGGING ONLY!</b> * * <p> * Will remove any shaders/textures and just display a wireframe of the * polygon. * </p> * * <p> * <b>NOTE</b> <br> * Any shaders/textures applied will be visible as the WireFrame lines. * </p> */ public static void EnableWireframeMode ( ) { GL11.glPolygonMode ( GL11.GL_FRONT_AND_BACK , GL11.GL_LINE ); } /** * Used to exit WireFrame mode * * <p> * NOTE * </p> * * <p> * Don't use if WireFrame mode is enabled. It will be useless as it won't do * anything. * </p> */ public static void DisableWireframeMode ( ) { GL11.glPolygonMode ( GL11.GL_FRONT_AND_BACK , GL11.GL_FILL ); }}
package main.apis.parabola;import org.lwjgl.util.vector.Vector3f;import main.apis.parabola.Lines.Line;public class Initialisation{ public static void InitArray ( ) { // Initialises the sizes of the arrays so that SIZE can be used to show // how many // things are stored without needing to take away 1 from the value Main.xPoints = new Vector3f [ Main.SIZE + 1 ]; Main.yPoints = new Vector3f [ Main.SIZE + 1 ]; Main.Lines = new Line [ Main.SIZE + 1 ]; Main.sizeMid = Main.SIZE / 2; // X Direction Iterator int x; // Initialises the X-Axis points for ( x = 0 ; x <= Main.SIZE ; x ++ ) { Main.xPoints [ x ] = new Vector3f ( - 1 + ( x / Main.sizeMid ) , - 1.0f , 0 ); } // Y Direction Iterator int y; // Initialises the Y-Axis points for ( y = 0 ; y <= Main.SIZE ; y ++ ) { Main.yPoints [ y ] = new Vector3f ( - 1.0f , - 1 + ( y / Main.sizeMid ) , 0 ); } // Iterator for the Arrays int i; // Initialises the Lines array in Main with initialised objects for ( i = 1 ; i <= Main.SIZE ; i ++ ) { Main.Lines [ i ] = new Line ( Main.xPoints [ i ] , Main.yPoints [ i ] ); } }}
package main.apis.parabola.Lines;import static org.lwjgl.opengl.GL11.*;import org.lwjgl.util.vector.Vector3f;public class Line{ /** * The point that intersects the X-Axis */ public Vector3f xPoint; /** * The point that intersects the Y-Axis */ public Vector3f yPoint; /** * Public constructor for the class. Will set the values of xPoint and * yPoint. * * @param x * Value for xPoint * @param y * Value for yPoint */ public Line ( Vector3f x , Vector3f y ) { xPoint = x; yPoint = y; } public void Draw ( ) { glClearColor ( 0.0f , 0.0f , 0.0f , 1.0f ); glClear ( GL_COLOR_BUFFER_BIT ); glBegin ( GL_LINES ); glVertex2f ( xPoint.x , xPoint.y ); glVertex2f ( yPoint.x , yPoint.y ); glEnd ( ); } }
Exception in thread "main" java.lang.IllegalStateException: Function is not supported at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58) at org.lwjgl.opengl.GL11.glBegin(GL11.java:682) at main.apis.parabola.Lines.Line.Draw(Line.java:41) at main.apis.parabola.Main.main(Main.java:55)