LWJGL Graphics Flow Question

So I want to start doing stuff with OpenGL using LWJGL.

I understand the basic way of setting up a window, openGL, rendering loop.

But in all the tutorials I have read, not one shows how to render with OpenGL outside of a class. Its all hard coded.

The flow in java using the Graphics object basically goes

tell objects to draw themselves by passing them the Graphics object from your draw method.

Example:


public void drawSelf( Graphics g )
	{
		if(alive)
		{
			double x1 = (int)size >> 1;
                        double y1 = (int)size >> 1;
                        Graphics2D g2d = (Graphics2D)g.create();
			Composite alphaComp = AlphaComposite.getInstance(
                               AlphaComposite.SRC_OVER, (float) fade);
			g2d.setComposite(alphaComp);
			g2d.drawImage(texture, (int)(loc.x - x1), (int)(loc.y - y1), (int)size, (int)size, null);
			g2d.dispose();
		}
	}

So what is the flow for OpenGl? I know how to hardcode something in it like this

Example:


while (!Display.isCloseRequested()) 
        {
 
        	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);	
        	 
    	    GL11.glColor3f(0.2f,0.1f,1.0f);
    	    
    	    GL11.glBegin(GL11.GL_QUADS);
	        	GL11.glVertex2f(100,100);
	        	GL11.glVertex2f(100+200,100);
	        	GL11.glVertex2f(100+200,100+200);
	        	GL11.glVertex2f(100,100+200);
	        GL11.glEnd();
 
        	Display.update();
		}

But how would you draw say a list of square objects?

Can you not pass them the resources they need to draw themselves?

Do you have to get their drawing information and then use that to drraw them?

I am lost and any help would be fantastic.

Since all LWJGL methods are static, there is no Graphics2D object to pass around. So you can still have the standard game loop (update() -> render() -> sleep() and restart) and each of your Entities’s render methods would basically just call OpenGL functions. Think of GLXX as your Graphics2D class except all the methods you can use are static.

Well that makes things seem really simple.

Although I have a feeling that doing it that way is going to byte me in the ass. :smiley:

I don’t know how but it will.

The OpenGL methods can be static (partly) because they can only be accessed from a single thread: the thread that owns the OpenGL context. It’s also only possible to draw to a single “image” at a time, so having multiple GL objects would not make much sense.

Just because you can call the static OpenGL methods from any class doesn’t mean that you SHOULD call them from any class. Try to keep everything as clean as possible. =)

it will, when you become overjoyed and forget which class should drawing and not.