0

again openGL) I need to make drag-control for textures and don't know how to store this values. i have a struct with point, image for texture, but i need a texture to change their position, so i need to change glVertex2f on mousePressed method, as i understand

glLoadIdentity();
glEnable(GL_TEXTURE_2D); //enable 2D texturing
if(number < 4){
   glBindTexture( GL_TEXTURE_2D, texture );
} else {
   glBindTexture( GL_TEXTURE_2D, texture2 );
}

glBegin (GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2f(x/window_width, y/window_height);
glTexCoord2d(1.0,0.0); glVertex2f(x/window_width+0.2, y/window_height);
glTexCoord2d(1.0,1.0); glVertex2f(x/window_width+0.2, y/window_height+0.2);
glTexCoord2d(0.0,1.0); glVertex2f(x/window_width, y/window_height+0.2);
glEnd();
glFlush();

how can i add them to vector and then change position ?

vallentin
  • 23,478
  • 6
  • 59
  • 81
gronzzz
  • 617
  • 6
  • 15

1 Answers1

0

If you want to drag the texture, you need to change the glTextCoord2d values. This way the poligon remains fixed but the texture you apply to it shifts.

Also check out the texture params to apply warp to your texture so that it repeats.

Sorin
  • 11,863
  • 22
  • 26
  • Thanks, i understand about changing position, i need to know how to create object with this params, that in future i can make something like obj->glVertex2f(0.1,0.2) e.t.c. – gronzzz Dec 18 '13 at 12:28
  • 1
    @gronzzz: Have your object class have a member `putVertex` that either calls `glVertex` with the right parameters. Or better let it fill into an array you can pass to OpenGL as a vertex array. glVertex and its friends are obsolete and have been removed from modern OpenGL altogether. – datenwolf Dec 18 '13 at 15:58