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

The Archive Base Latest Questions

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

While attempting to render a 3D object using OpenGL (and the GLFW library), the

  • 0

While attempting to render a 3D object using OpenGL (and the GLFW library), the model experiences lots of flickering. Im reading the .obj file using a library that I’ve written on my own.

Written below is my render function:
Unfortunately, in order to understand how faces and vertices are being inputted, I will have to provide all my code, which is linked:
Zipped code along with executable and sample .obj:
Source

Im using .obj files from here to test the program. Right now, the program doesn’t support normals and textures, which isnt an issue since most of the models on the site dont have them. Also, (right now) it only reads from “123.obj” so the file should’nt be named anything else. And it only accepts a single space, not more than that.

 float render()
    {
        glfwSetTime(0.0f);
        int win_width;
        int win_height;
        glfwGetWindowSize(&win_width, &win_height);
        float win_aspect = (float)win_width / (float)win_height;
        glViewport(0, 0, win_width, win_height);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90, win_aspect, 0, 100.0);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(0, 0, 50.0, 0, 0, 0, 0.0, 1.0, 0.0);

        glEnable(GL_DEPTH);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_NORMALIZE); 
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glRotatef(angle , 0 , 1, 0);
        glColor3f(0.0f, 0.0f, 0.0f);
        int index = 0;
        for(int a = 0; a < faces.size(); a++)
        {
            if(faces[a].vertices.size() == 3)
            {
                glBegin(GL_TRIANGLES);
            }
            else
            {
                glBegin(GL_QUADS);
            }
            for(int b = 0; b < faces[a].vertices.size(); b++)
            {
                index = faces[a].vertices[b];
                glVertex3f(vertices[index].Dimensions[_x], vertices[index].Dimensions[_y], vertices[index].Dimensions[_z]);
            }
            glEnd();
        }
        glfwSwapBuffers();
        return (float)glfwGetTime();
  • 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-26T10:02:00+00:00Added an answer on May 26, 2026 at 10:02 am

    Here’s the problem

    gluPerspective(90, win_aspect, 0, 100.0);
    

    You cannot set 0 as your nearclip, set it to something larger like 0.1, or 1.0.

    gluPerspective(90, win_aspect, 1.0, 100.0);
    

    With nearclip at 0, all of your depths get mapped to z = 1, and you get z fighting.

    EDIT : if you’re interested, here’s some theory on perspective depth:

    For a given distance from the camera x, your perspective transform outputs a certian depth value z. At the farclip, this value will be the maximum of 1, and at nearclip it will be 0.
    Between these values however, relationship is not linear like you may expect. The curve looks similar to the following diagrams:

    Diagram

    When you go to the extreme of setting your nearclip to 0, your curve is heavily warped, so now all distances map to z = 1.

    Because of all this, you should also try to keep the ratio far:near smaller than 10000:1

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

Sidebar

Related Questions

I've been attempting to render text onto an openGL window using SDL and the
Note : No MFC No ATL Using Visual C++ While attempting a connection between
While attempting to execute SQL insert statements using Oracle SQL Developer I keep generating
I'm attempting to render RTF documents using the WPF RichTextBox control. So far, the
so I added all the jars from jMock 2.5.1 While attempting to follow http://www.ibm.com/developerworks/opensource/library/os-eclipse-rmock/index.html
While attempting to access a test portal, I'm encountering the following problem while using
EDIT: SOLVED I encountered a problem while attempting to render into a texture. I
I'm having some problems while attempting to serialize a libxml2 object in python. In
I am using centOS 5 server. i got the error while i was attempting
While attempting to cross-compile ICU using android-ndk-r7 in Linux, the following error occurs after

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.