GL4Java-glTranslatef.glTexture

Trying to use glTranslatef to move the location of my object using the mouseDragged method. Having problem; tranlation barely happens I tried pos += (the value of x or y) however that just increments and the object continues to move more and more in the positive and doesn’t follow the mouseDragged method. Below is some code of what I want to do. Also having an issue with texture. Every time I rotate the object the texture on my sphere gets distorted. How can I fix this?Any assistance would be greatly appreciated.

public void display(){

if( glj.gljMakeCurrent() == false ) {
                     return;}           //Make Sure GL is initiated properly




   DrawGLScene();

   solidSphere();     //Method that creates the solid sphere

  //wireSphere();    //Method that creates the wireframe sphere
  gl.glDisable(GL_TEXTURE_2D);  //Turn the texture off

   for(Iterator i = drawables.iterator(); i.hasNext();)
   {
     draw_Interface pic = (draw_Interface) i.next();
     pic.draw(gl);

   }

   for(Iterator i = labels.iterator(); i.hasNext();)
   {
     text_Interface letter = (text_Interface) i.next();
     letter.text(glf,gl);
   }

 //System.out.println("output display");


 gl.glFlush();

}

public boolean LoadGLTextures(){
//PngTextureLoader texLoader = new PngTextureLoader(gl, glu); //Call to load a .png image file
AWTTextureLoader texLoader = new AWTTextureLoader(this,gl,glu); //Call to load a .jpg image file
texLoader.readTexture(“earth.jpg”);
if(texLoader.isOk())
{
//Create the texture
gl.glGenTextures(1,texture);
gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set Up Sphere Mapping
gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
gl.glEnable(GL_BLEND);
gl.glEnable(GL_SMOOTH);
gl.glEnable(GL_TEXTURE_GEN_S); // Enable Sphere Mapping
gl.glEnable(GL_TEXTURE_GEN_T);
gl.glTexImage2D(GL_TEXTURE_2D,0,3,texLoader.getImageWidth(),texLoader.getImageHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,texLoader.getTexture());

  return true;
}
return false;

}

public void solidSphere(){

gl.glEnable(GL_TEXTURE_2D);
gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
glut.glutSolidSphere(earth_radius,1200,1200);

}

public void DrawGLScene(){
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear screen and buffer bit
gl.glLoadIdentity(); //Reset the view

gl.glTranslatef(pos_x,pos_y,pos_z);                   //Position the objects
gl.glRotatef(angle_x,1.0f,0.0f,0.0f);
gl.glRotatef(angle_y,0.0f,1.0f,0.0f);
gl.glRotatef(angle_z,0.0f,0.0f,1.0f);
gl.glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE);

}

public void mouseMoved(MouseEvent evt){
angle_x = (float)evt.getX();
angle_y = (float)evt.getY();
//System.out.println(“Mouse was pressed” + evt);
repaint();
}

public void mouseDragged(MouseEvent evt){
pos_x = (float)evt.getX();
pos_y = (float)evt.getY();
repaint();
}

If you are using a perspective view, then the amount the globe travels in the x and y direction is highly dependant on its depth. It will take a smaller change in x to move closer objects than it would to move farther objects the same perceived amount (i.e. a 1/4 screen). Ortho projects maintain a constant relationship, but not necessarily 1:1, so connecting mouseMoved values directly to x or y just isn’t going to work.

Do you really want to move the globe? Perhaps, you just want to change the camera location/view. This is a lot easier to do with the mouse and is similar to moving the scene. Looking directly at an object and then looking to its right has the appearance of moving the object to the left. So maybe moving the view of the camera is an option for you.

As far as the texture goes, you may want to look into mipmapping your textures, esp. if you will be changing the depth (zoom in/out) and use GL_LINEAR_MIPMAP_NEAREST instead of GL_LINEAR for your GL_TEXTURE_MIN_FILTER parameter.

-Ron