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 8968059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:23:06+00:00 2026-06-15T17:23:06+00:00

I am trying to make it so that the cubes will render properly, but

  • 0

I am trying to make it so that the cubes will render properly, but the tops and bottoms of the cubes are refusing to work right.

code here:

package com.blazingkin.threeDee.thisguy;

import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.util.glu.GLU.gluPerspective;

import java.util.Random;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;


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

    public void walkForward(float distance)
    {
        x -= distance * (float)Math.sin(Math.toRadians(pitch));
        z += distance * (float)Math.cos(Math.toRadians(pitch));
    }
    public void walkBackwards(float distance)
    {
        x += distance * (float)Math.sin(Math.toRadians(pitch));
        z -= distance * (float)Math.cos(Math.toRadians(pitch));
    }

    public void strafeLeft(float distance)
    {
        x -= distance * (float)Math.sin(Math.toRadians(pitch-90));
        z += distance * (float)Math.cos(Math.toRadians(pitch-90));
    }

    //strafes the camera right relitive to its current rotation (yaw)
    public void strafeRight(float distance)
    {
        x -= distance * (float)Math.sin(Math.toRadians(pitch+90));
        z += distance * (float)Math.cos(Math.toRadians(pitch+90));
    }

    public void lookThrough()
    {
        //roatate the pitch around the X axis
        GL11.glRotatef(yaw, 1.0f, 0.0f, 0.0f);
        //roatate the yaw around the Y axis
        GL11.glRotatef(pitch, 0.0f, 1.0f, 0.0f);
        //translate to the position vector's location
        GL11.glTranslatef(x, -y, z);
    }

    int screenX = 800;
    int screenY = 600;
    int displayType = 0;
    long timePassed = 0L;
    long lastTime;
    float x, y, z = 0;
    float pitch, yaw= 0;
    boolean mouseLocked = true;

    public void start(){
        try {
            DisplayMode d = new DisplayMode(screenX, screenY);
            Display.setDisplayMode(d);
            Display.setVSyncEnabled(true);
            if (displayType == 1){
                System.setProperty("org.lwjgl.opengl.Window.undecorated","true");
                Display.setFullscreen(true);
            }else{
                System.setProperty("org.lwjgl.opengl.Window.undecorated","false");
            }
            if (displayType == 2){
                Display.setFullscreen(true);
            }
            Display.create();
        } catch (LWJGLException e) {
            e.printStackTrace();
            System.exit(0);
        }
        lastTime = System.currentTimeMillis();


        // init OpenGL here
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        gluPerspective((float)90,(float)screenX/(float)screenY,0.001f,100);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        Point[] points = new Point[100];
        Random r = new Random();
        for (int i = 0; i < points.length; i++){
            points[i] = new Point((r.nextFloat() - 0.5F) * 100,(r.nextFloat() - 0.5F) * 100, r.nextInt(200) - 200);
        }
        float speed = 0.2f;
        while (!Display.isCloseRequested()) {



            glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);   
            if (Keyboard.isKeyDown(Keyboard.KEY_D)){
                strafeRight(speed);
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_A)){
                strafeLeft(speed);
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_W)){
                walkForward(speed);
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_S)){
                walkBackwards(speed);
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
                y+=speed;
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
                y-=speed;
            }
            while (Keyboard.next()){

                if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
                    mouseLocked =! mouseLocked;
                }
            }
            if (Display.isActive()){
                if (mouseLocked){
                    Mouse.setCursorPosition(screenX/2, screenY/2);
                    yaw -= Mouse.getDY();
                    pitch += Mouse.getDX();
                }
            }
            yaw = yaw<-80?-80:yaw;
            yaw = yaw>80?80:yaw;
            pitch = pitch>360?pitch%360:pitch;
            pitch = pitch<-360?(pitch%360)*-1:pitch;

            GL11.glLoadIdentity();
            lookThrough();

            System.out.println(x+", "+y+", "+z);
                for (Point p: points){
                            GL11.glColor3f(1, 0, 1);
                            glBegin(GL11.GL_POLYGON);
                            //top face
                            GL11.glVertex3f(p.x, p.y+2, p.z);
                            GL11.glVertex3f(p.x, p.y+2, p.z+2);
                            GL11.glVertex3f(p.x+2, p.y+2, p.z+2);
                            GL11.glVertex3f(p.x+2, p.y+2, p.z);
                        glEnd();    
                            GL11.glColor3f(1,1,1);
                            glBegin(GL11.GL_POLYGON);
                            //bottom face

                                GL11.glVertex3f(p.x, p.y, p.z);
                                GL11.glVertex3f(p.x, p.y, p.z+2);
                                GL11.glVertex3f(p.x+2, p.y, p.z+2);
                                GL11.glVertex3f(p.x+2, p.y, p.z);
                            glEnd();



                    GL11.glColor3f(1, 0, 0);
                    glBegin(GL11.GL_POLYGON);
                        //back
                        GL11.glVertex3f(p.x, p.y, p.z);
                        GL11.glVertex3f(p.x+2, p.y, p.z);
                        GL11.glVertex3f(p.x+2, p.y+2, p.z);
                        GL11.glVertex3f(p.x, p.y+2, p.z);
                    glEnd();


                    GL11.glColor3f(0, 0, 1);
                    glBegin(GL11.GL_POLYGON);
                    //side 1 face (left)
                        GL11.glVertex3f(p.x, p.y, p.z);
                        GL11.glVertex3f(p.x, p.y, p.z+2);
                        GL11.glVertex3f(p.x, p.y+2, p.z+2);
                        GL11.glVertex3f(p.x, p.y+2, p.z);
                    glEnd();
                    GL11.glColor3f(1, 1, 0);
                    glBegin(GL11.GL_POLYGON);
                    //side 2 face (right)
                        GL11.glVertex3f(p.x+2, p.y, p.z);
                        GL11.glVertex3f(p.x+2, p.y, p.z+2);
                        GL11.glVertex3f(p.x+2, p.y+2, p.z+2);
                        GL11.glVertex3f(p.x+2, p.y+2, p.z);
                    glEnd();
                    GL11.glColor3f(0, 1, 1);
                    glBegin(GL11.GL_POLYGON);
                    //front
                        GL11.glVertex3f(p.x, p.y, p.z+2);
                        GL11.glVertex3f(p.x+2, p.y, p.z+2);
                        GL11.glVertex3f(p.x+2, p.y+2, p.z+2);
                        GL11.glVertex3f(p.x, p.y+2, p.z+2);
                    glEnd();


                }





            Display.update();
        }

        Display.destroy();
    }


    class Point{
        float x,y,z;
        public Point(float x, float y, float z){
            this.x = x;
            this.y = y;
            this.z = z;
        }

    }


}

Basically, it is rendering the bottom of the cube where the top should be, but only when you are underneath it and when you are inside it it all renders correctly

  • 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-06-15T17:23:08+00:00Added an answer on June 15, 2026 at 5:23 pm

    It could be a problem of depth testing. You don’t enable a depth double-check anywhere! Try this:

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    

    That worked for me. Without that, things looked REALLY odd, let me know if this helps!

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

Sidebar

Related Questions

I'm trying to make a method that will draw a cube with a specified
im trying to make input that automaticaly change to decimel while typing number but
I am trying to make something that will enable all controls if a SubString
Im trying to make a function that will return an element of type point:
Im trying to make multiple quizes that will keep track of each quiz on
Short question: I'm trying to make that in a given page (uses tabs) back
I have a WordPress blog and I'm trying to make that when a user
I'm trying to make sure that my Managed to Unmanaged calls are optimized. Is
I am trying to make Layout that contains 2 layout, vertical and horizontal scrolls.
Im trying to make a program that retrieves an endless amount of numbers that

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.