Cube decided not to participate.

All I’m trying to do is display a 3D cube with Ortho and I have no idea but nothing appears. although everything is in range O.o it has confused me to the next level to the point of > 9000

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class shadows{
	public static double angle = 0;
	
	public static void init(){
		try {
			Display.create();
			Display.setDisplayMode(new DisplayMode(800, 600));
			Display.setTitle("");
			
			GL11.glMatrixMode(GL11.GL_PROJECTION);
			GL11.glLoadIdentity();
			GL11.glOrtho(-10, 10, -10, 10, 10, -10);
			GL11.glMatrixMode(GL11.GL_MODELVIEW);
			GL11.glLoadIdentity();
			
			GL11.glEnable(GL11.GL_DEPTH_TEST);
		} catch (LWJGLException e) {
			e.printStackTrace();
		}
		
		
	}

	public static void renderLoop(){
		while(!Display.isCloseRequested()){
			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
			GL11.glClearColor(0, 0, 1, 1);
			GL11.glLoadIdentity();
			
			GL11.glColor3d(1,	1, 1);
			GL11.glBegin(GL11.GL_QUADS);
				// front
				GL11.glVertex3f(-1, -1, 1);
				GL11.glVertex3f(-1,  1, 1);
				GL11.glVertex3f( 1,  1, 1);
				GL11.glVertex3f( 1, -1, 1);
				//back
				GL11.glVertex3f(-1, -1, -1);
				GL11.glVertex3f(-1,  1, -1);
				GL11.glVertex3f( 1,  1, -1);
				GL11.glVertex3f( 1, -1, -1);
				// right
				GL11.glVertex3f( 1, -1, 1);
				GL11.glVertex3f( 1,  1, 1);
				GL11.glVertex3f( 1,  1,-1);
				GL11.glVertex3f( 1, -1,-1);
				// left
				GL11.glVertex3f(-1, -1, 1);
				GL11.glVertex3f(-1,  1, 1);
				GL11.glVertex3f(-1,  1,-1);
				GL11.glVertex3f(-1, -1,-1);
				// bottom
				GL11.glVertex3f(-1, -1, 1);
				GL11.glVertex3f(-1, -1,-1);
				GL11.glVertex3f( 1, -1,-1);
				GL11.glVertex3f( 1, -1, 1);
				// Top
				GL11.glVertex3f(-1,  1, 1);
				GL11.glVertex3f(-1,  1,-1);
				GL11.glVertex3f( 1,  1,-1);
				GL11.glVertex3f( 1,  1, 1);
			GL11.glEnd();
			
			Display.update();
			Display.sync(30);
			System.out.println("Frame Rendered");
		}
		cleanup();
	}
	
	public static void cleanup(){
		Display.destroy();
	}
	public static void main(String[] args){
		init();
		renderLoop();
		System.exit(0);
	}
}

For 2D rendering you normally use this line:
GL11.glOrtho(0, Panel.getWidth(), Panel.getHeight(), 0, mindepth, maxdepth);

I dont know what all these 10 and -10 are supposed to do.
Also the cube is really small, but i guess that can be fixed by choosing a smaller glortho.


void glOrtho(
	GLdouble  	left,
 	GLdouble  	right,
 	GLdouble  	bottom,
 	GLdouble  	top,
 	GLdouble  	nearVal,
 	GLdouble  	farVal);

I think the main problem here is I don’t understand why I can’t have the values at -10 to 10 in Ortho and still work normally…

try doing glViewport(0, 0, 800, 600); right after creating the display.

Always start with the most simple code you can imagine. Why not render a triangle or quad first? Then you have at least something on screen, and work from there.

You can look at this tutorial:

Ignore everything about vertex arrays and vertex buffer objects - one of the first methods shows how to draw a triangle.

VICTORY, view port has fixed it, but if you don’t mind me asking… Why?

I didn’t want to create a new topic about this so I’ll paste the question here

When it comes to placing the values into glLight with a buffer, the majority of the tutorials I don’t understand why we don’t just place things directly into a FloatBuffer instead of a ByteBuffer.


ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16);
byteBuffer.order(ByteOrder.nativeOrder( ) );
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer) byteBuffer.asFloatBuffer().put(light0Position).flip());
	

instead of


private FloatBuffer lightPosition;
lightPosition = BufferUtils.createFloatBuffer(4);
lightPosition.put(1.0f).put(1.0f).put(1.0f).put(0.0f).flip();
glLight(GL_LIGHT0, GL_POSITION, lightPosition);                         // sets light positio

The viewport is set automatically to whatever the display resolution is set to when created.
but you set the resolution after creating the window, so you had to set it manually.