tom384

03-12-2010, 10:02 AM

I am having trouble running my OpenGL program, as my calls to glVertex3f don't seem to be drawing anything.

My vertex class 'Ver' is:

class Ver {

public:

// ATTRIBUTES

std::vector<float> v_coord;

// CONSTRUCTORS

Ver();

Ver(float, float, float);

// ACCESSORS

std::vector<float>& get_coord();

};

This is the code for drawing the scene:

int DrawGLScene(GLvoid)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glLoadIdentity(); // Reset The View

glBegin(GL_TRIANGLES);

character.view(); // member function of my character class

glEnd();

if ((errCode = glGetError()) != GL_NO_ERROR) { // GLenum errCode;

errString = gluErrorString(errCode); // const GLubyte * errString;

MessageBox(NULL,(char *)errString,"ERROR",MB_OK|MB_ICONEXCLAMATION);

}

return TRUE;

}

void Character::view()

{

int num_polys = Character::get_mesh().get_num_polys();

vector<Ver> vers;

vers.resize(Character::mesh.get_num_vertices());

// *** I included this in the post for completeness here

// *** This for loop creates Ver objects which have 3 elements in their vectors

// *** And populates the vers vector with them

for (int i=0; i<(int)Character::bones.size(); i++)

{

vector<float> final_matrix;

multiply_matrices(Character::get_bones()[i].get_o_matrix(), Character::get_bones()[i].get_t_matrix(), final_matrix);

vector<float> matrix;

Ver new_ver;

for (int j=0; j<(int)Character::bones[i].get_v_indices().size(); j++)

{

multiply_matrices(Character::bones[i].get_weights()[j], final_matrix, matrix);

multiply_matrix_vertex(matrix, Character::mesh.get_vertex(Character::bones[i].get_v_indices()[j]).get_coord(), new_ver.get_coord());

vers[Character::bones[i].get_v_indices()[j]].add(new_ver.get_coord());

}

}

// *** Through couts, I have double checked that this past section works. It doesn't collapse the vector into nothingness

// *** or set everything to 0.

for (int i = 0; i < (int)vers.size(); i++)

{

// Write to terminal:

// Make sure that each vertex has 3 points, and that they are not 0.

if ((vers[i].get_coord()[0] == 0) || (vers[i].get_coord()[1] == 0) || (vers[i].get_coord()[2] == 0))

cout << "Coord is 0" << endl;

if ( (vers[i].get_coord().size() != 3) )

cout << "There aren't 3" << endl;

}

for (int i = 0; i < 1 /*num_polys*/; i++)

{

// *** These 3 glVertex3f commands draw a polygon

//glVertex3f(0.0572981f, -0.00736302f, -2.52117f);

//glVertex3f(0.031869f, -0.35291f, -2.3234f);

//glVertex3f(-0.105954f, -1.89219f, -1.49456f);

// *** These 3 don't do anything

glVertex3f((vers[0]).get_coord()[0], (vers[0]).get_coord()[1], (vers[0]).get_coord()[2]);

glVertex3f((vers[1]).get_coord()[0], (vers[1]).get_coord()[1], (vers[1]).get_coord()[2]);

glVertex3f((vers[2]).get_coord()[0], (vers[2]).get_coord()[1], (vers[2]).get_coord()[2]);

}

}

So the problem is that the 2 blocks of glVertex commands produce different outputs. This is despite the numbers in the first block being the values given when I print out the commands in the second block, i.e. "vers[0].get_coord()[0]" etc.

Can anyone please tell me why the second block doesn't actually draw anything?

My vertex class 'Ver' is:

class Ver {

public:

// ATTRIBUTES

std::vector<float> v_coord;

// CONSTRUCTORS

Ver();

Ver(float, float, float);

// ACCESSORS

std::vector<float>& get_coord();

};

This is the code for drawing the scene:

int DrawGLScene(GLvoid)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glLoadIdentity(); // Reset The View

glBegin(GL_TRIANGLES);

character.view(); // member function of my character class

glEnd();

if ((errCode = glGetError()) != GL_NO_ERROR) { // GLenum errCode;

errString = gluErrorString(errCode); // const GLubyte * errString;

MessageBox(NULL,(char *)errString,"ERROR",MB_OK|MB_ICONEXCLAMATION);

}

return TRUE;

}

void Character::view()

{

int num_polys = Character::get_mesh().get_num_polys();

vector<Ver> vers;

vers.resize(Character::mesh.get_num_vertices());

// *** I included this in the post for completeness here

// *** This for loop creates Ver objects which have 3 elements in their vectors

// *** And populates the vers vector with them

for (int i=0; i<(int)Character::bones.size(); i++)

{

vector<float> final_matrix;

multiply_matrices(Character::get_bones()[i].get_o_matrix(), Character::get_bones()[i].get_t_matrix(), final_matrix);

vector<float> matrix;

Ver new_ver;

for (int j=0; j<(int)Character::bones[i].get_v_indices().size(); j++)

{

multiply_matrices(Character::bones[i].get_weights()[j], final_matrix, matrix);

multiply_matrix_vertex(matrix, Character::mesh.get_vertex(Character::bones[i].get_v_indices()[j]).get_coord(), new_ver.get_coord());

vers[Character::bones[i].get_v_indices()[j]].add(new_ver.get_coord());

}

}

// *** Through couts, I have double checked that this past section works. It doesn't collapse the vector into nothingness

// *** or set everything to 0.

for (int i = 0; i < (int)vers.size(); i++)

{

// Write to terminal:

// Make sure that each vertex has 3 points, and that they are not 0.

if ((vers[i].get_coord()[0] == 0) || (vers[i].get_coord()[1] == 0) || (vers[i].get_coord()[2] == 0))

cout << "Coord is 0" << endl;

if ( (vers[i].get_coord().size() != 3) )

cout << "There aren't 3" << endl;

}

for (int i = 0; i < 1 /*num_polys*/; i++)

{

// *** These 3 glVertex3f commands draw a polygon

//glVertex3f(0.0572981f, -0.00736302f, -2.52117f);

//glVertex3f(0.031869f, -0.35291f, -2.3234f);

//glVertex3f(-0.105954f, -1.89219f, -1.49456f);

// *** These 3 don't do anything

glVertex3f((vers[0]).get_coord()[0], (vers[0]).get_coord()[1], (vers[0]).get_coord()[2]);

glVertex3f((vers[1]).get_coord()[0], (vers[1]).get_coord()[1], (vers[1]).get_coord()[2]);

glVertex3f((vers[2]).get_coord()[0], (vers[2]).get_coord()[1], (vers[2]).get_coord()[2]);

}

}

So the problem is that the 2 blocks of glVertex commands produce different outputs. This is despite the numbers in the first block being the values given when I print out the commands in the second block, i.e. "vers[0].get_coord()[0]" etc.

Can anyone please tell me why the second block doesn't actually draw anything?