# OpenGL How to draw normal vectors like this

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

## Recommended Posts

Hi everybody, I'm new to OpenGL. I'm doing the machining simulation software, I got the problem that how to draw normal vectors like this. http://upload.tinhco.net/thoai/normal.jpg Thank you :)

##### Share on other sites
You could try building a line list form the normal vectors and render them for last.

##### Share on other sites
Render a line from position to position + scale * normal where scale is some value that controls the length of the line. Assuming your normals are indeed unit length, a scale of 1 will result in a line 1 unit long.

##### Share on other sites
The normals in the image have 1D texture mapped, which is a gradient 1D image from blue to white. The centroid (the centre of a triangle) point can be easily computed by averaging the sum of 3 points. And Kalidor mentioned how to find the other end point.

Here is a code snippet to draw normals
glBindTexture(GL_TEXTURE_1D, texId);// draw lines with 1D textureglBegin(GL_LINES);glTexCoord1f(0); glVertex3fv(point1);glTexCoord1f(1); glVertex3fv(point2);...glEnd();glBindTexture(GL_TEXTURE_1D, 0);

##### Share on other sites
Actually, to get the gradient you don't need to use a texture. You can just set the color of the first point on the line to blue and the color of the second point to white, turn off texturing and lighting, and OGL will do the rest.

##### Share on other sites
thank you , I'll try
:(

1. 1
Rutin
73
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633425
• Total Posts
3011810
• ### Who's Online (See full list)

There are no registered users currently online

×