Jump to content
  • Advertisement
Sign in to follow this  
FirstStep

Using indices with normals?

This topic is 960 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
Advertisement

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. 

hehe.jpg
 
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!