• Create Account

# paulg568

Member Since 04 Jan 2012
Offline Last Active Jan 24 2012 12:09 PM

### Normals for smoothing groups issue

22 January 2012 - 11:31 PM

I have been creating an obj loader. I have pretty much everything working except for smoothing groups. They partially work.

I go through all the faces and check if their indicies are part of multiple smoothing groups. If so I mark what index was part of a separate smoothing group. Then I go through again and duplicate that vertex and update the faces array to use that new vertex.

I hope that makes sense.

Here is a screenshot of two chess pieces. In it you can see the knight and the rook have certain areas that are smoothing nicely and others that you can clearly see the polygons. I feel like I am duplicating vertices too many times if they are part of too many faces but I can't seem to fix it. If anyone has any idea what I am doing wrong I would greatly appreciate it. Code is below the picture. Thanks for the help.

Here is the code for finding shared vertices and the how I duplicate them.
It probably looks confusing and is.... so if you want me to explain it more I can. Thanks for the help.

```void ObjFileReader::findSharedVertices(int numberOfObjects, int sizeOfVerts, QVector<int> *faces, QVector<int> *repeatedIndices, QVector<int> *repeatsInsideFaces, QVector<int> *smoothingGroups){
QVector<int> *smooths = new QVector<int>[numberOfObjects];
for(int i = 0; i < numberOfObjects; i++){
repeatedIndices[i].resize(sizeOfVerts);
smooths[i].resize(sizeOfVerts);
for(int j = 0; j < faces[i].size(); j++){
repeatedIndices[i][faces[i][j]]++;
if(repeatedIndices[i][faces[i][j]] > 1){
if(smooths[i][faces[i][j]] == smoothingGroups[i][j]){
repeatedIndices[i][faces[i][j]]--;
} else {
repeatsInsideFaces[i].append(j);
}
} else {
smooths[i][faces[i][j]] = smoothingGroups[i][j];
}
}
}
}
void ObjFileReader::duplicateSharedVertices(int numberOfObjects, QVector<int> *smoothingGroupIndices, QVector<int> *faces, QVector<Point3d> *m_points, QVector<int> *uvCoordinateIndexing, QVector<int> *repeatedIndices, QVector<int> *repeatsInsideFaces){
int total = 0;
for(int i = 0; i < numberOfObjects; i++){
for(int j = 0; j < repeatsInsideFaces[i].size(); j++){
m_points->append((*m_points)[faces[i][repeatsInsideFaces[i][j]]]);
faces[i][repeatsInsideFaces[i][j]] = m_points->size()-1;
}
}
}
```

### GUI Images don't render if x position is negative.

17 January 2012 - 12:15 AM

I wrote my own gui image renderer.

I am having an issue with images not rendering if there position is negative even if part of the image is still on screen.

Here is my code:

```glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glRasterPos2f(xPos, yPos);
glPixelZoom(xScale, yScale);
glDrawPixels(originalWidth, originalHeight, GL_RGBA, GL_UNSIGNED_BYTE, imageData.bits());
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
```

Anyone know how to fix this?

Thanks.

### texture coordinates problem

04 January 2012 - 02:51 PM

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, I downloaded the qt obj viewer a while ago from this link http://qt.gitorious....abs/modelviewer. 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.

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.

As you can see the u v coords are going into a class Point3d. The u_v_coords is a QVector<Point3d>

```...
else if (id == "vt"){
Point3d p;
for(int i = 0; i < 2; ++i){
ts >> p[i];
}
u_v_coords << p;
}
...
```

The opengl code for drawing a textures is below. I am using glTexCoordPointer with the stride of size Point3d.

```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[i]].Ka);
glMaterialfv(GL_FRONT, GL_DIFFUSE, materials[objectMaterialInt[i]].Kd);
glMaterialfv(GL_FRONT, GL_SPECULAR, materials[objectMaterialInt[i]].Ks);
glMaterialf(GL_FRONT, GL_SHININESS, materials[objectMaterialInt[i]].Ns);
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[i].size(), GL_UNSIGNED_INT, objects[i].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.

PARTNERS