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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:24:36+00:00 2026-06-12T12:24:36+00:00

How do I render a .obj file (in 3d)? And how do I add

  • 0

How do I render a .obj file (in 3d)? And how do I add color to that? I’m on an OS X, and using XCode 4. Here’s my little ‘test lab’.

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

void render(void);

void keyboard(unsigned char c, int x, int y);

void mouse(int button, int state, int x, int y);

int main(int argc, char ** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Simple GLUT Application");

    glutDisplayFunc(render);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);

    glutMainLoop();
}

void keyboard(unsigned char c, int x, int y) {
    if (c == 27){
        exit(0);
    }
}

void mouse(int button, int state, int x, int y) {
    if (button == GLUT_RIGHT_BUTTON){
        exit(0);
    }
}

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

    //RENDER STUFF HERE
    glBegin(GL_POLYGON);
    glVertex3f(  0.0, -0.8,  0.5);
    glVertex3f(  0.0,  0.2,  0.5);
    glVertex3f(  0.5,  0.8, -0.5);
    glVertex3f(  0.5, -0.2, -0.5);
    glEnd();

    glutSwapBuffers();
}
  • 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-12T12:24:38+00:00Added an answer on June 12, 2026 at 12:24 pm

    OpenGL is a low level 3D API. It doesn’t have high level features like loading model files. So to render a .obj file you’ll write code to load the data yourself and then write OpenGL code that draws the polygons you’ve loaded.

    There are a few ways to add colors and textures to the OpenGL primitives you draw. Your current code uses OpenGL in ‘immediate mode’, and the immediate mode method of adding color is to set the color using glColor*() functions before producing a vertex.

    glBegin(GL_TRIANGLES);
    glColor3f(   1.0,  0.0,  0.0);
    glVertex3f(  0.0, -0.8,  0.5);
    glColor3f(   0.0,  1.0,  0.0);
    glVertex3f(  0.0,  0.2,  0.5);
    glColor3f(   0.0,  0.0,  1.0);
    glVertex3f(  0.5,  0.8, -0.5);
    glEnd();
    

    In the last few years there have been some significant changes to the OpenGL API. OpenGL tutorials you find online frequently cover the older methods of using OpenGL. I would strongly recommend picking up the latest edition of the book OpenGL SuperBible: Comprehensive Tutorial and Reference. It covers modern usage of OpenGL (i.e., a non-immediate mode) in detail, including a chapter on using OpenGL with OS X’s native windowing API, Cocoa.

    Although the 5th edition (the latest at the time of this writing) of the OpenGL Superbible was written somewhat before the new OpenGL stuff was supported in OS X, the new features have since been added. You’ll need to read Apple’s docs on enabling the “OpenGL Core Profile” in Cocoa or OS X’s implementation of GLUT to use them.

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

Sidebar

Related Questions

How to add texture in .obj file from .mtl file because libgdx can't render
I have a very simple program, that loads an wavefront obj file, rotate and
I want to render an object imported from wavefront obj file. The object has
I've a face.obj and face.mtl file. But libgdx doesn't allow me to render face.mtl
Aloha, I have a 8MB XML file that I wish to deserialize. I'm using
How to render partial view in some specific div without using ajax in asp.net
I want to render the partial view using ajax. When I submit the button,
I use RenderAction to render a partial that is used all over my site.
i am using django endless pagination . its working normally that just shows the
I'm currently working on a project that involves a CSV file. I initially was

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.