How to set normals on polygons?

Hello people, i have problem, not know set normals on polygons, i need set normals, for light.

My code:

glBegin(GL_QUADS);
	        glVertex3d(0.1f, 1.0f, 0.0f);
			glVertex3d(0.0f, 0.0f, 0.0f);
			glVertex3d(1.2f, 0.0f, 0.0f);
			glVertex3d(0.9f, 1.0f, 0.0f);

			glVertex3d(1.2f, 0.0f, 0.0f);
			glVertex3d(1.2f, 0.0f, -0.6f);
			glVertex3d(0.9f, 1.0f, -0.6f);
			glVertex3d(0.9f, 1.0f, 0.0f);

			glVertex3d(0.9f, 1.0f, -0.6f);
			glVertex3d(1.2f, 0.0f, -0.6f);
			glVertex3d(0.0f, 0.0f, -0.6f);
			glVertex3d(0.1f, 1.0f, -0.6f);

			glVertex3d(0.1f, 1.0f, -0.6f);
			glVertex3d(0.0f, 0.0f, -0.6f);
			glVertex3d(0.0f, 0.0f, 0.0f);
			glVertex3d(0.1f, 1.0f, 0.0f);

			glVertex3d(0.1f, 1.0f, -0.6f);
			glVertex3d(0.1f, 1.0f, 0.0f);
			glVertex3d(0.9f, 1.0f, 0.0f);
			glVertex3d(0.9f, 1.0f, -0.6f);
	
		glEnd();
        
		glPopMatrix();

		// Kabina vozila
		glPushMatrix();
		glBegin(GL_QUADS);
		glVertex3f(1.2f, 0.9f, 1.0f);
		glVertex3f(1.2f, -0.1f, 1.0f);
		glVertex3f(2.4f, -0.1f, 1.0f);
		glVertex3f(2.1f, 0.9f, 1.0f);

		glVertex3f(2.4f, -0.1f, 1.0f);
		glVertex3f(2.4f, -0.1f, 0.0f);
		glVertex3f(2.1f, 0.9f, 0.0f);
		glVertex3f(2.1f, 0.9f, 1.0f);

		glVertex3f(2.1f, 0.9f, 0.0f);
		glVertex3f(2.4f, -0.1f, 0.0f);
		glVertex3f(1.2f, -0.1f, 0.0f);
		glVertex3f(1.2f, 0.9f, 0.0f);

		glVertex3f(1.2f, 0.9f, 0.0f);
		glVertex3f(1.2f, -0.1f, 0.0f);
		glVertex3f(1.2f, -0.1f, 1.0f);
		glVertex3f(1.2f, 0.9f, 1.0f);

		glVertex3f(1.2f, 0.9f, 0.0f);
		glVertex3f(1.2f, 0.9f, 1.0f);
		glVertex3f(2.1f, 0.9f, 1.0f);
		glVertex3f(2.1f, 0.9f, 0.0f);
		glEnd();
		glPopMatrix();

Need set normals, in this code. Can help me ?

Maybe can use this:

void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)

First off,


glVertex3d(0.1f, 1.0f, 0.0f);

this should be


glVertex3f(0.1f, 1.0f, 0.0f);

because you are send in a float type… see the little f at the end “1.0f”

And yes. You can use that function to give the normals.


glNormal3f(0.0f, 1.0f, 0.0f); //Pointing Upwards
glVertex3f(0.1f, 1.0f, -0.6f);

glNormal3f(1.0f, 0.0f, 0.0f); //Pointing Right
glVertex3f(0.6f, 1.0f, -0.1f);

You can help me with all code ? :slight_smile: please :slight_smile: Or if want i contact you skype, maybe … I now work texture :slight_smile:

We can talk through here. I will be working for the next 3-4 hours. I’ll check this often.

Here is a simple example: OpenGL: why do I have to set a normal with glNormal? - Game Development Stack Exchange
Calculating Vertex Normals: Calculating vertex normals. - OpenGL: Basic Coding - Khronos Forums

Normals on QUADS is done :slight_smile: I have problem in texture on glutSolidCube :frowning:

glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_ZID2]);
glColor3ub(255, 0, 0);
glPushMatrix();
glTranslatef(-1.55f, -0.35f, 0.0f);
glScaled(2.4f, 0.6f, 2.0f);
glutSolidCube(1.0);
glPopMatrix();
glColor3ub(255, 0, 0);
glPushMatrix();
glTranslatef(0.3f, -0.35f, 0.0f);
glScaled(1.4f, 0.4f, 1.7f);
glutSolidCube(1.0);
glPopMatrix();
glColor3ub(255, 0, 0);
glPushMatrix();
glTranslatef(1.65f, -0.35f, 0.0f);
glScaled(1.5f, 0.6f, 2.0f);
glutSolidCube(1.0);
glPopMatrix();

Where i not got texture, why ?

You should always follow proper matrix transformation conventions. Swap your scale and translation matrices first.

Scale -> Rotate -> Translate

[QUOTE=ParagonArcade;1262974]You should always follow proper matrix transformation conventions. Swap your scale and translation matrices first.

Scale -> Rotate -> Translate[/QUOTE]

Um, no. You should do them in the order that actually performs the transformation you want. And while that’s often in that order, it is by no means the one true order for transformations.

That should not be taken to mean that his order is in fact correct for his intended purposes. Only that you can’t assume that it’s wrong without further evidence. Like what those numbers are supposed to mean.

Yes, but i not see texture :frowning: What do ?

Did you generate the texture?
Did you double check that you loaded the texture properly?
Did you load it into array properly?
Did you fetch the id properly?

What third party lib are you using to load textures? SOIL?

Typically, I bind my textures using the following setup:

Using some class Texture


glGenTextures(1, &id);

/* load an image file directly as a new OpenGL texture */
setTextureId( SOIL_load_OGL_texture
	(
	filename,
	SOIL_LOAD_AUTO,
	SOIL_CREATE_NEW_ID,
	SOIL_FLAG_INVERT_Y
	));

glBindTexture(GL_TEXTURE_2D, getTextureID());

Thank you! Hmm…i not generate texture , i need that :slight_smile: Can explain how generate texture ? Any code…

[ATTACH=CONFIG]834[/ATTACH]

Hm… good texture on crane ?

[ATTACH=CONFIG]835[/ATTACH]

Hmm… not bad :slight_smile: How fix this line texture on crane ?

How set background in my OpenGL code ? :slight_smile: Please can help me ?