Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Rotating Image Along Y axis in JOGL so that its horizontal (Visible side faces upwad)

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Rotating Image Along Y axis in JOGL so that its horizontal (Visible side faces upwad)

    I am new to JOGL and have tried to display an image in JOGL from an example.

    Displaying an Image in JOGL (Part 1) - TankaarWiki

    However , this example displays the image in 2D, with the right side facing the user(i-e leaf is visible to user), **I wanted to change the code so that i can rotate the image along Y-axis, so that leaf is facing upwards and is not visible to user,(Outline of image is visible to user) and if i rotate it 30 degrees,

    (gl.glRotated(30, 0, 1, 0)

    some part of image should be visible to user.** ,Below is the changing that i have done in the code, but it does not show the image, can any one tell me what am i doing wrong here.. Any Help will be GREATLY Appreciated, Thanks





    import java.awt.Graphics2D;
    import java.awt.color.ColorSpace;
    import java.awt.image.BufferedImage;
    import java.awt.image.ComponentColorModel;
    import java.awt.image.DataBuffer;
    import java.awt.image.DataBufferByte;
    import java.awt.image.Raster;
    import java.awt.image.WritableRaster;
    import java.io.IOException;
    import java.nio.ByteBuffer;

    import javax.imageio.ImageIO;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLDrawable;
    import javax.media.opengl.GLEventListener;
    import javax.swing.JFrame;
    //import net.java.games.jogl.GL;
    //import net.java.games.jogl.GLCanvas;
    //import net.java.games.jogl.GLDrawable;
    //import net.java.games.jogl.GLEventListener;

    public class Image3DGraphics {
    public Image3DGraphics() {
    JFrame frame = new JFrame("2D Graphics");
    frame.setSize(800,900);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener((GLEventListener) new JOGLListener());
    frame.add(canvas);
    frame.setVisible(true);
    }
    public static void main(String args[]){
    new Image3DGraphics();
    }

    private class JOGLListener implements GLEventListener {


    public void display(GLAutoDrawable drawable) {
    System.out.println("DISPLAY CALLED");
    GL gl = drawable.getGL();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, 300, 300, 0, 0, 1);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glDisable(GL.GL_DEPTH_TEST);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable (GL.GL_BLEND);
    BufferedImage bufferedImage = null;
    int w = 10;
    int h = 10;
    int d=10;
    try {
    bufferedImage = ImageIO.read(Image3DGraphics.class.getResource("le af.jpg"));
    w = bufferedImage.getWidth();
    h = bufferedImage.getHeight();
    d = bufferedImage.getWidth();
    } catch (IOException e) {
    e.printStackTrace();
    }
    WritableRaster raster =
    Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE,
    w,
    h,
    4,
    null);
    ComponentColorModel colorModel=
    new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
    new int[] {8,8,8,8},
    true,
    false,
    ComponentColorModel.TRANSLUCENT,
    DataBuffer.TYPE_BYTE);
    BufferedImage dukeImg =
    new BufferedImage (colorModel,
    raster,
    false,
    null);

    Graphics2D g = dukeImg.createGraphics();
    g.drawImage(bufferedImage, null, null);
    DataBufferByte dukeBuf =
    (DataBufferByte)raster.getDataBuffer();
    byte[] dukeRGBA = dukeBuf.getData();
    ByteBuffer bb = ByteBuffer.wrap(dukeRGBA);
    bb.position(0);
    bb.mark();
    gl.glBindTexture(GL.GL_TEXTURE_3D, 13);
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
    gl.glTexImage3D (GL.GL_TEXTURE_3D, 1, GL.GL_RGBA, w, h, d,1, GL.GL_RGBA,
    GL.GL_UNSIGNED_BYTE, bb);

    int left = 100;
    int top = 100;
    gl.glEnable(GL.GL_TEXTURE_3D);
    gl.glBindTexture (GL.GL_TEXTURE_3D, 13);


    // gl.glPushMatrix();
    // gl.glTranslated(100, 100, 0);
    gl.glRotated(30, 0, 1, 0);
    // gl.glTranslated(-100, -100, 0);
    gl.glBegin (GL.GL_POLYGON);
    gl.glTexCoord3d (0, 0,0);
    gl.glVertex3d (left,top,0);
    gl.glTexCoord3d(1,0,0);
    gl.glVertex3d (left + w, top,0);
    gl.glTexCoord3d(1,1,+1.0);
    gl.glVertex3d (left + w, top + h,+1.0);
    gl.glTexCoord3d(0,1,+1.0);
    gl.glVertex3d (left, top + h,+1.0);
    // gl.glTexCoord2d (0, 0);
    // gl.glVertex2d (left,top);
    // gl.glTexCoord2d(1,0);
    // gl.glVertex2d (left + w, top);
    // gl.glTexCoord2d(1,1);
    // gl.glVertex2d (left + w, top + h);
    // gl.glTexCoord2d(0,1);
    // gl.glVertex2d (left, top + h);
    gl.glEnd ();

    gl.glFlush();


    }


    public void displayChanged(GLAutoDrawable arg0, boolean arg1,
    boolean arg2) {
    System.out.println("DISPLAY CHANGED CALLED");
    }


    public void init(GLAutoDrawable drawable) {
    System.out.println("INIT CALLED");
    }


    public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
    int arg4) {
    System.out.println("RESHAPE CALLED");

    }

    public void init(GLDrawable gld) {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void display(GLDrawable gld) {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void reshape(GLDrawable gld, int i, int i1, int i2, int i3) {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void displayChanged(GLDrawable gld, boolean bln, boolean bln1) {
    throw new UnsupportedOperationException("Not supported yet.");
    }
    }
    }
    Attached Images Attached Images


Similar Threads

  1. Mendelbrot set implementation using JOGL
    By Kalyan in forum Member Introductions
    Replies: 0
    Last Post: March 29th, 2011, 05:53 PM
  2. rotating a rectangular image
    By ighor10 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 19th, 2010, 06:12 PM
  3. JOGL Problem
    By Brt93yoda in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 9th, 2010, 07:04 PM
  4. Problem in rotating and moving image at the same time
    By SlimShady in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 17th, 2010, 02:33 PM
  5. JOGL
    By helloworld922 in forum Java IDEs
    Replies: 3
    Last Post: July 21st, 2009, 02:19 AM

Tags for this Thread