Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 / Re: Drawing "Overlay" problem... on: 2006-10-10 17:06:57
Can you post your code or what depth mask and did you use to draw this?
2  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-10 17:05:18
You mean enabling front face culling, then draw scene, and then back face culling and redrawing the whole thing again without depth testing?
I think you may have something here...  Wink

What I am planning is quite simple at the moment so it should not bother the card..

Thanks
3  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-09 14:58:44
I know I have depth testing on, I've written it  Tongue.
But without the depth testing back polygons appear on top of the front ones.

But I will read in the red book about depth testing.
4  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-08 17:28:05
It's true, I put them there, but I rotate and move them so I don't know what polygon is in front of the other all the time, so is there any method or tutorial to do this correctly?

about the texture which has pixels which are transparent to some polygons and some don't, here's a screenshot


Notice that there is a black line obscuring the top polygon in circle A, and the same rectangle appers to be transparent to the back polygon. This behaviour is wierd and it's happening with depth testing on and the blend function is GL_ONE_MINUS_SRC_ALPHA.

Thanks for the help
5  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-07 19:09:45
Well, I have never use depthMask so I don't know what it is...
And how do I sort the polygons? how do I know which is the furthest from the camera?
6  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-07 18:18:37
The blend function GL_ONE_MINUS_SRC_ALPHA gives nice results but only with the depth testing disabled, which makes the display very weird as further polygons show above the closer ones. but with depth testing enabled there are other wierd results, such as black pixels where the texture should be transparent, but some polygons show through the black pixels, and some don't, and not all of the textures behave this way although they are the same texture on the card.

I am not trying to show a semi-transparent texture, but to show an opaque picture with the translucent and transparent areas as they sould apper, so it looks like a 2D sprite in 3D space.

Could there be a problem in the texture loading code? you can see it in the URL above.

Thanks for the help.
7  Java Game APIs & Engines / JOGL Development / Re: Texture loading on: 2006-10-06 09:17:14
Well, I am using the code from http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc/src/f_Textures/TextureLoader.java and it works quite well  Wink.

I am using NeHe's tutorials but the code used to load and display textures is from the site above.
The TextureIO class loads textures, but they come out blurred, even with the demo supplied in the JOGL demo library, so I prefer the code above.
8  Java Game APIs & Engines / JOGL Development / Re: Alpha Blending on: 2006-10-06 08:45:31
Well, The code I use to load textures is found here http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc/src/f_Textures/TextureLoader.java

Notice that the Texture class can bind the texture to the gl context given. and it recognizes automatically which texture has alpha and which don't. The image I am testing has an alpha channel and is in PNG format.

The code used in the init() method 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  
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  
public void init(GLAutoDrawable drawable) {

      // Getting the GL object
      GL gl = drawable.getGL();
     
      // Setting a GLU object
      this.glu = new GLU();
     
      // Setting smooth shading
      gl.glShadeModel(GL.GL_SMOOTH);
     
      // Setting depth buffer and function
      gl.glClearDepth(1.0D);
      gl.glDepthFunc(GL.GL_LEQUAL);
     
      // Enabling 2D textures
      gl.glEnable(GL.GL_TEXTURE_2D);
     
      // Showing only the front face
      //gl.glEnable(GL.GL_DEPTH_TEST);
     
      // Setting nicest perspective
      gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
     
      // Setting the backgroud color to be black
      gl.glClearColor(0.0F, 0.0F, 0.0F, 0.5F);
     
      // Setting the ambient light parameters
      gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient, 0);
       
      // Setting the diffuse light parameters
      gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse, 0);
      gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPosition, 0);
     
      gl.glEnable(GL.GL_LIGHT1);
      gl.glEnable(GL.GL_LIGHTING);
     
      /*
       * Alpha blending
       */

     
      // Setting alpha
      gl.glColor4f(1.0f, 1.0f, 0.0f, 0.0f);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

      gl.glEnable(GL.GL_BLEND);
     
      try {
         
         this.image = TextureManager.LoadTexture("ship_full.png").toGL(gl, this.glu, true);
      }
      catch (IOException ioe) {
         
         ioe.printStackTrace();
      }


Notice that depth testing is commented, as it makes weird effect such as - the alpha is black on some polygons, except for some faces which the black is transparent for them and they show through the black. I've tried different blending functions and turned depth testing on and off, but with no luck.

the display method() 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  
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  
public void display(GLAutoDrawable drawable) {
   
      GL gl = drawable.getGL();

      // Clearing the screen
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   
      /*
       * Drawing a Cube
       */


      // Resestting the modelview matrix
      gl.glLoadIdentity();

      // Move right 3.0 units
      gl.glTranslatef(0.0F, 0.0F, -6.0F);
      gl.glRotatef(this.rotRecty, 0.0f, 1.0f, 0.0f);
      gl.glRotatef(this.rotRectx, 1.0f, 0.0f, 0.0f);

      // Setting the color
      gl.glColor4f(1.0F, 1.0F, 0.0F, 1.0f);
   
      gl.glBindTexture(GL.GL_TEXTURE_2D, this.image);
     
      // Drawing the rectangle
      gl.glBegin(GL.GL_QUADS);
      {
         // Front Face
         gl.glNormal3f(0.0f, 0.0f, 1.0f);
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);   // Bottom Left Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);   // Bottom Right Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);   // Top Right Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);   // Top Left Of The Texture and Quad
         
         // Back Face
         gl.glNormal3f(0.0f, 0.0f, -1.0f);
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);   // Bottom Right Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);   // Top Right Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);   // Top Left Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);   // Bottom Left Of The Texture and Quad
         
         // Top Face
         gl.glNormal3f(0.0f, 1.0f, 0.0f);
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);   // Top Left Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);   // Bottom Left Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);   // Bottom Right Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);   // Top Right Of The Texture and Quad
         
         // Bottom Face
         gl.glNormal3f(0.0f, -1.0f, 0.0f);
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);   // Top Right Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);   // Top Left Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);   // Bottom Left Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);   // Bottom Right Of The Texture and Quad
         
         // Right face
         gl.glNormal3f(1.0f, 0.0f, 0.0f);
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);   // Bottom Right Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);   // Top Right Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);   // Top Left Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);   // Bottom Left Of The Texture and Quad
         
         // Left Face
         gl.glNormal3f(-1.0f, 0.0f, 0.0f);
         gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);   // Bottom Left Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);   // Bottom Right Of The Texture and Quad
         gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);   // Top Right Of The Texture and Quad
         gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);   // Top Left Of The Texture and Quad
      }
      gl.glEnd();
   
      this.rotRectx = (this.rotRectx + this.rectXmodifier) % 360;
      this.rotRecty = (this.rotRecty + this.rectYModifier) % 360;
   }


Can anyone see the problem here?

Thanks in advance.
9  Java Game APIs & Engines / JOGL Development / Alpha Blending on: 2006-10-05 17:48:13
Hello,

Is there any way to draw textures with alpha on the screen without the whole picture to be semi-transparent?
I've tried NeHe's tutorial about blending but I can draw images with the black color as transparent, but if there is a polygon behind the textured polygon it will show through the opaque parts of the image, no matter what the color is (if the alpha value between 0.0 or 1.0).

Does anyone know what the problem is?

Thanks in advance
10  Java Game APIs & Engines / JOGL Development / Re: Frame resizing problems on: 2006-10-05 17:36:27
Yes, it was the gl.glLoadIdentity() after the gl.glMatrixMode(GL.GL_PROJECTION) line.

Thanks for the help!!  Grin
11  Java Game APIs & Engines / JOGL Development / Re: Frame resizing problems on: 2006-10-04 19:28:46
Well, I am adding the canvas to the frame directly like I did before.
But why does the screen turn black after the frame has been resized?
I've seen some code examples and they all use the same code, so what is the problem?
12  Java Game APIs & Engines / JOGL Development / Texture loading on: 2006-10-01 12:50:10
Hello all.

Is there any extensive tutorial on how to load images and display them on screen with JOGL?
I've searched the forums but didn't find any dedicated guide to displaying images.

Thanks for the help.
13  Java Game APIs & Engines / JOGL Development / Frame resizing problems on: 2006-10-01 11:12:17
Hello everyone,

I recently started programming in OpenGL using JOGL and I am using NeHe's tutorial as a reference.
There seems to be a problem after I reshape the Frame in which the canvas is located.
After I resize the frame, the reshape() method() is called, but the screen turns black (the background color).
the code 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  
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

      GL gl = drawable.getGL();
      GLU glu = new GLU();
     
      gl.glViewport(x, y, width, height);
     
      // If the height is 0 set it to 1 to avoid division by zero
      if (height == 0) {
         
         height++;
      }
     
      // Calculate the aspect ratio
      float fovy = (float) width / (float) height;
     
      // Setting the matrix mode
      gl.glMatrixMode(GL.GL_PROJECTION);
     
      // Calculate perspective
      glu.gluPerspective(45.0D, fovy, 0.1D, 100D);

      // Setting ModelView matrix
      gl.glMatrixMode(GL.GL_MODELVIEW);
   }


My question is, should I put the GLCanvas directly inside the frame? and should I use the glOrth() method for any type of aspect ratio calculations?

Thanks in advance.
14  Game Development / Newbie & Debugging Questions / Loading an image as a static one on: 2005-12-09 20:57:02
Hello.

I've been trying to load an image to a static final variable and use it from another class, but I couldn't find a way to do it.
I'm quite new to loading images in Java and displaying them..
I have used this method to load an image, but it can't be used in static context..

Image im = new ImageIcon(getClass().getResource("resourcename.bmp")).getImage();

any help would be greatly appreciated..
15  Game Development / Newbie & Debugging Questions / Re: Two really stupid questions.. on: 2005-09-06 12:25:44
Thanks a lot for your help guys... Wink

actually i have solved the image issue - Image img = ImageIcon((getClass().getResource("ball.gif")).getImage();

but about that mutex thing.. how do you do it? sounds interesting..
16  Game Development / Newbie & Debugging Questions / Re: Two really stupid questions.. on: 2005-09-05 22:54:24
The game is not in FSEM, its on a JPanel inside a JFrame.

Anyway.. i've tried matching the screen's refresh rate and it didn'y help  Undecided, so it's not the problem, probably.

Thanks anyway for your help.. but do you know of any other method of refreshing without tearing?

oh and what about the image loading, can someone give me any help with that?
17  Game Development / Newbie & Debugging Questions / Two really stupid questions.. on: 2005-09-05 17:27:27
First of all, let me just say that this is my first forum message..

And without further Blah Blah i'll get to the questions.

I have recently started developing in Java.. which I think is a great language and decided to do some graphic applications (games).
so I began doing something which uses double buffered graphics, the game consists a falling ball which avoids obstacles by pulling itself up whenever space is pressed (a tribute to a friend of mine who did it in VB  Smiley), anyway.. the mechanics are all done and i want to replace my ball (filled oval) with an image of a ball, I've tried different techniques to load an image and draw it to a Graphics2D object, but no luck.. so could anyone explain how to do it?

My second question relates to the double buffering technique,  I know it is used to prevent flickering. but my obstacles (which are currently empty 3DRects) are tearing as they move (I switched to draw3DRect from fill3DRect because i wanted to hide the tearing effect,
 
My technique is as follows - i get the graphics from an Image, render my ball, obstacles etc. to it and then calls repaint(), I have overrided paintCompotent(Graphics g), so it should be ok (It is explained in a book about java games programming).

Help would be greatly appreciated..
Thanks
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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (55 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (44 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!