Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6752009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:40+00:00 2026-05-26T12:59:40+00:00

I have spent about 2 Days trying to find out how to make 3d

  • 0

I have spent about 2 Days trying to find out how to make 3d objects using lwjgl, and have found nothing. I can easily render 2d objects, and when I tried to render 3d objects, either the program crashed, or a black screen was opened, right now, I’m using Eclipse, and I’m running it in that environment (I don’t know if that’s the problem). If someone could point me towards a good tutorial, or just give me an explanation of what I’m doing wrong, that would be appreciated. Here’s my code:

    import org.lwjgl.LWJGLException;
    import org.lwjgl.opengl.Display;
    import org.lwjgl.opengl.DisplayMode;
    import org.lwjgl.opengl.GL11;

    public class Objects {
        public static void main(String[] args) {
            Objects objects = new Objects();
            objects.start();
        }

        public void start() {
            try {
                Display.setDisplayMode(new DisplayMode(800, 600));
                Display.create();
            } catch (LWJGLException e) {
                e.printStackTrace();
                System.exit(0);
            }

            initGL();

            while(!Display.isCloseRequested) {
                Cube();

                Display.update();
            }

            Display.destroy();
        }

        public void initGL() {
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GL11.glOrtho(0, 800, 600, 0, 1, -1);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);

            return;
        }

        public void cube() {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

            //front face

            GL11.glColor3d(0.0, 1.0, 1.0);
            GL11.glVertex3d(1.0, 1.0, -1.0);
            GL11.glVertex3d(-1.0, 1.0, -1.0);
            GL11.glVertex3d(-1.0, -1.0, -1.0);
            GL11.glVertex3d(1.0, -1.0, -1.0);

            //side face

            GL11.glColor3d(1.0, 0.0, 0.0);
            GL11.glVertex3d(1.0, 1.0, -1.0);
            GL11.glVertex3d(1.0, 1.0, -3.0);
            GL11.glVertex3d(1.0, -1.0, -3.0);
            GL11.glVertex3d(1.0, -1.0, -1.0);

            ...(I kept going like this for the rest of the faces)

             return;
         }

***************EDIT***************

I have read both of your answers, and have made a java lwjgl code based on it, however when I tried to run it in the Eclipse environment, it gave me the error:

usage:
XPMFile <file>
java.lang.ArrayIndexOutOfBoundsException: 0
at org.lwjgl.util.XPMFile.main(XPMFile.java:260)

So, once again here’s my code:

    package testing;

    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 CubeRender {
        public static void main(String[] args) {
            CubeRender cube = new CubeRender();
            cube.start();
        }

        public void start() {
            try {
                Display.setDisplayMode(new DisplayMode(800, 600));
                Display.create();
            } catch(LWJGLException e) {
                e.printStackTrace();
                System.exit(0);
            }

            initGL();

            while(!Display.isCloseRequested()) {
                renderCube();

                Display.update();
            }

            Display.destroy();
        }

        public void initGL() {
            GL11.glMatrixMode(GL11.GL_PROJECTION);

            GL11.glLoadIdentity();

            GLU.gluPerspective(45, 100, 1, 100);
            GL11.glEnable(GL11.GL_DEPTH_TEST);
            GL11.glDepthFunc(GL11.GL_LEQUAL);

            GL11.glMatrixMode(GL11.GL_MODELVIEW);
        }

        public void renderCube() {
            double x = 1;
            double y = 1;
            double z = -1;

            //front face

            GL11.glBegin(GL11.GL_QUADS);

            GL11.glNormal3d(0, 0, 1);

            GL11.glColor3d(0.0, 1.0, 1.0);
            GL11.glVertex3d(x, y, z);
            GL11.glVertex3d(x-2, y, z);
            GL11.glVertex3d(x-2, y-2, z);
            GL11.glVertex3d(x, y-2, z);

            GL11.glEnd();

            //right face

            GL11.glBegin(GL11.GL_QUADS);

            GL11.glNormal3d(-1, 0, 0);

            GL11.glVertex3d(x, y, z);
            GL11.glVertex3d(x, y, z-2);
            GL11.glVertex3d(x, y-2, z-2);
            GL11.glVertex3d(x, y-2, z);

            GL11.glEnd();

            return;
        }
    }

******EDIT 2******
if you have anything to contribute for the above answer please post answers here:
How to import lwjgl_util

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:59:41+00:00Added an answer on May 26, 2026 at 12:59 pm

    Your using a 2d orthographic view see the following line “GL11.glOrtho(0, 800, 600, 0, 1, -1);” which clips everything to 1, -1 axis for the 3rd dimension.

    What you really need to be looking at is a setting up a 3d view, likely using glFrustum or gluPerspective instead of glOrtho.

    Although old now, you should have a quick read of the Nehe Tutorials at http://nehe.gamedev.net/ with some LWJGL ports of the first few found at http://ninjacave.com/nehetutorials

    Do keep in mind that the Nehe tutorials use classic OpenGL is which pretty much depreciated for modern opengl, however it doesn’t hurt to know how classic opengl works. Its better you google for some newer OpenGL tutorials that use techniques such as shaders and VBO’s, I’d recommend that you get some books like the OpenGL Red Book, Orange Book or OpenGL Super Bible. Alternatively have a look at the links and resources page on the LWJGL Wiki, it should point you to a ton of opengl resources and tutorials.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent several days now researching Hibernate and have several small questions about
I have spent last 3 days until I got gps working on android using
I've spent two days on this and have gotten nowhere. I'm trying to use
I am a little confused about when do I have to serialize objects using
I spent days to search about this topic and I found some good articles,
I have spent the last few days trying to look up how to use
I’ve got a pyparsing issue that I have spent days trying to fix, with
I have now spent 2 days trying to get this going. I am however
I have spent 3 days reading and doing tutorials about PHP upload scripts for
I have spent a few days learning Objective-C and have a few questions about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.