Hi everyone this is my first post here, I think I am in the right area.
I am working on making my own opengl graphics engine. I am mostly trying to learn opengl.
To start off, [color=#363534][font=Verdana,]I downloaded the qt obj viewer a while ago from this link http://qt.gitorious....abs/modelviewer[/font][color=#363534][font=Verdana,]. I have been modifying it to fit my needs. It is my first time using opengl. Right now I am working on texturing objects. I cannot tell if it is my opengl code that is wrong or if I am writing my u v coordinates incorrectly. As it stands I write the u v coords in the same order as they are in the obj file. It appears that part of my texture is correct. Here is an image and below is my code.[/font]
[color=#363534][font=Verdana,]As a side note, reading obj files with multiple objects and materials has worked just fine. The next step is texturing which is giving me some trouble.[/font]
[color=#363534][font=Verdana,][/font]
[color=#363534][font=Verdana,]As you can see the u v coords are going into a class Point3d. The u_v_coords is a QVector<Point3d>[/font]
[color=#363534][font=Verdana,]
...
else if (id == "vt"){
Point3d p;
for(int i = 0; i < 2; ++i){
ts >> p;
}
u_v_coords << p;
}
...
[/font]
...
else if (id == "vt"){
Point3d p;
for(int i = 0; i < 2; ++i){
ts >> p;
}
u_v_coords << p;
}
...
[color=#363534][font=Verdana,]The opengl code for drawing a textures is below. I am using glTexCoordPointer with the stride of size Point3d.[/font]
void Model::renderHelper(int i) const{
if(texture != NULL){
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture->texture );
glTexCoordPointer(2, GL_FLOAT, sizeof(Point3d), u_v_coords.data());
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
glMaterialfv(GL_FRONT, GL_AMBIENT, materials[objectMaterialInt].Ka);
glMaterialfv(GL_FRONT, GL_DIFFUSE, materials[objectMaterialInt].Kd);
glMaterialfv(GL_FRONT, GL_SPECULAR, materials[objectMaterialInt].Ks);
glMaterialf(GL_FRONT, GL_SHININESS, materials[objectMaterialInt].Ns);
glShadeModel(GL_SMOOTH);
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, (float *)m_points.data());
glNormalPointer(GL_FLOAT, 0, (float *)m_normals.data());
glDrawElements(GL_TRIANGLES, objects.size(), GL_UNSIGNED_INT, objects.data());
glPopMatrix();
if(texture != NULL){
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
Thanks for the help, let me know if you need more information.