Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

OpenGL 3d model not showing up on the frustum?

This topic is 2459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I've just been guided along by an brilliant programmer who has helped me load .obj models in opengl the only problem he had to go to bed before we finished it.


The problem is too me everything seems perfect yet when I compile and run the program the 3d model it doesn't show up on the frustum I don't know if its glDrawElements or if its how I'm translating it I tried different functions and different translations its gotta be something about how I'm drawing it too the screen or its not in the right location or something.


But if anyone knows please tell me I'm really dieing for it


Here is my opengl setup information


/////////////////////////////
//OpenGL - Viewport Setup
////////////////////////////

#define SCREEN_WIDTH 1240
#define SCREEN_HEIGHT 960
#define BPP 32


//Clear Color
glClearColor(0.0,0.0,0.0,0.0);

//Model View Matrix Setup
glMatrixMode(GL_MODELVIEW);
//Reset Matrix
glLoadIdentity();


//Projection Setup
glOrtho(0,1276,0,1000,-1,1);


//Projection Matrix Setup
glMatrixMode(GL_PROJECTION);

glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);



////////////////////////////////////////////////////



and here is the actual code that loads the .obj file



path p("ModelFolder");





std::vector< std::string > list;




try
{
for (directory_iterator it(p); it != directory_iterator(); ++it)
{
//cout << *it << endl;")
{
string s = (*it).path().string();

list.push_back( s );


//string output;
//io::stream<string_source> in(s);
//getline(in, output);
// assert(s == output);





// NEED TO STORE EACH ENTRY OF A FILENAME INTO A STRING
// THEN READ EACH STRING AS A FILENAME OR READ THE STRING

}
}

for(string_list::iterator it = list.begin(); it!= list.end(); it++)
{


ifstream infile((*it).c_str());

std::vector<int>faces;
std::vector<Point>points;
while (infile.good())
{
char Boxbuffer [1000];
Point p;
int face[4];

infile.getline(Boxbuffer, 1000);


switch(Boxbuffer[0])
{

case 'v':
sscanf(Boxbuffer, "v %f %f %f", &p.x, &p.y, &p.z);
points.push_back(p);
//cout << "v" << p.x << endl;
//cout << "v" << p.y << endl;
// cout << "v" << p.z << endl;
// cout << Boxbuffer << endl;

break;
case 'f':
sscanf(Boxbuffer, "f %d %d %d %d", face, face+1, face+2, face+3 );
faces.push_back(face[0]);
faces.push_back(face[1]);
faces.push_back(face[2]);
faces.push_back(face[3]);


// cout << result << endl;


}


}


//can draw the object

//glvp
//glip
//glda

//to get the pointer to data inside the vector use e.g. points.data() or faces.data()
glVertexPointer(3, GL_FLOAT, 0, points.data());
//points to go glVertexPointer(...)
//indices go to glIndexPointer(...)
//glIndexPointer(GL_DOUBLE, 0, faces.data());

//you need to give the glDrawArrays the number of points (count argument), take it as points.size()
// the glDrawArrays wants mode. your model is made up of sqares, the appropriate mode is GL_QUADS

glEnable( GL_VERTEX_ARRAY );


glPushMatrix();
glTranslatef(0, 0, -1);

//glTranslatef( -1.5f, 0.0f, -6.0f );

//glScalef(100, 100, 1);

glDrawElements(GL_QUADS, faces.size(), GL_UNSIGNED_INT, faces.data());
//glDrawArrays(GL_QUADS,0, points.size());
glPopMatrix();
glColor3f(255, 0, 0);




}

}

catch (const filesystem_error& ex)
{
// cout << ex.what() << endl;
}

// cout << list.size() << endl;

}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!