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

  • SEARCH
  • Home
  • 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 7731219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:25:34+00:00 2026-06-01T06:25:34+00:00

For some reason i cant draw anything past z>1 in openGL. The Z buffer

  • 0

For some reason i cant draw anything past z>1 in openGL.
The Z buffer works fine, I’m stuck on this for a while now.
I thought that the problem was the gluPerspective, but its still not working.
I can see anything between 0 and 1, the triangle of the code apears clipped.
Sorry for my poor english.

#include <iostream>
#include <GL/glut.h>

using namespace std;

void idle() {
    glutPostRedisplay();
}

void changeSize(int w, int h) {

    // Prevent a divide by zero, when window is too short
    // (you cant make a window of zero width).
    if(h == 0)
        h = 1;
    float ratio = 1.0* w / h;

    // Use the Projection Matrix
    glMatrixMode(GL_PROJECTION);

        // Reset Matrix
    glLoadIdentity();

    // Set the viewport to be the entire window
    glViewport(0, 0, w, h);

    // Set the correct perspective.
    gluPerspective(0, ratio, 0.1, 1000.0);

    // Get Back to the Modelview
    glMatrixMode(GL_MODELVIEW);
}

void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    glBegin(GL_TRIANGLES);
        glVertex3f(-0.5,-0.5,0.0);
        glVertex3f(0.5,0.0,0.0);
        glVertex3f(0.0,0.5,2.0);
    glEnd();

    glutSwapBuffers();
}

int main(int argc, char **argv) {

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(800,600);
    glutCreateWindow("OpenGL");

    glutDisplayFunc(renderScene);
    glutReshapeFunc(changeSize);
    glutIdleFunc(idle);

    glEnable(GL_DEPTH_TEST);

    glutMainLoop();

    return 0;
}
  • 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-01T06:25:36+00:00Added an answer on June 1, 2026 at 6:25 am

    First of all, your gluPerspective has a value of zero for fovy, which is completely nonsensical. Try putting a nominal value for field of view (maybe 60).

    Secondly, with that being fixed, I don’t think any of your three vertices should be visible. Provided that you have no view matrix (there’s none shown), the first two vertices should be clipped by the near plane. For the third vertex you probably mean for it to be at -2, not 2 (the default eye looks down the negative z axis). So this vertex is also behind the eye.

    Frankly I’m surprised that you were able to see anything at all, but see if correcting these things helps. Try drawing your triangle with z values of -0.2, -0.2, and -2.0.

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

Sidebar

Related Questions

For some reason i cant get my model to work.. never had this problem
Im working on responsive code just now and for some reason i cant get
for some reason i cant get the string that are inside the strings.xml. this
Newbie question here but for some reason I cant figure this out. I have
For some reason, I can't get pyglet to draw sprites. Here's my code: import
For some reason I can't get this to work. It pulls the name and
For some reason I can't get this script to run when I add the
for some reason I cant get my events to have start and end on
The below code works, but for some reason the $('#chart').fadeTo callback seems to create
For some reason I cant call a function thats inside my settings method into

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.