Java-Gaming.org Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (565)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (605)
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] 2 3 4
1  Java Game APIs & Engines / OpenGL Development / Re: How to set texture coords without duplicate vertex positions on: 2015-02-24 07:28:48
Why a VBO for each "Gui" ?
You can push all "Gui" items in the same VBO. In this case you just have to bind your atlas texture and your vbo and call how many required drawElements... method (with appropriate index)
2  Discussions / General Discussions / Re: What's your day job? on: 2015-02-16 07:29:25
I'm a CTO in a small french software company (around 40 employees)
We wrote softwares in many realms like insurance, stock gestion, ....

It took/take me a lot of time and writing some "free" stuff at home is a way to wash my head.
I mean free for theses topics:
  - no deadline / planning
  - no success garantee
  - no client's returns
  - no mandatory subjects

That's why if at home i don't finish a project, it's not a problem for me Tongue

The only things i regret with home job is to lost the team work (i love that),
But it's the price for having previous topics : it's hard to work without planning or sucess garantee when you start to work with someone else (just for respect him).

So, i learn some low-level stuffs at home (like OpenGL) for contrast with all high-level stuffs we work with at work (many of them was done by me).

Séb.




3  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-02-15 20:23:54
Implemented the RadialGradiant paint with multiple stops (software rasterizer for now)


4  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-02-14 20:49:56
wrote my vecmath package.
I don't really understood the Hermite polynomirals interpolation but i was able to copy the formulae Tongue
5  Java Game APIs & Engines / OpenGL Development / Re: [Solved] Rendering text in lwjgl without slick on: 2015-02-09 19:33:21
Most of sample codes don't handle unicode charsets that is not trivial with theses 250K valid codepoints (1 000 000 total codepoints).
If you want a general fonts system, it's a pain to write it.

i will give it a try soon !!!

6  Discussions / General Discussions / Re: What does this return for you? on: 2015-02-08 08:53:41
1  
2  
3  
4  
Windows 7
AMD Radeon HD 5700 Series
4.4.13283 Compatibility Profile Context 14.501.1003.0
ATI Technologies Inc.

7  Discussions / Miscellaneous Topics / Re: Unit Testing: Waste Of Time? Discuss on: 2015-02-05 18:44:55
You can use "unit tests" without going completely in a TDD process.
I try to have a pragmatic approach in my job or for personnal projects that is the following:
  - Wrote unit test during the developpement process for parts that i found critical of difficult.
 
Critical because i haven't the right to introduce a bug
Difficult because i will have difficulty to enhance theses parts without taking some risks to break something.

In this stage, i not write a billions of unit tests and i try to keep reasonnable.

After this developpement process, become the maintenance time when a bug is found.
When a bug is found in production, i consider we never see it in all stages we can have (dev, internal test, client test)
So it's not a "simple bug", and in this case, we wrote a unit test that can check this precise bug that protect us to have it again.

With this approach, i can reduce costs of unit tests (in term of time and effort) and trying to maximize theses benefits.

Best regards,
Séb.




8  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-02-03 21:10:20
I work since this week-end on an implementation of a LinearGradient paint.

The LinearGradient supports a gradient vector with differents color-stop in order to perform a multiple gradient paint.

With this code :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
// rainbow
LinearGradient gradient =
{
   Color c1 = new Color(255,0  ,0  );
   Color c2 = new Color(255,255,0  );
   Color c3 = new Color(0  ,255,0  );
   Color c4 = new Color(0  ,255,255);
   Color c5 = new Color(0  ,0  ,255);
   Color c6 = new Color(255,0  ,255);
         
   gradient = new LinearGradient(0 , 0 , 800 , 300 , new Color[]{c1,c2,c3,c4,c5,c6},new float[]{0f,0.15f,0.30f,0.5f,0.65f,0.80f} , RepeatPolicy.CLAMP );
}


and

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    @Override
   public void paint(Window window) {
      Graphics2D g2d = window.createGraphics();

      g2d.setPaint(gradient);
      g2d.fillRect(0, 0, window.getWidth() , window.getHeight() );
      g2d.setColor( Color.WHITE );
      g2d.drawLine( 0 , 300 , 800 , 300 );
   
      g2d.dispose();
   }


I obtain this :
 

My custom implementation can be viewed here : http://i.imgur.com/Wk0rGsW.png
The same test with a swing implementation here : http://i.imgur.com/MDmbygs.png
The rasterized form of the gradient (texture generated) : http://i.imgur.com/GIWaWUM.png

As we can see, i have some little bit differences with the swing version !!
I must go further on it to find why !! i must have an issue somewhere but it's late and i don't find it !!!

Edit:
I found my issue this morning (it was my rotation point that was badly computed) and now i obtain exactly the same result than the swing version.
I updated images on this thread accordingly this correction !!! I can now consider my implementation completed (after some code cleanup and comments)


Séb.

9  Discussions / General Discussions / Re: Schemes to teach the masses to code on: 2015-02-02 15:03:47
We made 2 lessons on http://code.org this week-end with my childrens and they really enjoy it !!

We will continue and i hope they would go further on this new hobby !!

I think that in 15 years laters, someone that is not comfortable with a PC and/or technology will be in a strong diffculty in the proffessionnal place.
So, childrens must learn theses stuff. It doesn't mean they must learns to code but imho it should be a good things.

Séb.
10  Java Game APIs & Engines / OpenGL Development / Re: Linear Gradient on a QUAD from 2 colors on: 2015-02-01 21:33:01
So i answer to myself (because maybe it will help a day someone else)

My intuition saying that we should use for 2 other vertices, the color at the center of the gradient line is a false assumption.
Or at least, it was true only for a gradient line that fit a perfect square.

So, it's more complicate with a quad.

Let's go with this example (full size of image : http://i.imgur.com/RCb1fGc.png)



Principle
It's a linear gradient, that mean all points on an orhogonal line of the gradient line has the same color !
That mean, for computing the color for 2 others vertices, we must find the orthogonal line of the gradient line that pass by the vertex and check where is the intersection with the gradient line.
After what, we can compute the distance of this intersection point and the start point (x0,y0).
This distance (in a range of [0 ~ 1] relative to the length of the gradient line) give us the interpolation factor to apply for finding the color at this intersection point.
This color is the same for our vertex. That's all.

We must compute theses distances:
1  
2  
3  
 
 dU that give the factor of interpolation to apply from color A to colorB for the vertex (x0,y1)
 dV that give the factor of interpolation to apply from color A to colorB for the vertex (x1,y0)


Compute the equation of our gradient line:
The slope is the change in height divided by the change in horizontal distance : m = (y0 - y1) / (x0 - x1)
The slope-intercept formula is y = mx + b that give b = y - mx        

1  
2  
3  
 
  float m = (y0 - y1) / (x0 - x1);
  float b = y0 - (m * x0);


Compute the equation of the orthogonal line of the gradient line that pass by (x0,y1)
The slope of a line perpendicular to a line is the negative reciprocal of its slope : 1 / -m
1  
2  
  float mo = 1f / -m;
  float bo = y1 - ( m * x0 );


Compute the intersection point of the gradient line and the orthogonal line
At the intersection point, both equation lines are equals, that give y == mx + b == mox + bo
That provide theses equations for computing the intersection :
  x = (bo - b) / (m - mo)
  y = mx + b

1  
2  
  float xU = (bo - b) / (m - mo);
  float yU = (m * xU) + b;


Computing the distance of the point (x0,y0) to the intersection point (that provide dU)
I use the simple pythagor theorem:
1  
2  
3  
4  
5  
  float d1 = xU - x0;
  float d2 = yU - y0;
           
  dU = (float)Math.sqrt( (d1*d1) + (d2*d2) );
  dU = dU / length;                                          // Length is the distance of the gradient line from (x0,y0) to (x1,y1). That allow to convert dU in a [0 ~ 1] range.


Compute dV from dU
dV can be computed by symetric from dU.
1  
  dV = 1 - dU;


Interpolate colors at (x0,y1) and (x1,y0)
- Considering cA[] giving color's component of color A at (x0,y0)
- Considering cB[] giving color's component of color B at (x1,y1)

We can obtain cU[] giving color's component at (x0,y1)
1  
2  
3  
4  
5  
  float[] cU = new float[4];
  cU[0] = ( (cB[0] - cA[0]) * dU ) + cA[0];
  cU[1] = ( (cB[1] - cA[1]) * dU ) + cA[1];
  cU[2] = ( (cB[2] - cA[2]) * dU ) + cA[2];
  cU[3] = ( (cB[3] - cA[3]) * dU ) + cA[3];


And the same for cV[] giving color's component at (x1,y0)
1  
2  
3  
4  
5  
  cV = new float[4];
  cV[0] = ( (cB[0] - cA[0]) * dV ) + cA[0];
  cV[1] = ( (cB[1] - cA[1]) * dV ) + cA[1];
  cV[2] = ( (cB[2] - cA[2]) * dV ) + cA[2];
  cV[3] = ( (cB[3] - cA[3]) * dV ) + cA[3];


I tested, i obtain the same result than LinearGradientPaint from awt/swing
Maybe it exist a simpler method but this one seems to work !


11  Java Game APIs & Engines / OpenGL Development / Linear Gradient on a QUAD from 2 colors on: 2015-02-01 12:48:42
Hi,

i have to render a quad with a linear gradient but i have colors for only 2 vertices like this scheme:



Ideally, i would let OpenGL to find which colors to interpolate for 2 others vertices but i'm suspect it is impossible. it's right ?

So, how do interpolate theses yourself ?

My intuition say me that it's corresponds to translate the diagonal (respecting //) until they reach another vertex.
In theses cases both other vertices would touch the diagonal at it's center ! (it's right ?) (it's right only if the gradient line fit a square)

If it's the case, i'm would compute the color at 50% of the gradient so that would being :
1  
2  
3  
4  
 
  red    = ( ( redB - redA ) / 2 ) + redA
  green = ( ( greenB - greenA ) / 2 ) + greenA
  blue   = ( ( blueB - bleuA ) / 2 ) + blueA
 

Best regards,
Sébastien.






12  Game Development / Newbie & Debugging Questions / Re: Textbook for Java NIO Networking. on: 2015-01-30 11:00:47
I don't know if it can help you, but i studying more deeply nio some years ago and i started to write a server api available here : https://code.google.com/p/objectserver/
It's quite functionnal but it was mainly for studying purpose. The code is quite well documented (if i remember well, you should start from EventDispachThread class).

I don't recommand to use it. I don't maintain or use it !! now i understand how it works, i use netty Tongue

But for books materials, i have no advices to do... sorry.
13  Discussions / General Discussions / Re: Schemes to teach the masses to code on: 2015-01-30 09:27:02
It's funny, my childrens ( 8 years old boy and 11 years old girl) wants to learn programming (seeing it's father to write code so often has an impact  Grin).
I will start to teach this week-end and i'm quite excited since i started programming when i was 7 years old in basic and i'm nostalgic ^^

I agree on one point, childrens construct their hobbies from which they can have access !!!.
If childrens are on an environnment (social, family, country, ...) that not help us to have discover the computer sciences, they can't discover they like it !!

But the problems occurs at a more general level ! when i see so many childrens and families around me without any contact with cultural things like arts, books, sports or even sciences, i'm very  afraid...

Séb.
14  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-28 23:19:30
I'm working on my support of Image and especially sub-image !!

An exemple of mirrored repeat from an image inside an atlas :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
  if( boxImage == null ) {
      boxImage  = image.getSubimage(768,128,128,128);
  }
  if( texture == null ) {
    texture = new Texture(boxImage , new Rectangle(0 , 0 , 128 , 128 ) , TextureWrapPolicy.REPEAT_MIRRORED , TextureWrapPolicy.REPEAT_MIRRORED , true );
  }

  g2d.setPaint( texture );
  g2d.fillRect(x, y, 512, 512);
  g2d.dispose();


Result :


from this atlas :



Séb.
15  Java Game APIs & Engines / OpenGL Development / Re: Fill Ellipse from a fragment shader on: 2015-01-26 13:28:02
Hi,

I'm not on the "AA" feature (that seems to be another complete topic  persecutioncomplex)
But the discard() is not mandatory if you play with glBlend function by example if you set an equivalent than AlphaComposite.SRC ?

16  Java Game APIs & Engines / OpenGL Development / Re: Fill Ellipse from a fragment shader on: 2015-01-21 21:10:47
i'm completing the fragment shader from advices.

The result is here :

The shader look's like

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  
#version 330

varying vec2 v_boundingBoxPosition;

void checkFragment() {

   /**
    * Ellipse equation =  (x/a)2 + (y/b)2 = 1
    *     a = horizontal radius
    *     b = vertical   radius
    *
    *
    * Bounding box is a vec2 that correponds to this rectangle coordinate
    *        (-1,-1)            (+1,-1)
    *                  (0,0)
    *        (-1,+1)            (+1,+1)
    *
    *  The varying result in this fragment shader correspond to [ (x/a) , (y/b) ]
    *  We can perform a dot() for doing the pow(2)
    */

    float d  = dot( v_boundingBoxPosition , v_boundingBoxPosition );
    if( d > 1 ) {
       discard;
    }    
}


The fragment result looks much nicer.

But in term of performance, i bench this for 600 ellipses per frame (i use large buffer for prevent implicit flush while pushing datas):
  - Bresenham : 10 ms for pushing datas on the batcher. 6.8 ms for flush it
  - Shader      : 0.1 ms for pushing datas on the batcher. 3.5ms for flush it.

In both of them i take the worst case but in average it's most:
  - Bresenham : 10 ms for pushing datas on the batcher. 6 ms for flush it.
  - Shader      : 0.1 ms for pushing datas on the batcher. 2.8 ms for flush it.

I must check if i have not some performance issues in the push data method. but in all cases, the flush is also faster in the shader version.

So, ATM the shader way seems the way to go...


EDIT: The bresenham algorithm push 6 floats per vertices (color + 2d position) that mean 24 bytes per vertices
The ellipse drawn use 584 vertices that means 14 016 bytes for an ellipse (14 Ko)
When i draw 600 ellipses, it's come up to 8 409 600 bytes (8.02 Mo).
the FloatBuffer.put(...) take me the 50% of total time of the push sequence. It seems strange that it's longer to fill it in RAM than sending it to the GPU...

EDIT : I updated the fragment shader, i don't use anymore an uniform. the varying vec2 is ready to use and minimize computation inside the fragment shader like pitbuller said.
17  Java Game APIs & Engines / Engines, Libraries and Tools / GLFW 3.1 is out on: 2015-01-20 13:09:14
Hi,

I just seen that GLFW 3.1 is now released since 18/01/2015

We can see the changelog http://www.glfw.org/changelog.html
I know LWJGL include an hybrid version but i hope it will include this one soon !! I found GLFW a great library.

Séb.



18  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-18 23:12:35
I implemented the Bresenham algorithm for drawing and filling ellipse : http://www.java-gaming.org/topics/fill-ellipse-from-a-fragment-shader/35411/msg/335293/view.html#msg335293
Il will continue on the fragment shader version with advises of other members.
19  Java Game APIs & Engines / OpenGL Development / Re: Fill Ellipse from a fragment shader on: 2015-01-18 19:26:16
If you want to do this in a fragment shader, wouldn't you be better using texture coordinates rather than gl_FragCoord and your uniforms?


The easiest way to do this in a fragment shader is to NOT rely on gl_FragCoord. If you rotate the coordinates, the result stays the same. A better idea is to assign "texture" coordinates to each corner and have the shader rely on those instead, since those coordinates will be and interpolated correctly after rotation.

Thanks all, it's the right way with the fragment shader. I don't found it alone.... damn Tongue
It's not yet naturals for me to write shaders and understood all subtles with theses !!!

The most hard things with openGL is the debugging !! .
When it don't work as you wish, it's a reallly a painfull to find the cause.

Thanks all, for your advices, but il will stick with the Bresenham implementation.
20  Java Game APIs & Engines / OpenGL Development / Re: Fill Ellipse from a fragment shader on: 2015-01-18 16:16:56
I give it a try to the Bresenham algorithm

Some result here (i know there is no reason to be so enthousiast Tongue)

1  
2  
3  
      
g2d.setColor( Color.YELLOW );
g2d.fillOval( 400 ,  50 ,  200 ,  100 );







1  
2  
3  
4  
5  
      
g2d.setColor( Color.YELLOW );
g2d.transform( AffineTransform.identity().rotate( 0.2f , 400 + 100 , 50 + 50 ) );
g2d.fillOval( 400 ,  50 ,  200 ,  100 );
g2d.setTransform( null );






 
1  
2  
3  
4  
5  
      
g2d.setColor( Color.YELLOW );
g2d.transform( AffineTransform.identity().rotate( 0.2f , 400 + 100 , 50 + 50 ) );
g2d.drawOval( 400 ,  50 ,  200 ,  100 );
g2d.setTransform( null );






1  
2  
3  
4  
g2d.setPaint( texture ); // set a Texture instead of a color to fill it
g2d.transform( AffineTransform.identity().rotate( 0.2f , 400 + 100 , 50 + 50 ) );
g2d.fillOval( 400 ,  50 ,  200 ,  100 );
g2d.setTransform( null );




Here the implementation using Breshenham.
I just have a difficulty to pre check buffers size of my batcher. So ATM i must check a BufferOverFlowException that is not quite fun...

I don't do any benchmarks for now but i find this solution much functionnal than the fragment shader (but less fun ^^)

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  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
/**
     *  https://sites.google.com/site/ruslancray/lab/projects/bresenhamscircleellipsedrawingalgorithm/bresenham-s-circle-ellipse-drawing-algorithm
     */

    private void paintOvalBresenham(float x0, float y0, float rx, float ry , boolean fill , Graphics2DAttributes g2dAttributes , boolean overflowed ) {
       /**
        * Basics primitives perform pre check on all buffers of this batcher before pushing datas like:
        *      // 1 primitive 4 vertices and 6 indices.
        *      checkBufferSize( 1 , 4 , 6 );  
        *    
        * This implementation is quite more complicated and i can't determine how much vertices and indices i will use.
        * So, i don't do any pre check but if i have a buffer overflow, i discard this primitive, flush() and restart this paint process
        *
        * I can assume at least to have 1 primitive enought
        */

       checkBufferSize( 1  , 0 , 0 );
       
       /**
        * Get the primitive
        */

       Primitive p = getPrimitive( ( fill ? GL11.GL_TRIANGLE_FAN : GL11.GL_LINE_LOOP ) , g2dAttributes );
       
      float a2  = rx * rx;
       float b2  = ry * ry;
       float fa2 = 4 * a2, fb2 = 4 * b2;
       
       /** Bresenham algorithm compute 2 octants and determine 6 others by symetric computations
        *    - Theses 2 first octants are done without the use of cos/sin operations but use (* +)
        *    - Theses 6 others octants are done only with translation ( + or - operations)
        *
        *  The difficulty is able to order vertices in the "indices buffer" sinces points are not computed sequentially...
        *  
        *  Which is the order of points computation:
        *    - Each octant is numbered from 1 to 8. We compute octants 1,2,3,4 (multiplexed) and after we compute octants 5,6,7,8 (multiplexed)
        *    - Some octants as computed in a clockwise and some others in counterclockwise
        *    - The drawing process draw octants in this order 1 , 5 , 7 , 3 , 4 , 8 , 6 , 2 in the counterclockwise.
        *    - Some octant are clockwise and some others in counterclockwise by nature of symetric computation used.
        *               - Octant 1 : counterclockwise
        *               - Octant 5 : clockwise
        *               - Octant 7 : counterclockwise
        *               - Octant 3 : clockwise
        *               - Octant 4 : counterclockwise
        *               - Octant 8 : clockwise
        *               - Octant 6 : counterclockwise
        *               - Octant 2 : clockwise
        *                
        *  
        *   - Octants topology:
        *  
        *                   ***************
        *              *****   \ 4 | 3  /  *****
        *            **    8     \ |  /    7    **
        *          **             \|/             **
        *          *---------------X---------------*
        *          **      6     / | \     5      **
        *            **         /  |  \         **
        *              *****  /  2 | 1  \  *****
        *                   ***************
        */

       int sizeOctants1234 = 0;
       int sizeOctants5678 = 0;
       
       try {
          /* first half */
          float x, y, sigma;  
          for (x = 0, y = ry, sigma = 2*b2+a2*(1-2*ry); b2*x <= a2*y; x++)
          {
             p.pushVertex( x0 + x , y0 + y ); // Octant 1
             p.pushVertex( x0 - x , y0 + y ); // Octant 2
             p.pushVertex( x0 + x , y0 - y ); // Octant 3
             p.pushVertex( x0 - x , y0 - y ); // Octant 4
             sizeOctants1234++;
             
              if (sigma >= 0)
              {
                  sigma += fa2 * (1 - y);
                  y--;
              }
              sigma += b2 * ((4 * x) + 6);
          }
   
          /* second half */
          for (x = rx, y = 0, sigma = 2*a2+b2*(1-2*rx); a2*y <= b2*x; y++)
          {
             p.pushVertex( x0 + x , y0 + y ); // Octant 5
             p.pushVertex( x0 - x , y0 + y ); // Octant 6
             p.pushVertex( x0 + x , y0 - y ); // Octant 7
             p.pushVertex( x0 - x , y0 - y ); // OCtant 8
             sizeOctants5678++;
   
             if (sigma >= 0)
              {
                  sigma += fb2 * (1 - x);
                  x--;
              }
              sigma += a2 * ((4 * y) + 6);
          }
       }
       catch( BufferOverflowException e ) {
          /** Ouch, we have not enough place for put all vertices, we flush this batcher without the primitive
           */

          if( overflowed ) throw new IllegalStateException("OpenGLSupport with too small buffer size for this method");
          primitiveCount--; // discard this primitive
          flush();
          paintOvalBresenham(x0, y0, rx, ry, fill, g2dAttributes , true);
          return;
       }
       
       /** Now we put all vertices, we know how many indices we must have
        *  We can do a pre check in order to avoid the BufferOverflowException...
        */

       if( ! checkBufferSize( 0 , 0 , ( 4 * sizeOctants1234 ) + ( 4 * sizeOctants5678 )  , false ) ) {
          if( overflowed ) throw new IllegalStateException("OpenGLSupport with too small buffer size for this method");
          primitiveCount--; // discard this primitive
          flush();
          paintOvalBresenham(x0, y0, rx, ry, fill, g2dAttributes , true);
          return;
       }
       
       /** Push indices
        */

       IntBuffer buffer = indicesBuffer.getBuffer();
       
       final int strideOctants1234 = 4 * sizeOctants1234;
       final int strideOctants5678 = 4 * sizeOctants5678;
       
       /**
        * Computing where start each octants
        */

       final int offsetOctant1 = 0;                                                      // forward
       final int offsetOctant4 = 3;                                                 // forward
       final int offsetOctant6 = strideOctants1234 + 1;                              // forward
       final int offsetOctant7 = strideOctants1234 + 2;                              // forward
       final int offsetOctant5 = strideOctants1234 + strideOctants5678 - 4;              // backward
       final int offsetOctant3 = strideOctants1234 - 2;                             // backward
       final int offsetOctant8 = strideOctants1234 + strideOctants5678 - 1;             // backward
       final int offsetOctant2 = strideOctants1234 - 3;                          // backward
       
       // octant 1
       int offset = offsetOctant1;
       int stride = 4;
       for(int i = 0 ; i < strideOctants1234 ; i += stride ) {
          buffer.put( offset + i );
       }
       // octant 5
       offset = offsetOctant5;
       for(int i = 0 ; i < strideOctants5678 ; i += stride ) {
          buffer.put( offset - i );
       }
       // octant 7
       offset = offsetOctant7;
       for(int i = 0 ; i < strideOctants5678 ; i += stride ) {
          buffer.put( offset + i );
       }
       // octant 3
       offset = offsetOctant3;
       for(int i = 0 ; i < strideOctants1234 ; i += stride ) {
          buffer.put( offset - i );
       }
       // octant 4
       offset = offsetOctant4;
       for(int i = 0 ; i < strideOctants1234 ; i += stride ) {
          buffer.put( offset + i );
       }
       // octant 8
       offset = offsetOctant8;
       for(int i = 0 ; i < strideOctants5678 ; i += stride ) {
          buffer.put( offset - i );
       }
       // octant 6
       offset = offsetOctant6;
       for(int i = 0 ; i < strideOctants5678 ; i += stride ) {
          buffer.put( offset + i );
       }
       // octant 2
       offset = offsetOctant2;
       for(int i = 0 ; i < strideOctants1234 ; i += stride ) {
          buffer.put( offset - i );
       }
       p.end();
   }


Sébastien.
21  Java Game APIs & Engines / OpenGL Development / Re: Fill Ellipse from a fragment shader on: 2015-01-18 13:55:36
When using the "vertices" solution, the main problem is to determine how many vertices we should use (depending on the resolution and size of the ellipse).
Using the fragment technics, it's openGL that determine the "size" of the fragment and you haven't to worry about.

Another technic is to use by example the Bresenham's algorithm and you don't have to worry about determining how many vertices you need. but:
   -  when you push only points, it's quite ok, when you want lines, you need to set vertices in the correct order that is a pain with such algorithm.
   -  using the plain old trigo algo is enough but i don't like to compute cos/sin for every points.

i give a try to the bresenham's and will make some benchs
22  Java Game APIs & Engines / OpenGL Development / Fill Ellipse from a fragment shader on: 2015-01-18 12:40:09
I always rewriting some old 2D stuffs using old OpenGL glBegin/glEnd for use modern openGL statements.

I'm writing a fillOval implementation using a fragment shader instead of pushing a lot of vertices for drawing my ellipse.

The idea is to paint a classic rectangle (2 triangles composition) and use a fragment shader that discard all fragment that is not inside the ellipse.

As is, i push on OpenGL in order to draw my ellipse :
  - 4 vertices
  - 6 indices 
  - 2 "vec2" uniforms
       - the center of the ellipse
       - the radius of the ellipse

my fragment shader (responsible to discard fragments) looks like this one:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
#version 330

uniform vec2 u_centerOval;
uniform vec2 u_radiusOval;

layout(origin_upper_left) in vec4 gl_FragCoord;

out vec4 outputColor;

void checkFragment() {
   /**
    * Ellipse equation =  (x/a)2 + (y/b)2 = 1
    *     a = horizontal radius
    *     b = vertical   radius
    */

   
    float e1 =  ( gl_FragCoord.x - u_centerOval.x ) / ( u_radiusOval.x );
    float e2 =  ( gl_FragCoord.y - u_centerOval.y ) / ( u_radiusOval.y );
   
    float d  = (e1 * e1) + (e2 * e2);
    if( d > 1 ) {
       outputColor = vec4(1.0 , 0.0 , 0.0 , 1.0 ); // discard;
    }    
}



So, it works not so bad. I have an "aliasing" issue, but i will see this later.

But now, if i paint with this statement:
1  
2  
  g2d.setColor( Color.YELLOW );
  g2d.fillOval( 400 ,  50 ,  200 ,  100 );


i obtain this

But if i apply an affine transformation like this:

1  
2  
3  
4  
 g2d.transform( AffineTransform.identity().rotate( 0.2f , 400 + 100 , 50 + 50 ) );
 g2d.setColor( Color.YELLOW );
 g2d.fillOval( 400 ,  50 ,  200 ,  100 );
g2d.setTransform( null );


i obtain this

That's quite normal since my fragment shader don't take in account my affine transform.
It's only my vertex shader that use it (and it rotate the rectangle as well).

i should inverse my transformation on gl_FragCoord in order to compute the ellipse equation ?
It's a pain, all matrices are not invertible. I can pass it as an uniform.

Have you a better idea ?
At this point, maybe this technical approach is completely crazy but at first  thinking i found it quite fun.

Best regards,
Sébastien.
23  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-17 23:11:17
What i did:
 - Removed deprecated openGL functions like glMatrix, glOrtho.... and use instead a vertex shader.

What i got:
 - A black screen instead of what i would to render  Huh

So it's time to go bed  Angry

I won over the black screen and retrieve what i would to render  Grin
I had 2 problems:
  - My orthographic matrix was badly computed and i provided to the vertex shader a completely crazy matrix.
  - I used the asFloatBuffer() from a ByteBuffer but i don't seen that position() and limit() was independant from theses both buffers.. so i pass to attribPointer completely wrong datas.

With theses 2 mistakes, yesterday, i was far to see somethings to my screen  Roll Eyes
24  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-16 23:32:51
What i did:
 - Removed deprecated openGL functions like glMatrix, glOrtho.... and use instead a vertex shader.

What i got:
 - A black screen instead of what i would to render  Huh

So it's time to go bed  Angry
25  Discussions / General Discussions / Re: New rules regarding Game Engine topics on: 2015-01-14 16:25:03
I'd even say that, if someone really wants to make something more generic/flexible, it'd probably be better to develop a game with modding capabilities, rather than a general use engine.

I think we can't provide theses statements with this simplicity when most of amateur dev works in their free time in stuff they "like" whatever it will be usefull or not.
So if your goal is to built a game and won money with it, maybe you should'nt go into the way of writing an engine (or equivalent).
But as opposed, if you want learn, have fun and that's fun come with such tasks !! why not !!

I know that peoples here don't really like or approve guys that work on theses own stuffs but for me it's not a bad things if it has not a negative impact (by exemple on a team or budget, ...)
Personnaly, i can work on a library even if i have no plan to use it because it's fun for me !!!

Now, i agree that we can have some variable "quality level" of theses homemade engines.
But if a day i post what i done as framework (2d only), it will not for providing the "next level tools" but mainly for have feedback about it and improve it.
I assume that this forum is for such purpose !!!

Séb.





26  Java Game APIs & Engines / OpenGL Development / Re: OpenGL multiple shaders nonsense! on: 2015-01-13 22:02:37
I'm a newbie in shader since i just start to play with theses, but i'm a little surprised from what we read here !!

I bieleved we can attach more than one shaders from the same type on a program !!!


We can read on the glAttach this documentation:

All operations that can be performed on a shader object are valid whether or not the shader object is attached to a program object. It is permissible to
attach a shader object to a program object before source code has been loaded into the shader object or before the shader object has been compiled. It
is permissible to attach multiple shader objects of the same type because each may contain a portion of the complete shader
. It is also permissible to
attach a shader object to more than one program object. If a shader object is deleted while it is attached to a program object, it will be flagged for
deletion, and deletion will not occur until glDetachShader is called to detach it from all program objects to which it is attached.


After some research, we can have more than one shaders of the same type but only one "main" method ? is it right ?



27  Java Game APIs & Engines / OpenGL Development / Re: modern OpenGL discussion on: 2015-01-11 13:15:52
So, i reply here for giving feedback of theses 3 past days.

I rewrote my batcher with vertex array instead of VBO.

I used IntBuffer for indices (since it's more simple than ByteBuffer) for glDrawElements but LWJGL don't have method facilities for use an IntBuffer and providing the number of vertices to fetch except by consumming all datas from the buffer. But my indices buffer is filled with all primitives that i had to draw by multiple calls.

I had to call the unchecked version :
1  
   GL11.nglDrawElements( p.type , p.indicesCount , GL11.GL_UNSIGNED_INT, MemoryUtil.memAddress( indicesBuffer ) );


Now, i have perform a 2d texturing from an atlas texture. I had done all shader/program stuff in order to activate the fragment shader that will do the texturing from an atlas texture.

I have two technical approachs for handling shaders
  - only one program but i attach/detach shaders when needed
  - One program for each shaders topology.

Both of them can be achieve with the same kind of API where i just enable/disable shaders and back-end choose/generate the appropriate program or alter it (depends of the solution).

What is the best practice ?

At this time, i will have 2 shaders (one for texturing from atlas and a second for multiples stop gradiant paint)

Best regards,
Sébastien.






28  Java Game APIs & Engines / OpenGL Development / Re: modern OpenGL discussion on: 2015-01-07 21:03:02
Hi,

Thanks for your detailed answer.

So, ok, fixed pipeline and deferred rendering are two differents things. i deep into deferred rendering with VBO. but for dynamic pipeline it's the use of shaders (vertex, fragment, geometry).

while  reading you, you are seems to say that VBO and shaders are not suitable together and you must go to VAs if i want to use shaders (that i will soon for doing repeated atlases subregion) ?

Anothers small questions

You say than glTranslatef(), glRotatef() are fixed pipeline stuff, so that means we should avoid theses ? At this time i don't use theses but i use some matrix mode when i need to apply an affine transform (that remains the same than glTranslatef() or glRotatef() but provide more flexibilty).

When reading your example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//With VAs
//Init
FloatBuffer fb = BufferUtils.createFloatBuffer(3 * (2 + 3)); //3 vertices with 2 position floats and 3 colour floats.
fb.put(new float[] {...}); Imagine this is the data for a triangle with XYRGB interleaving.
//And then we DON'T create a VBO for the data.

...
//Render (Assuming you've enabled all the relevant stuff)
fb.position(0); //Move the buffer's position to the vertex offset.
glVertexPointer(2, 20 /*(2+3)*4*/, fb); //Notice that we don't pass the "type" parameter in LWJGL becuase it will infer that these are floats since it is a FloatBuffer
fb.position(2); //Then we move the buffer's position to the colour offset.
glColorPointer(2,20 /*(2+3)*4*/, fb);
glDrawElements(...); //You know this bit



How work the buffer "fb" communication between the cpu and the gpu. You pass it to 2 calls (glVertexPointer and glColorPointer). It have 2 copy into the GPU or the OpenGL API retains that is the same buffer instance and communicate it only on time to the GPU at the end ?

I will try to adapt my code to VAs instead of VBO.

Sébastien.
29  Discussions / General Discussions / Re: New rules regarding Game Engine topics on: 2015-01-05 19:00:02
For continue on the kpars response.

A big difference in the picture between a "game post" and a "game engine post" is the lifetime of the project.

A game even if it will jave few updates and patch should change slowly over the time and not so actively while it is published. A static topic page that describe a such project fit well.
A game engine has a lifecycle more dynamic and must have more frequent maintainance since feedbacks and evolution are mades. You can't so efficiently maintain a static forum topic as well for such projects.

All "game engine" topic without any activity from a while could be moved on the "Archive" forum as Riven do.
In the counterparts, active ones (if it's still have one ?) should remains or moved somewhere else ?

So, all that for said, that a better approach for theses projects is to build an index-directory page that list all of theses projects and provide url to point on the official project's site like a "resources page" could do.
It could give a better visibility for such projects and a better resource finder for thoses need it.

it's my 2 cent's that worth what it worth since i push on this forum 0 game and 0 game engine Tongue

Sébastien.
30  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-04 21:27:12
I forgot GL11.glEnable( GL11.GL_TEXTURE_2D ); and searched for 2 hours why my texture was so white....

So, i continued today to review some personnal stuff using old fixed pipeline openGL with more modern version... i have to work on it for some times :-/
Pages: [1] 2 3 4
 
theagentd (10 views)
2015-03-27 23:08:20

wxwsk8er (52 views)
2015-03-20 15:39:46

Fairy Tailz (45 views)
2015-03-15 21:52:20

Olo (28 views)
2015-03-13 17:51:59

Olo (30 views)
2015-03-13 17:50:51

Olo (35 views)
2015-03-13 17:50:16

Olo (41 views)
2015-03-13 17:47:07

ClaasJG (40 views)
2015-03-10 11:36:42

ClaasJG (41 views)
2015-03-10 11:33:01

Pippogeek (47 views)
2015-03-05 14:36:23
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!