• 9
• 11
• 9
• 20
• 12
• ### Similar Content

• Hello guys,

How do I know? Why does wavefront not show for me?
I already checked I have non errors yet.

And my download (mega.nz) should it is original but I tried no success...
- Add blend source and png file here I have tried tried,.....

PS: Why is our community not active? I wait very longer. Stop to lie me!
Thanks !

• I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.

• Hello everyone,
I have problem with texture

• Hello everyone
For @80bserver8 nice job - I have found Google search. How did you port from Javascript WebGL to C# OpenTK.?
I have been searched Google but it shows f***ing Unity 3D. I really want know how do I understand I want start with OpenTK But I want know where is porting of Javascript and C#?

Thanks!
• By mike44
Hi
I draw in a OpenGL framebuffer. All is fine but it eats FPS (frames per second), hence I wonder if I could execute the framebuffer drawing only every 5-10th loop or so?
Many thanks

# OpenGL Untitled

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

## Recommended Posts

hello, i am very new to OpenGL and have some questions: i just activated lighting but now all my colors are gone and the polygons are from black to white depending on the lighting. i am rendering a heightfield and need to calculate normals for that. so far i get the slopes for each point, but how do i get the normals out of it? thanks!

##### Share on other sites
http://sjbaker.org/steve/omniv/opengl_lighting.html

Here is a good way to find the normals per vertex on a model.

for all vertices
vertex.norm = {0,0,0}

for all triangles in model{
temp_norm = trianlge.findNorm()
triangle.vertex1.norm += temp_norm
triangle.vertex2.norm += temp_norm
triangle.vertex3.norm += temp_norm
}

for all vertices
normalize(vertex.norm);

##### Share on other sites
use glEnable(GL_COLOR_MATERIAL); to be able to use glColor in conjunction with opengl-lighting :)

##### Share on other sites
thank you!

the glEnable(GL_COLOR_MATERIAL); worked!
but now on the other hand i dont get any shading on objects that have a texture on it? is there a similar thing i should enable?

im rendering a heightfield, so i basically have a twodimensional array with values from 0 to 1.
i dont really understand that algorithm.

thanks!

##### Share on other sites
Quote:
 Original post by ehmdjiithank you!the glEnable(GL_COLOR_MATERIAL); worked!but now on the other hand i dont get any shading on objects that have a texture on it? is there a similar thing i should enable?

Did this change when you turned on color material? Are you setting vertex color values for the textured faces (using color pointer or glcolor)?

The diffuse material color is combined with the light color for diffuse lighting, so if it were 0, or something else very dark, then you would see little or no diffuse shading from the lights. With GL_COLOR_MAERIAL on and the default settings, the diffuse material color comes from the vertex color. If you are using this functionality you need to supply colors for those verticies, if not you should turn off GL_COLOR_MATERIAL for those faces.

There are other possible problems that could cause lighting not to show up correctly. You might want to post your lighting/texture setup code.

Quote:
 about the normals:im rendering a heightfield, so i basically have a twodimensional array with values from 0 to 1.i dont really understand that algorithm.thanks!

Bascily if you want a smooth shaded object you will want to set the normal for each vertex to the average of the normals of the faces it touches.

The algorithim above will do that for a generic mesh by taking each face in the mesh and adding it's normal to a sum stored for each vertex used by that face. Then he normalizes those sums to get the final vertex normal for each vertex.

In the case of your terrain consider all of the triangles that touch a height point in the grid, these are your faces. For a non-edge vertex there should be 6:
+----+----+|\ 1 |\   || \  | \  ||  \ |  \ || 2 \| 3 \|+----+----+|\ 4 |\ 5 || \  | \  ||  \ |6 \ ||   \|   \|+----+----+

##### Share on other sites
thanks a lot for you reply!

Quote:
 Did this change when you turned on color material?

no, it didnt work before either.

Quote:
 Are you setting vertex color values for the textured faces (using color pointer or glcolor)?

no, i am not setting vertex colors.

Quote:
 bascily if you want a smooth shaded object you will want to set the normal for each vertex to the average of the normals of the faces it touches.

ok, but how do i get the normals of the surrounding faces?

thanks a lot!

##### Share on other sites
Quote:
 ok, but how do i get the normals of the surrounding faces?

The normal of your triangle, is the crossproduct of two sides.

normal = a.cross(b);

If you don't normalize the normal yourself, you should call glEnable(GL_NORMALIZE) - automatic normalization by opengl.

##### Share on other sites
ah thanks! that makes sense now!

but isnt this a lot of calculation? will performance decrease if my heightfield is 64x64?

##### Share on other sites
You only need to calculate the normals once (unless they are constantly changing, then you need to calculate after each change). Before you draw anything find the normal for each vertex and save it. Then just use the saved values every time you draw.

You shouldn't notice the time it takes to find the normals for a 64x64 feild, especially if you only do it once.

##### Share on other sites
Quote:
Original post by stein
Quote:
 ok, but how do i get the normals of the surrounding faces?

The normal of your triangle, is the crossproduct of two sides.

normal = a.cross(b);

If you don't normalize the normal yourself, you should call glEnable(GL_NORMALIZE) - automatic normalization by opengl.

Yep that's it, and just to make sure this is really clear, if you have 3 verts in the face v1, v2, v3, then you'll get the face normal with: cross_product(v2 - v1, v3- v1).