LWJGL 2.9.3 function not supported error for glBegin

Started by JamesYeoman, October 30, 2016, 12:55:00

Previous topic - Next topic

JamesYeoman

I have not had this error ever for LWJGL and I have been using it for about 4 months now. I have used glBegin before and had no problems with it.

Below is the code of my project but allow me to explain the project first...
I am trying to make a simple program that will draw a Parabola using the drawing trick: URL To The Site.

I have worked out the logic and all of that but for some reason, it rejects glBegin...

Main.java
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 ( ) );
	}
	
}


DisplayManager.java
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 );
	}
}


Initialisation.java
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 ] );
		}
	}
}


Line.java
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 ( );
		
	}
	
}


Error Message
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)

Kai

The OpenGL 3.2 Core Profile, which you are using, forbids the use of glBegin/glEnd, together with everything from the fixed-function pipeline (FFP).

JamesYeoman

Thanks. I am more used to 3.2+ and VBOs etc but it requires some boilerplate code to be able to declare and make dynamically etc... I thought I might be able to get away with this method but... I guess I'll have to give up the shortcuts and do it properly... Thank you again