Sign in to follow this  

Using indices with normals?

This topic is 678 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

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 this post


Link to post
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).

Edited by dancingmad

Share this post


Link to post
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. 

[url=http://postimg.org/image/ajgabchsd/]hehe.jpg[/url]
 
How can you map the coordinate of two vertex on a texture that requires 4 vertex?

Share this post


Link to post
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 this post


Link to post
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)

Share this post


Link to post
Share on other sites

This topic is 678 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this