Public Group

# Using indices with normals?

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

## Recommended Posts

Is it posible to use normals with indices? If so, how?

say for example i have

std::vector<GLfloat> vertices{
2.0f, 0.0f, -2.0f,  0.0f,  0.0f, -1.0f, 2.0f, 2.0f,
-2.0f, 0.0f, -2.0f, 0.0f,  0.0f, -1.0f, 0.0f, 2.0f,
-2.0f, 0.0f, 2.0f,  0.0f,  0.0f, -1.0f, 0.0f, 0.0f,
2.0f, 0.0f, 2.0f,  0.0f,  0.0f, -1.0f, 2.0f, 0.0f
};
std::vector<GLuint>indices{
0,1,3,
1,2,3
};

I just dont want to declare too many vertices. Using indices is my much preferred method when for example making a cube.

Its just a plane. I just want to visualize normal vectors with the use of geometry shader. Ive been trying to use the normal but still not showing on my scene.

Edited by FirstStep

##### Share on other sites

As far as I know, you can use normals with indices, but keep in mind that the normal on your surface with be interpolated in the pixel shader, so the cube will look roundish. If you want to have hard edges, you have to declare a vertex for each corner of a face (so you'll have 4x6=24 vertices).

##### Share on other sites

Hello. Thanks. I manage to put a normal vector line on each edge of the plane. but  I see another problem of using indices though. It is so hard to position the texture.

take for example this

std::vector<GLfloat> cuberVertices{

0.5f, 0.0f, -0.5f, 0.0f,1.0f,0.0f, 2.0f, 2.0f,
-0.5f, 0.0f, -0.5f, 0.0f,1.0f,0.0f, 0.0f, 2.0f,
-0.5f, 0.0f, 0.5f, 0.0f,1.0f,0.0f,   0.0f, 0.0f,
0.5f, 0.0f, 0.5f, 0.0f,1.0f,0.0f, 2.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f,0.0f,0.0f, 2.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f,0.0f,0.0f, 2.0f, 2.0f
};

The first 4 row was easy. but the next 2 row is hard. I mean. The image look stretched. The plane has a correct image position. the wall though looks stretched.

How can you map the coordinate of two vertex on a texture that requires 4 vertex?

##### Share on other sites

The image look stretched. The plane has a correct image position. the wall though looks stretched. How can you map the coordinate of two vertex on a texture that requires 4 vertex?

That's where you get into the art of texture mapping and UV coordinates. It is one step of making beautiful 3D models, and part of the reason we use high quality modeling tools rather than trying to hard-code models in code.

##### Share on other sites

Do you mean an index buffer for usage of normals only? as far as I know.. no.

Indicies in OpenGL are built to contain the index of a single vertex/UV/Normal.

So if you have x1,x2,x3,uv1,uv2,n1,n2,n3 (Representation of a single point)

All of that will conclude to a single index.

----------------

Texturing issue:

Try setting different wrapping or a different filtering method.

Although it looks like your coordinates should be tweaked correctly. (UV)

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013602
×