Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Time based animitaion on: 2005-02-12 20:05:34
I have a sprite that the user controlls and he moves using time based movement.  My question is how can i make the actual animation frames time based.  He moves at a good rate but the animation is extreamly fast.  Here is the code that draws the sprite.  It is called every time the display meathod is called(about 30 fps).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
public void drawHero(int heroXPosition, int heroYPosition, int direction,
                  boolean move) {
           
           
           
           
            if (move) {
                       
                        if (animationPosition < 7 ) {
                             
                              animationPosition++;
                        } else {
                              animationPosition = 0;
                        }
                       
                  }
                 
                  else {
                        animationPosition = 0;
                  }
           
            gl.glEnable(GL.GL_TEXTURE_2D);
            gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
            gl.glDisable(GL.GL_LIGHTING);
            if (direction == 0) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroUpTextureId[animationPosition]);
            }
            if (direction == 1) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroDownTextureId[animationPosition]);
            }
            if (direction == 2) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroLeftTextureId[animationPosition]);
            }
            if (direction == 3) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroRightTextureId[animationPosition]);
            }
            gl.glBegin(GL.GL_QUADS);
            gl.glTexCoord2f(0.0f, 0.0f);
            gl.glVertex2f((heroXPosition), (heroYPosition));
            gl.glTexCoord2f(1.0f, 0.0f);
            gl.glVertex2f(((heroXPosition) + 128), (heroYPosition));
            gl.glTexCoord2f(1.0f, 1.0f);
            gl.glVertex2f(((heroXPosition) + 128), ((heroYPosition) + 128));
            gl.glTexCoord2f(0.0f, 1.0f);
            gl.glVertex2f((heroXPosition), ((heroYPosition) + 128));
            gl.glEnd();
            gl.glDisable(GL.GL_TEXTURE_2D);
      }


Thanks
2  Java Game APIs & Engines / JOGL Development / Red tint? on: 2005-02-08 02:02:47
What would cause textures to be rendered with a red tint?
3  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 22:49:05
even when i replace GL_MODULATE with GL_REPLACE  it still has the red tint.

Is

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public static void texImage2D(GL gl,GLU glu, BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();
   
        int[] rawData = image.getRGB(0, 0, width, height, null, 0, width);
        convertJavaToGL(width, height, rawData);
         
        gl.glPushClientAttrib(GL.GL_CLIENT_PIXEL_STORE_BIT);
        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 4);
        //gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8, rawData);
       glu.gluBuild2DMipmaps(GL.GL_TEXTURE_2D,GL.GL_RGBA,width,height,GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,rawData);
        gl.glPopClientAttrib();
     
     }
     
     /**
      * Convertes the image data from argb to rgba and flips the image vertically.
      */

     private static void convertJavaToGL(int width, int height, int[] rawData) {
           for (int y1 = 0, y2 = height - 1; y2 >= y1; y1++, y2--) {
                 for (int x = 0; x < width; x++) {
                       int argb1 = rawData[y1 * width + x];
                       int argb2 = rawData[y2 * width + x];

                       int rgba1 = (argb1 << 8) | (argb1 >>> 24);
                       int rgba2 = (argb2 << 8) | (argb2 >>> 24);

                       rawData[y1 * width + x] = rgba2;
                       rawData[y2 * width + x] = rgba1;
                 }

ok?
4  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 22:34:36
I have tried both methods, but niether will remove the red tint.
5  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 21:03:04
wait a minute... all my textures have a red tint.  I didnt notice on that example because it was a red square.  Why the heck could that be?
6  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 19:54:13
AHHH, YES!!!!, It worked.  In addition to changing that method i changed the order of my initializations:

1  
2  
3  
4  
5  
6  
7  
image3 = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("moveobject.gif")));
           
            gl.glEnable(GL.GL_TEXTURE_2D);
            gl.glGenTextures(1,textureid);
            gl.glBindTexture (GL.GL_TEXTURE_2D, textureid[0]);
            ImageUtils.texImage2D(gl,glu, image3);
            gl.glDisable (GL.GL_TEXTURE_2D);


Thank you all!!!
7  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 19:50:35
I changed it again.  What i did before made no sese.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public static void texImage2D(GL gl,GLU glu, BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();
   
        int[] rawData = image.getRGB(0, 0, width, height, null, 0, width);
        convertJavaToGL(width, height, rawData);
         
        gl.glPushClientAttrib(GL.GL_CLIENT_PIXEL_STORE_BIT);
        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 4);
       
        glu.gluBuild2DMipmaps(GL.GL_TEXTURE_2D,GL.GL_RGBA,width,height,GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,rawData);
        gl.glPopClientAttrib();
       }


It  ran but the tile is still white
8  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 19:33:16
I fixed that before but it still does the same thing
9  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 19:16:29
Also, im only trying to map one 32*32 texture to one 32*32 quad
10  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 19:13:51
I changed the image utils method to
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public static void texImage2D(GL gl,GLU glu, BufferedImage image) {
           
              int width = image.getWidth();
           int height = image.getHeight();
           ByteBuffer dest = null;
           int[] rawData = image.getRGB(0, 0, width, height, null, 0, width);
           convertJavaToGL(width, height, rawData);
           int[] data = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
           dest = ByteBuffer.allocateDirect(data.length * BufferUtils.SIZEOF_INT);
           dest.order(ByteOrder.nativeOrder());
           dest.asIntBuffer().put(data, 0, data.length);
           gl.glPushClientAttrib(GL.GL_CLIENT_PIXEL_STORE_BIT);
           gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 4);
          // gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8, rawData);
          glu.gluBuild2DMipmaps(GL.GL_TEXTURE_2D,GL.GL_RGBA,width,height,GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,dest);
         
           gl.glPopClientAttrib();
     }


It now gives my a gray screen.  How exactly does the 2dMipmaps method work?
11  Java Game APIs & Engines / JOGL Development / Re: Textures on: 2005-02-07 11:21:54
I have tried binding before loading and it is still white.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
 public static void texImage2D(GL gl, BufferedImage image) {
           int width = image.getWidth();
           int height = image.getHeight();

           int[] rawData = image.getRGB(0, 0, width, height, null, 0, width);
           convertJavaToGL(width, height, rawData);
           
           gl.glPushClientAttrib(GL.GL_CLIENT_PIXEL_STORE_BIT);
           gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 4);
           gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8, rawData);
           gl.glPopClientAttrib();
     }


This is image utils.

And i did this order to load.
1  
2  
3  
4  
5  
6  
7  
image3 = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("tilepng.png")));
            gl.glEnable(GL.GL_TEXTURE_2D);
            gl.glGenTextures(1,textureid);
            gl.glBindTexture (GL.GL_TEXTURE_2D, textureid[0]);
           
            ImageUtils.texImage2D(gl, image3);
            gl.glDisable (GL.GL_TEXTURE_2D);


it still doesnt work.
12  Java Game APIs & Engines / JOGL Development / Textures on: 2005-02-07 00:53:32
Im having some difficulty applying a texture to a quad.  I have used :
1  
image3 = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("tilepng.png")));

to import an image and then used :

1  
ImageUtils.texImage2D(gl, image3);


to create a texture.

finaly I used:

1  
2  
gl.glGenTextures(1,textureid);
gl.glBindTexture (GL.GL_TEXTURE_2D, textureid[0]);

to id the texture.

Later I:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE );
                  gl.glEnable(GL.GL_TEXTURE_2D);
                  gl.glBindTexture (GL.GL_TEXTURE_2D, textureid[0]);
                  gl.glBegin (GL.GL_QUADS);
                  gl.glTexCoord2f (0.0f, 0.0f);
                  gl.glVertex2f (0.0f, 0.0f);
                  gl.glTexCoord2f (32.0f, 0.0f);
                  gl.glVertex2f (32.0f, 0.0f);
                  gl.glTexCoord2f (32.0f, 32.0f);
                  gl.glVertex2f (32.0f, 32.0f);
                  gl.glTexCoord2f (0.0f, 32.0f);
                  gl.glVertex2f (0.0f, 32.0f);
                  gl.glEnd ();                        
                  gl.glDisable (GL.GL_TEXTURE_2D);


The quad shows up one the screen but it is white and not with a texture.

Any suggestions?
13  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 17:57:34
Do you mean to create 2d quad primitves and map the textures to them?
14  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 17:09:23
I will try that now
15  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 17:07:48
Its working great!!!,  Now I understand what you were saying and it makes alot of sense.   Thank you!  Cool
16  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 15:27:34
here is the code

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
import net.java.games.jogl.*;
import java.awt.event.*;
import javax.imageio.*;
import java.io.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.imageio.ImageIO;
import java.lang.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.net.URL;


/**
 * For our purposes only two of the GLEventListeners matter.
 * Those would be init() and display().
 */

public class SecondGLEventListener implements GLEventListener, KeyListener {
     
      int heroXPosition=100,heroYPosition=100;
      private int texture;
      final int TILE_SIZE=32;
      final int WORLD_SIZEX=12;
      final int WORLD_SIZEY=12;
      GL gl;
    GLU glu;
      GLCanvas glc;
      boolean left;
      boolean right;
      boolean up;
      boolean down;
     
      public void setglcanvas(GLCanvas glc)
      {
      this.glc=glc;      
     
      }
     
      public void init(GLDrawable gld) {
   
            gl = gld.getGL();
            glu = gld.getGLU();
            gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            gl.glViewport(0, 0, 1024, 768); //sets visible area of screen
           gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            glu.gluOrtho2D(0.0, 1024.0, 0.0, 768.0); //sets coordinate system
           
      }

      public void display(GLDrawable drawable) {
       
           
            BufferedImage image,image2,image3;
            gl.glClear (GL.GL_COLOR_BUFFER_BIT);
            try
            {
                  image = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("tile1.gif")));
                  image2 = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("tile2.gif")));
                  image3 = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream ("moveobject.gif")));
                  ImageUtils utils;
       
                  ImageUtils.readPixels(gl, 0, 0, 1, 1, image);
                  ImageUtils.readPixels(gl, 0, 0, 1, 1, image2);
                  ImageUtils.readPixels(gl, 0, 0, 1, 1, image3);
     
                  char map[][] = {
                              {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
                              {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}};
       
                  int tile;
                  int x;
                  int y;
     
      for (y = 0; y < WORLD_SIZEY; y++)
        {
          for (x = 0; x < WORLD_SIZEX; x++)
          {
            tile = map[y][x];
            gl.glRasterPos2i (32*x,32*y);
            if(tile==2)
            ImageUtils.drawPixels(gl,image);
            if(tile==1)
            ImageUtils.drawPixels(gl,image2);
          }
        }
     
                  gl.glRasterPos2i (heroXPosition,heroYPosition);
                  ImageUtils.drawPixels(gl,image3);
     
     
                  GL gl = drawable.getGL();
                  gl.glEnd();
                  gl.glFlush();
   
                  }
                  catch(IOException e)
                  {
              //nothing
                 }
                 
                  if(left) heroXPosition-=10;
                if(right) heroXPosition+=10;
                if(up) heroYPosition+=10;
                if(down) heroYPosition-=10;
 
      }

      public void reshape(
                        GLDrawable drawable,
                        int x,
                        int y,
                        int width,
                        int height
                      ) {}
 
      public void displayChanged(
                              GLDrawable drawable,
                              boolean modeChanged,
                              boolean deviceChanged
                            ) {}

public void keyPressed(KeyEvent e)
{
       
      if(e.getKeyCode() == KeyEvent.VK_LEFT) left = true;
        if(e.getKeyCode() == KeyEvent.VK_RIGHT) right= true;
        if(e.getKeyCode() == KeyEvent.VK_UP) up = true;
        if(e.getKeyCode() == KeyEvent.VK_DOWN) down = true;
     
       
     
       
}


public void keyReleased(KeyEvent e)
{
     
      if(e.getKeyCode() == KeyEvent.VK_LEFT) left = false;
        if(e.getKeyCode() == KeyEvent.VK_RIGHT) right= false;
        if(e.getKeyCode() == KeyEvent.VK_UP) up = false;
        if(e.getKeyCode() == KeyEvent.VK_DOWN) down = false;      

}

public void keyTyped(KeyEvent e)
{
     

}



     
     
               
     
}
17  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 15:21:45
Im now using FPSAnimate to lock the frame rate.  The image moves better but still lags when more images are drawn to the screen.  The files are soo small.  Why am  I experiencing this lag?
18  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 04:52:03
Im kind of confused.  Wouldnt something like that be used to move a standalone sprite based on elapsed time?  The sprite im talking about is controlled by the user.
19  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 00:39:54
I also notice that even with one sprite on the screen, if i hold down the arrow key it skips every few seconds while moving.  How can i make this program run more smoothly?
20  Java Game APIs & Engines / JOGL Development / Re: Help with Animator on: 2005-02-05 00:15:32

Originally, I was drawing my sprite after drawing an array of tile images under it.   It was an array of 32X34 tiles,  each being 32*32 pixles.  After commenting out the tile map my  sprite it moves smoothly.  Could this be because i was displaying too many tiles on the screen?  
21  Java Game APIs & Engines / JOGL Development / Re: Display image file on glcanvas ??? on: 2005-02-04 22:39:23
Thanks alot!, I actually found that a little after posting my message.  It makes alot more sence now.  
22  Java Game APIs & Engines / JOGL Development / Help with Animator on: 2005-02-04 22:37:03
I am trying to move a sprite around the screen when the user presses the arrow keys.  Im using the animator class to drive the display meathod.  This is working but the image moves in a jerky manner.   Is there something im missing about use of the animator class?  Could this be a frame rate issue?

Thanks
23  Game Development / Newbie & Debugging Questions / Display image on glcanvas ??? on: 2005-02-03 19:48:46
Hello

Im a complete noob with JOGL.  I have a basic JOGL program  up and running and im trying to figure out how to import and display an image file to the glcanvas.  What would be the best way to do this.

As a side note im also curious about how the animate class works.  When you use this to update  display(); does it do double buffering for you to achive smooth animation?  If not, whats the best way to begin experimenting with double buffers in JOGL.

Thanks Alot!!!

P.S. Whats the general consensus about where the best place to find JOGL information is.  So far I have found the forum to be the best.
24  Java Game APIs & Engines / JOGL Development / Display image file on glcanvas ??? on: 2005-02-03 19:47:28
Hello

Im a complete noob with JOGL.  I have a basic JOGL program  up and running and im trying to figure out how to import and display an image file to the glcanvas.  What would be the best way to do this.

As a side note im also curious about how the animate class works.  When you use this to update  display(); does it do double buffering for you to achive smooth animation?  If not, whats the best way to begin experimenting with double buffers in JOGL.

Thanks Alot!!!

P.S. Whats the general consensus about where the best place to find JOGL information is.  So far I have found this forum to be the best.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (11 views)
2014-07-23 21:16:32

Riven (12 views)
2014-07-23 21:07:15

Riven (13 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!