Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Colors on terrain, glcolorpointer ?

  1. #1
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43

    Colors on terrain, glcolorpointer ?

    glcolorpointer doesn't work. i mean, it changes nothing on the tiles.. what is missing ?


    init loop :

    Code :
    keslan[z * TERRAIN_SIZE + x].x=x - TERRAIN_SIZE/2;
    			keslan[z * TERRAIN_SIZE + x].y=heightmap[z * TERRAIN_SIZE + x]  / SCALE_FACTOR ;
    			keslan[z * TERRAIN_SIZE + x].z=z - TERRAIN_SIZE/2;
    			keslan[z * TERRAIN_SIZE + x].u=(GLfloat)x/TERRAIN_SIZE*16;
    			keslan[z * TERRAIN_SIZE + x].v=(GLfloat)z/TERRAIN_SIZE*16;
    			keslan[z * TERRAIN_SIZE + x].r=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
    			keslan[z * TERRAIN_SIZE + x].g=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
    			keslan[z * TERRAIN_SIZE + x].b=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
    			keslan[z * TERRAIN_SIZE + x].a=1.0f;



    draw code :

    Code :
    glBindBuffer(GL_ARRAY_BUFFER,m_vert);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glVertexPointer(3, GL_FLOAT, sizeof(vrt), NULL);
    	glTexCoordPointer(2,GL_FLOAT,sizeof(vrt),(char*)NULL + 12);
    	glColorPointer(4,GL_FLOAT,sizeof(vrt),(char*)NULL + 20);
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ind);
    	glDrawElements(GL_TRIANGLE_STRIP,indices.size(),GL_UNSIGNED_INT,0);
    	glBindBuffer(GL_ARRAY_BUFFER,0);
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glDisableClientState(GL_COLOR_ARRAY);

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    I can't see anything wrong with the array setup code.
    How are you shading the terrain, where's the rest of the draw code and state?

  3. #3
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    Code :
    void CGfxOpenGL::Render()
    {
    	glClearColor(0.0f, 0.0, 0.0, 0.0);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glLoadIdentity();
    	gluLookAt(cameraX, cameraY, cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     
     
    	m_skybox.Render(cameraX, cameraY, cameraZ);
     
    	DrawTerrain();
    }

    drawterrain is the above one

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    381
    Are you using shaders, or the fixed function? If you are using shaders you will need to use gl_Color for colors to have any effect.

  5. #5
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    shaders ? i don't think i use them. what do you mean by fixed function ?

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    I think we need to see what's inside DrawTerrain();

  7. #7
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    Code :
    void CGfxOpenGL::DrawTerrain()
    {
    	static float ze = 2.00f;
     
    	glBindTexture(GL_TEXTURE_2D, m_grassTexture);
    	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     
    	glBindBuffer(GL_ARRAY_BUFFER,m_vert);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glVertexPointer(3, GL_FLOAT, sizeof(vrt), NULL);
    	glTexCoordPointer(2,GL_FLOAT,sizeof(vrt),(char*)NULL + 12);
    	glColorPointer(4,GL_FLOAT,sizeof(vrt),(char*)NULL + 20);
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ind);
    	glDrawElements(GL_TRIANGLE_STRIP,indices.size(),GL_UNSIGNED_INT,0);
    	glBindBuffer(GL_ARRAY_BUFFER,0);
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glDisableClientState(GL_COLOR_ARRAY);
     
     
     
    	//water
    	glBindTexture(GL_TEXTURE_2D, m_waterTexture);
    	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    	glBegin(GL_QUADS);
    		glTexCoord2f(0.0, 0.0);
    		glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);
     
    		glTexCoord2f(TERRAIN_SIZE/4.0f, 0.0);
    		glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);
     
    		glTexCoord2f(TERRAIN_SIZE/4.0f, TERRAIN_SIZE/4.0f);
    		glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);
     
    		glTexCoord2f(0.0, TERRAIN_SIZE/4.0f);
    		glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);
    	glEnd();
     
    }

  8. #8
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    Your Terrain render isn't doing anything with the colours in the vertex array because you have enabled texturing. What you need to do is combine the texture colour with the per-vertex colour.
    This is usually done via glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pname);
    where pname is either GL_DECAL, GL_ADD, GL_MODULATE, GL_BLEND, GL_REPLACE or GL_COMBINE

    Basic per-vertex colour * Texture colour is achieved via GL_MODULATE.

    GL_COMBINE uses Texture Combiner Functions which has been superceeded by shaders which will allow you to perform a custom wizzy function on your terrain instead of some rather limited math.

    Perhaps you have set the textEnv to GL_REPLACE elsewhere in your code which means the final colour is only the texture colour and the vertex colour is ingored.

  9. #9
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    thank you so much, it works now. I think i have to learn about textures more :P

  10. #10
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    Quote Originally Posted by BionicBytes View Post
    Your Terrain render isn't doing anything with the colours in the vertex array because you have enabled texturing. What you need to do is combine the texture colour with the per-vertex colour.
    This is usually done via glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pname);
    where pname is either GL_DECAL, GL_ADD, GL_MODULATE, GL_BLEND, GL_REPLACE or GL_COMBINE

    Basic per-vertex colour * Texture colour is achieved via GL_MODULATE.

    GL_COMBINE uses Texture Combiner Functions which has been superceeded by shaders which will allow you to perform a custom wizzy function on your terrain instead of some rather limited math.

    Perhaps you have set the textEnv to GL_REPLACE elsewhere in your code which means the final colour is only the texture colour and the vertex colour is ingored.
    by the way i have to ask

    what is "normal" for a mesh/model ? i got texture coords, vertex, color thing but what is a normal ?

Posting Permissions

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