Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Opengl - Jumpy lighting

  1. #1
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50

    Opengl - Jumpy lighting

    My one light seems to 'jump' and not flow smoothly across my floor tile texture.

    It's much better explained in this short youtube video youtube link
    Note that my light is not going somewhere and coming back; it is always located half way between the camera and the cube.

    This is my function for drawing the floor tiles:
    Code :
    void drawFloor(){
     
    	float size = 20.0;
    	float startX = -60.0f;
    	float startZ = 60.0f;
     
    	glDisable(GL_COLOR_MATERIAL);
     
    	glPushMatrix();
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, _textureId);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    	//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
     
    	for(int x = 0;x < 6; x++){
    		for(int z = 0;z < 6; z++){
     
    			glBegin(GL_QUADS);
     
    			glNormal3f(0.0f, 1.0f, 0.0f);
    			 glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(startX + size*x, 0.0f, startZ + -size*z);//bottom-left
    			 glTexCoord2f(1.0f, 0.0f);
    			glVertex3f(startX + size + size*x, 0.0f, startZ + -size*z);//bottom-right
    			 glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(startX + size + size*x, 0.0f, startZ + -size + -size*z);//top-right
    			 glTexCoord2f(0.0f, 1.0f);
    			glVertex3f(startX + size*x, 0.0f, startZ + -size + -size*z);//top-left
     
    			glEnd();
    		}
    	}
     
    	glDisable(GL_TEXTURE_2D);
     
    	glPopMatrix();
     
    	glEnable(GL_COLOR_MATERIAL);
     
    }

    Question: How can i make my light not jump and light the tiles smoothly?

  2. #2
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    70

    Re: Opengl - Jumpy lighting

    Quote Originally Posted by shawn619
    It's much better explained in this short youtube video youtube
    O_o. I do not think it links to what you wanted it to.

  3. #3
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50

    Re: Opengl - Jumpy lighting

    Fixed*

    Thanks for catching that, i was very tired when i posted this

  4. #4
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50

    Re: Opengl - Jumpy lighting

    Bump

  5. #5
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Opengl - Jumpy lighting

    and where's the code which handles the lighting? Can't fix lighting with seeing lighting code you know ;-)

  6. #6
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    70

    Re: Opengl - Jumpy lighting

    Random guess: you use per vertex lighting (http://en.wikipedia.org/wiki/Gouraud_shading) and your polygons are just too big for that.

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Opengl - Jumpy lighting

    So use shaders to do PPL = per pixel lighting
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  8. #8
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50

    Re: Opengl - Jumpy lighting

    Ah yes, im going to that now, thanks everyone!

    @V-man, nice to see a Canadian opengl programmer =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •