Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 IZOLINES of temperature on: 2012-10-29 22:34:43
In the code is not as easy as in theory ;( I can't imagine how ... I need to sleep mayby tomorrow will be better.
2  Java Game APIs & Engines / JOGL Development / Re: Drawing IZOLINES of temperature on: 2012-10-29 21:45:36
Hmm i agree with you but how i can write somthing like that?

1  
2  
3  
4  
5  
6  
7  
8  
9  
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0] ).m_position.x,
                Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0] ).m_position.y);
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1] ).m_position.x,
                Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1] ).m_position.y);
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2] ).m_position.x,
               Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2] ).m_position.y);


First i put in shader a temperature and it calculate color. Where put second step? On this same vertices? I do not imagine that Sad
3  Java Game APIs & Engines / JOGL Development / Re: Drawing IZOLINES of temperature on: 2012-10-29 21:39:17
I tried but i havent neighbour pixels.

When I calculate it without neigbours but by function calculating my color. I tried obtain izo by 10 degrees it doted or all black, or line is to width.
4  Java Game APIs & Engines / JOGL Development / Drawing IZOLINES of temperature on: 2012-10-29 21:19:22
Hello everybody!

I stuck with my problem.

PROBLEM:
- very slow algorithm
- no idea how to improve it
- any existing algorithm in Java/ JOGL?

HOW I DO:
I use shader to calculate izolines of temperature and i obtain for example this:

http://imageshack.us/photo/my-images/26/izoline.png

now i must to draw in JOGL black lines on color edges. I read all pixels from GL buffer.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public BufferedImage toImage(GL gl, int w, int h) 
    {
        gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK

        ByteBuffer glBB = ByteBuffer.allocate(3 * w * h);
        gl.glReadPixels(0, 0, w, h, GL.GL_BGR, GL.GL_BYTE, glBB);

        BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
       
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                int b = 2 * glBB.get();
                int g = 2 * glBB.get();
                int r = 2 * glBB.get();
                bd[(h - y - 1) * w + x] = (r << 16) | (g << 8) | b | 0xFF000000;
            }
        }

        return bi;
    }


But trying find edge pixel by pixel is soooo long in time. Like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
BufferedImage bi = toImage(m_gl, Resources.dCanvasWidth, Resources.dCanvasHeight);
            for(int i=0; i< 20; ++i)
            {
                System.out.println( i );
                for(int i1=0; i1< bi.getData().getHeight()-1; ++i1)
                {
                    int[] buff1;
                    int[] buff2;
                   
                    buff1 = bi.getData().getPixel(i, i1, (int[]) null );
                    buff2 = bi.getData().getPixel(i, i1, (int[]) null );
                   
                    if( !Arrays.equals(buff1, buff2) )
                    {
                        m_gl.glDrawPixels(i, i1,GL.GL_RGB, GL.GL_INT, blackPixel);
                        m_gl.glFlush();
                       
                    }
                   
                }


Can somebody help me solve this problem?
5  Java Game APIs & Engines / JOGL Development / [solved]GLSL problem on: 2012-10-22 10:14:44
Hello Wink

I have some problem. I tried use GLSL into JOGL. I draw simple traingle which red green blue vertices. I obtain all blue triangle. What i do wrong?

OK I SOLVED IT:
gl.glShadeModel(GL.GL_SHADER_TYPE);
against:
gl.glShadeModel(GL.GL_FLAT);

Here is my code:

frag.txt ---
1  
2  
3  
4  
void main()
{
    gl_FragColor = gl_Color;
}


vert.txt ---
1  
2  
3  
4  
5  
void main()
{
    gl_FrontColor = gl_Color;
    gl_Position = ftransform();
}


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  
181  
182  
.java ---
package org.yourorghere;

import com.sun.opengl.util.Animator;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

public class SimpleShaderExample extends GLCanvas implements GLEventListener {

   private boolean updateUniformVars = true;
   private int vertexShaderProgram;
   private int fragmentShaderProgram;
   private int shaderprogram;
   private final Animator animator = new Animator(this);
   private float x = -2;
   private float y = -2;
   private float height = 4;
   private float width = 4;
   private int iterations = 255;

   public SimpleShaderExample() {
      addGLEventListener(this);
        animator.start();
    }

    public void init(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
     
        // generate a VBO pointer / handle
     
     
        // Enable VSync
       gl.setSwapInterval(1);
      gl.glShadeModel(GL.GL_FLAT);
      try {
         attachShaders(gl);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   private String[] loadShaderSrc(String name){
      StringBuilder sb = new StringBuilder();
      try{
         InputStream is = getClass().getResourceAsStream(name);
         BufferedReader br = new BufferedReader(new InputStreamReader(is));
         String line;
         while ((line = br.readLine())!=null){
            sb.append(line);
            sb.append('\n');
         }
         is.close();
      }
      catch (Exception e){
         e.printStackTrace();
      }
      System.out.println("Shader is "+sb.toString());
      return new String[]{sb.toString()};
   }

   private void attachShaders(GL gl) throws Exception {
      vertexShaderProgram = gl.glCreateShader(GL.GL_VERTEX_SHADER);
      fragmentShaderProgram = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);

      String[] vsrc = loadShaderSrc( "vert.txt" );
      gl.glShaderSource(vertexShaderProgram, 1, vsrc, null, 0);
      gl.glCompileShader(vertexShaderProgram);

      String[] fsrc = loadShaderSrc( "frag.txt");
      gl.glShaderSource(fragmentShaderProgram, 1, fsrc, null, 0);
      gl.glCompileShader(fragmentShaderProgram);

      shaderprogram = gl.glCreateProgram();
      gl.glAttachShader(shaderprogram, vertexShaderProgram);
      gl.glAttachShader(shaderprogram, fragmentShaderProgram);
      gl.glLinkProgram(shaderprogram);
      gl.glValidateProgram(shaderprogram);
      IntBuffer intBuffer = IntBuffer.allocate(1);
      gl.glGetProgramiv(shaderprogram, GL.GL_LINK_STATUS,intBuffer);
      if (intBuffer.get(0)!=1){
         gl.glGetProgramiv(shaderprogram, GL.GL_INFO_LOG_LENGTH,intBuffer);
         int size = intBuffer.get(0);
         System.err.println("Program link error: ");
         if (size>0){
            ByteBuffer byteBuffer = ByteBuffer.allocate(size);
            gl.glGetProgramInfoLog(shaderprogram, size, intBuffer, byteBuffer);
            for (byte b:byteBuffer.array()){
               System.err.print((char)b);
            }
         } else {
            System.out.println("Unknown");
         }
         System.exit(1);
      }
      gl.glLinkProgram(shaderprogram);
      gl.glUseProgram(shaderprogram);
   }

   public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        GLU glu = new GLU();

        if (height <= 0) { // avoid a divide by zero error!

            height = 1;
        }
        final float h = (float) width / (float) height;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(0, 1, 0, 1);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
    }



    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
       
      //if (updateUniformVars){
     //    updateUniformVars(gl);m
     //}

        // Reset the current matrix to the "identity"
       gl.glLoadIdentity();

       
        // Draw A Quad
       //int temp = gl.glGetUniformLocation(shaderprogram, "t");
       //int min = gl.glGetUniformLocation(shaderprogram, "min");
       //int max = gl.glGetUniformLocation(shaderprogram, "max");
          //gl.glUniform1f(temp, 500.0f);
          //gl.glUniform1f(min, 400.0f);
          //gl.glUniform1f(max, 900.0f);
      gl.glBegin(GL.GL_TRIANGLES);
       
       
            gl.glColor3f(1.0f,0.0f,0.0f);
            gl.glVertex3f(0.5f, 1.0f, 0.0f);
           
            gl.glColor3f(0.0f,1.0f,0.0f);
            gl.glVertex3f(0.0f, -1.0f, 0.0f);
           
            gl.glColor3f(0.0f,0.0f,1.0f);
            gl.glVertex3f(1.0f, -1.0f, 0.0f);
 
      // Done Drawing The Quad
     gl.glEnd();

        // Flush all drawing operations to the graphics card
       //gl.glFlush();
   }


   public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            JFrame jf = new JFrame();
            jf.setSize(800,600);
            jf.getContentPane().setLayout(new BorderLayout());
            jf.getContentPane().add(new SimpleShaderExample(), BorderLayout.CENTER);
            jf.setVisible(true);
            jf.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         }
      });

   }
}
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.

Riven (7 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

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

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

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

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

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

Zero Volt (51 views)
2014-07-17 23:47:54
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!