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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:59:42+00:00 2026-06-13T22:59:42+00:00

am trying to load an obj model : # 3ds Max Wavefront OBJ Exporter

  • 0

am trying to load an obj model :

# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 05.11.2012 20:07:48

mtllib test.mtl

#
# object Box001
#

v  -12.6264 0.0000 -58.6877
v  -12.6264 0.0000 6.8357
v  43.9557 0.0000 6.8357
v  43.9557 0.0000 -58.6877
v  43.9557 -51.9219 6.8357
v  -12.6264 -51.9219 6.8357
v  -12.6264 -51.9219 -58.6877
v  43.9557 -51.9219 -58.6877
# 8 vertices

vn 0.0000 1.0000 -0.0000
vn 0.0000 -1.0000 -0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
vn -1.0000 0.0000 -0.0000
# 6 vertex normals

vt 0.0000 65.5234 0.0000
vt 0.0000 0.0000 0.0000
vt 56.5821 0.0000 0.0000
vt 56.5821 65.5234 0.0000
vt 0.0000 -51.9219 0.0000
vt 56.5821 -51.9219 0.0000
vt 65.5234 0.0000 0.0000
vt 65.5234 -51.9219 0.0000
# 8 texture coords

g Box001
usemtl wire_229154215
s 2
f 1/1/1 2/2/1 3/3/1 4/4/1 
s 4
f 5/2/2 6/3/2 7/4/2 8/1/2 
s 8
f 3/3/3 2/2/3 6/5/3 5/6/3 
s 16
f 4/7/4 3/2/4 5/5/4 8/8/4 
s 32
f 1/3/5 4/2/5 8/5/5 7/6/5 
s 64
f 2/7/6 1/2/6 7/5/6 6/8/6 
# 6 polygons

I have a class called Model :

#ifndef _Model_H_
#define _Model_H_

#include <vector>

struct Coordinate{
    float X,Y,Z;
    Coordinate(float x,float y,float z);
};

struct TextureCoordinate{
    float U,V;
    TextureCoordinate(float u,float v);
};

struct Face
{
    int VertexIndex,TextureIndex,NormalIndex;

    Face(int vi, int ti, int ni);

};

class Model
{
public:
    Model(void);
    ~Model(void);
    bool IsTriangle;
    std::string Name;
    std::vector<Coordinate> Vertices;
    std::vector<Coordinate> VerticesNormals;
    std::vector<Coordinate> VerticesTexture;
    std::vector<Face      > Faces;
    int ModelNumber;
};

#endif

and am trying to load it like this :-

Model ModelsLoader::LoadModel(const char * ModelName){
    std::ifstream fs(ModelName);
    char temp[256];
    std::string * line;
    Model m;
    float tempX,tempY,tempZ;
    int tempA1,tempA2,tempA3,tempA4;

    if(fs.is_open()){

        while (!fs.eof())
        {
            fs.getline(temp,256);
            Lines.push_back(new std::string(temp));
        }
        int c,slashes;
        for (int i = 0; i < Lines.size(); i++)
        {
            line = Lines[i];

            if(line->size() == 0 ||(*line)[0] == '#' ) continue;
            else if((*line)[0] == 'v' && (*line)[1] == ' ')
            {
                sscanf(line->c_str(),"v %f %f %f",&tempX,&tempY,&tempZ); 
                m.Vertices.push_back( Coordinate(tempX,tempY,tempZ));
            }
            else if((*line)[0] == 'v' && (*line)[1] == 't'){
                sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ); 
                m.VerticesTexture.push_back( Coordinate(tempX,tempY,tempZ));
            }
            else if((*line)[0] == 'v' && (*line)[1] == 'n'){
                sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ); 
                m.VerticesNormals.push_back( Coordinate(tempX,tempY,tempZ));
            }
            else if((*line)[0] == 'f' && (*line)[1] == ' ')
            {
                c = std::count(line->begin(),line->end(),' ') - 1;
                slashes = std::count(line->begin(),line->end(),'/');

                if( slashes / c == 2){
                    int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12;
                    sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9,&i10,&i11,&i12);
                    m.Faces.push_back(Face(i1-1,i2-1,i3-1));
                    m.Faces.push_back(Face(i4-1,i5-1,i6-1));
                    m.Faces.push_back(Face(i7-1,i8-1,i9-1));
                    m.Faces.push_back(Face(i10-1,i11-1,i12-1));
                    m.IsTriangle = false;
                }
                else if (slashes / c == 3)
                {
                    int i1,i2,i3,i4,i5,i6,i7,i8,i9;
                    sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9);
                    m.Faces.push_back(Face(i1-1,i2-1,i3-1));
                    m.Faces.push_back(Face(i4-1,i5-1,i6-1));
                    m.Faces.push_back(Face(i7-1,i8-1,i9-1));
                    m.IsTriangle = true;
                }

            }
        }
        fs.close();
        m.ModelNumber = glGenLists(1);
        glNewList(m.ModelNumber, GL_COMPILE);
        for (int i = 0; i < m.Faces.size(); i++)
        {
            if(m.IsTriangle){
            }
            else
            {
                glBegin(GL_QUADS);
                for (int i = 0; i < m.Faces.size(); i++)
                {
                    glVertex3f(m.VerticesNormals[m.Faces[i].NormalIndex].X,m.VerticesNormals[m.Faces[i].NormalIndex].Y,m.VerticesNormals[m.Faces[i].NormalIndex].Z);
                    glNormal3f(m.Vertices[m.Faces[i].VertexIndex].X,m.Vertices[m.Faces[i].VertexIndex].Y,m.Vertices[m.Faces[i].VertexIndex].Z);
                }
                glEnd();
            }
        }
        glEndList();
    }

    Clear();
    return m;
}

now when I call the list it’s not showing anything:-

void drawScene() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
    glLoadIdentity(); //Reset the drawing perspective

    camera();

    glCallList(model.ModelNumber);

    glutSwapBuffers(); //Send the 3D scene to the screen
}

what am doing worng here!?

  • 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-13T22:59:42+00:00Added an answer on June 13, 2026 at 10:59 pm

    Make sure you’re calling ModelsLoader::LoadModel() after you create an OpenGL context via glutCreateWindow().

    If you call LoadModel() before you have a current GL context all the GL calls inside it will fail.

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

Sidebar

Related Questions

I'm trying to load a .obj File in Java with lwjgl without using any
I have a problem trying to load a 3d object from a wavefront file
Trying to load a small .txt file into mysql but get all my data
Here are some models I am trying to load data for: class School(models.Model): name
Is there some sort of try/catch function in obj-c? I'm trying to load saved
Hey all. I'm really new at this obj-c/xcode stuff. I'm trying to load the
im new to obj-c, and need help im trying to dynamically load data (10
I am trying to load .clp file in my iPhone application. For that I
i am trying to write a c++ opengl application to load .OBJ files and
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine

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.