Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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: Determine what graphics card is being used on: 2007-11-10 23:07:28
Thank you that's just what I was looking for
2  Java Game APIs & Engines / JOGL Development / Determine what graphics card is being used on: 2007-11-10 18:25:28
Hi, Just a quick question.
I was wondering if it was possible to get the graphics card make and model using JOGL or just JAVA?

Thanks
3  Java Game APIs & Engines / JOGL Development / Print variables from shader on: 2007-11-06 22:59:04
Hi,
I was just wandering if it is possible to display a variable defined in a vertex or fragment shader and display it in the console like you would do in Java using System.out.
Just that I am finding it hard to debug shaders when I currently cant see what some of the variables are set to.

Thanks
4  Java Game APIs & Engines / JOGL Development / Re: Blank screen when uisng shaders on: 2007-10-21 18:06:08
Quote
My I ask why you're enabling GL_TEXTURE_GEN_S and G_TEXTURE_1D if you never bind any textures?
It appears I accidentally left the code there after I was learning how to get a teapot on the screen:
How to draw a texture mapped teapot with automatically generated texture coordinates
But it appears that all I forgot to do was to actually set up the uniform values.
1  
2  
3  
4  
5  
6  
// Set up initial uniform values
       gl.glUniform3f(gl.glGetUniformLocation(shaderprogram, "BrickColor"), 1.0f, 0.3f, 0.2f);
        gl.glUniform3f(gl.glGetUniformLocation(shaderprogram, "MortarColor"), 0.85f, 0.86f, 0.84f);
        gl.glUniform2f(gl.glGetUniformLocation(shaderprogram, "BrickSize"), 0.30f, 0.15f);
        gl.glUniform2f(gl.glGetUniformLocation(shaderprogram, "BrickPct"), 0.90f, 0.85f);
        gl.glUniform3f(gl.glGetUniformLocation(shaderprogram, "LightPosition"), 5.0f, 0.0f, 0.0f);

Otherwise it seems to working fine now and I have since removed those redundant enables and a bunch of other code.

Thanks for your help; I really do appreciate it especially through these really noobish times.
5  Java Game APIs & Engines / JOGL Development / Blank screen when uisng shaders on: 2007-10-20 14:59:26
I am currently trying to get a shder to create a brick like texture on a teapot.
I can render a teapot fine using the GLUnit tools but as soon as I add the shaders the teapot just disapears.
The frag and vertex shaders were a copy paste from the orange book so they should be fine and I dont get any errors in the shader log, so at the moment I hit a wall and not sure what I have done wrong.

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  
public class SimpleJOGL implements GLEventListener {

    private int shaderprogram = 0;
    private GLUT glut;
    private String vertsrc = "VertexShader.vert";
    private String fragsrc = "FragmentShader.frag";
   

    public static void main(String[] args) {
        Frame frame = new Frame("Simple JOGL Application");
        GLCanvas canvas = new GLCanvas();
       
        [....]
               
        // Center frame
       frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }

    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
        drawable.setGL(new DebugGL(drawable.getGL()));
        GL gl = drawable.getGL();
        glut = new GLUT();
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
       gl.setSwapInterval(1);

        // Setup the drawing area and shading mode
       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        //gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
       
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LESS);
        gl.glEnable(GL.GL_TEXTURE_GEN_S);
        gl.glEnable(GL.GL_TEXTURE_1D);
        gl.glEnable(GL.GL_CULL_FACE);
        gl.glEnable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_LIGHT0);
        gl.glEnable(GL.GL_AUTO_NORMAL);
        gl.glEnable(GL.GL_NORMALIZE);
        gl.glFrontFace(GL.GL_CW);
        gl.glCullFace(GL.GL_BACK);
        gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 64.0f);
       
        setupShaders(gl);// comment this out and u can see the teapot
   }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        [.. usual ..]
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();

        // Clear the drawing area
       //gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
       // Reset the current matrix to the "identity"
       //gl.glLoadIdentity();

        // Move the "drawing cursor" around
       gl.glTranslatef(-1.5f, 0.0f, -6.0f);
   
        //gl.glPushMatrix();
       glut.glutSolidTeapot(1.0f);

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

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

    private void setupShaders(GL gl) {
        int v = gl.glCreateShader(GL.GL_VERTEX_SHADER);
        int f = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);

        if (shaderprogram == 0) {
            System.out.println("initializing shaders");
            try {
                String[] vertexsource = {stringifyfile(vertsrc)};
                String[] fragmentsource = {stringifyfile(fragsrc)};
               
                gl.glShaderSource(v, 1, vertexsource, (int[]) null, 0);
                gl.glCompileShader(v);
                checkLogInfo(gl, v);

                gl.glShaderSource(f, 1, fragmentsource, (int[]) null, 0);
                gl.glCompileShader(f);
                checkLogInfo(gl, f);

                shaderprogram = gl.glCreateProgram();
                gl.glAttachShader(shaderprogram, v);
                gl.glAttachShader(shaderprogram, f);
               
                gl.glLinkProgram(shaderprogram);
                gl.glValidateProgram(shaderprogram);
                checkLogInfo(gl, shaderprogram);
            } catch (FileNotFoundException e) {
                System.err.println("Shader source file not found." + e);
            } catch (IOException e) {
                System.err.println("Could not read shader file.");
            }
        }
        gl.glUseProgram(shaderprogram);
        checkLogInfo(gl, shaderprogram);
        checkLogInfo(gl, v);
        checkLogInfo(gl, f);
    }

    private String stringifyfile(String filename) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(filename));
        String res = "";
        String line;
        while ((line = br.readLine()) != null) {
            res += line + "\n";
        }
        return res;
    }

    private void checkLogInfo(GL gl, int obj) {
        IntBuffer iVal = BufferUtil.newIntBuffer(1);
        gl.glGetObjectParameterivARB(obj, GL.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);

        int length = iVal.get();

        if (length <= 1) {
            return;
        }

        ByteBuffer infoLog = BufferUtil.newByteBuffer(length);

        iVal.flip();
        gl.glGetInfoLogARB(obj, length, iVal, infoLog);

        byte[] infoBytes = new byte[length];
        infoLog.get(infoBytes);
        System.out.println("GLSL Validation >> " + new String(infoBytes));
    }
}
6  Java Game APIs & Engines / JOGL Development / Re: simple procedural texture on: 2007-10-12 13:13:27
Hi Jark,
Thanks for the tip and book suggestion.

But back to my problem, and after searching around I came across a MSDN page that gave more information about the glBindTextute method:
http://msdn2.microsoft.com/en-us/library/ms537140.aspx
In particular this is what it said:
Quote
Data is read from pixels as a sequence of signed or unsigned bytes, shorts or longs, or single-precision floating-point values, depending on type.
The thing that struck me was no mention of integers so I changed the type over to floats and it started to work again.

Maybe leaving a more open question if people are willing to help me gain a better understanding. At the moment I am happy to continue using this method in generating any other procedural texture work that I will do but due to the lack of knowledge I am currently unaware of any other more efficient ways in doing this. Will there be any performance issues that I might not be aware at in this moment in time?

Thanks
7  Java Game APIs & Engines / JOGL Development / Re: simple procedural texture on: 2007-10-12 11:55:24
Sorry for double post but I have some developments. I was going to try get buffered image and graphics2D involved until I found this tutorial which seems to be the thing I was looking for. It doesn't use glDrawPixels instead it used glBindTexture.
http://www.java-tips.org/other-api-tips/jogl/demonstration-of-using-glbindtexture-by-creating-and-managing-two-tex.html

Until I manage to get a book on JOGL or OpenGL I am still in the learning stages, but at the moment I am wondering that instead of using bytes for the RGBA values I could use Integers instead. I am aware there might be some efficiency problems there but at the moment I find it easier working with simple ints.

I tried converting that example to use ints but so far it hasn't worked and I am currently left with two white textures.

Here is what I have tried to do.
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  
import java.awt.event.*;
import javax.swing.JFrame;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;
import java.nio.IntBuffer;

/**
 * This program demonstrates using glBindTexture() by creating and managing two
 * textures.
 *
 * @author Kiet Le (Java port)
 */

public class texbind extends JFrame implements GLEventListener, KeyListener {

    private GLCapabilities caps;
    private GLCanvas canvas;
    private GLU glu;
    private GLUT glut;
    //
   private static final int rgba = 4;
    private static final int checkImageWidth = 64;
    private static final int checkImageHeight = 64;
    // private byte checkImage[][][];
   // private byte otherImage[][][];
   private IntBuffer checkImageBuf = BufferUtil.newIntBuffer(checkImageWidth * checkImageHeight * rgba);
    private IntBuffer otherImageBuf = BufferUtil.newIntBuffer(checkImageWidth * checkImageHeight * rgba);
    private int[] texName = new int[2];

    public texbind() {
        super("texbind");

        caps = new GLCapabilities();
        canvas = new GLCanvas(caps);
        canvas.addGLEventListener(this);
        canvas.addKeyListener(this);

        getContentPane().add(canvas);
    }

    public void run() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250, 250);
        setLocationRelativeTo(null);
        setVisible(true);
        canvas.requestFocusInWindow();
    }

    public static void main(String[] args) {
        new texbind().run();
    }

    public void init(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        glu = new GLU();

        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL.GL_FLAT);
        gl.glEnable(GL.GL_DEPTH_TEST);

        makeCheckImages();

        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

        gl.glGenTextures(2, texName, 0);
        gl.glBindTexture(GL.GL_TEXTURE_2D, texName[0]);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, checkImageWidth, checkImageHeight, 0, GL.GL_RGBA, GL.GL_INT, checkImageBuf);

        gl.glBindTexture(GL.GL_TEXTURE_2D, texName[1]);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
        gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL);
        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, checkImageWidth, checkImageHeight, 0, GL.GL_RGBA, GL.GL_INT, otherImageBuf);
        gl.glEnable(GL.GL_TEXTURE_2D);
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

        //First texture
       gl.glBindTexture(GL.GL_TEXTURE_2D, texName[0]);
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3d(-2.0, -1.0, 0.0);
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3d(-2.0, 1.0, 0.0);
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3d(0.0, 1.0, 0.0);
        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3d(0.0, -1.0, 0.0);
        gl.glEnd();

        //Second texture
       gl.glBindTexture(GL.GL_TEXTURE_2D, texName[1]);
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3d(1.0, -1.0, 0.0);
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3d(1.0, 1.0, 0.0);
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3d(2.41421, 1.0, -1.41421);
        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3d(2.41421, -1.0, -1.41421);
        gl.glEnd();
        gl.glFlush();
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
        GL gl = drawable.getGL();

        gl.glViewport(0, 0, w, h);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(60.0, (float) w / (float) h, 1.0, 30.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glTranslated(0.0, 0.0, -3.6);
    }

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

    private void makeCheckImages() {
        //byte c = 0x00;
       for (int i = 0; i < checkImageWidth; i++) {
            for (int j = 0; j < checkImageHeight; j++) {
                checkImageBuf.put((int) (Math.random()*256)); // R
               checkImageBuf.put((int) (Math.random()*256)); // G
               checkImageBuf.put((int) (Math.random()*256)); // B
               checkImageBuf.put((int) (Math.random()*256)); // A
               
                otherImageBuf.put((int) (Math.random()*256)); // R
               otherImageBuf.put((int) (Math.random()*256)); // G
               otherImageBuf.put((int) (Math.random()*256)); // B
               otherImageBuf.put((int) (Math.random()*256)); // A

            }
        }
        checkImageBuf.rewind();
        otherImageBuf.rewind();
    }

    public void keyTyped(KeyEvent key) {
    }

    public void keyPressed(KeyEvent key) {
        switch (key.getKeyCode()) {
            case KeyEvent.VK_ESCAPE:
                System.exit(0);
            default:
                break;
        }
    }

    public void keyReleased(KeyEvent key) {
    }
}
8  Java Game APIs & Engines / JOGL Development / simple procedural texture on: 2007-10-11 06:16:54
I am just trying my hands at a procedural type of texture but so far any attempts have failed yet I can draw squares and triangles no problem.
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  
    public void display(GLAutoDrawable drawable) {

        GL gl = drawable.getGL();

        // Clear the drawing area
       gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        // Reset the current matrix to the "identity"
       gl.glLoadIdentity();

        // Move the "drawing cursor" around
       gl.glTranslatef(-1.5f, 1.0f, -6.0f);

        // Drawing Using Triangles
       float[] brickColour = { 0.5f, 0.15f, 0.14f};
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3fv(brickColour,0);    // Set the current drawing color to red
       gl.glVertex3f(0.0f, 1.0f, 0.0f);   // Top
       gl.glColor3f(0.0f, 1.0f, 0.0f);    // Set the current drawing color to green
       gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
       gl.glColor3f(0.0f, 0.0f, 1.0f);    // Set the current drawing color to blue
       gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
       // Finished Drawing The Triangle
       gl.glEnd();

        // Move the "drawing cursor" to another position
       gl.glTranslatef(3.0f, 0.0f, 0.0f);
       
        // Draw a simple texture
       drawImage(gl);

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

    private void drawImage(GL gl) {
       
        // draw a rectangle which should be seen if this works
       gl.glColor3f(1.0f, 0.5f, 0.0f);
        gl.glRecti(0, 1, 1, 0);
        gl.glColor3f(0.0f, 0.0f, 0.0f);


        int width = 50;
        int height = 100;
        IntBuffer buffer = IntBuffer.allocate(3 * width * height);

        for (int h = 0; h < height; h++) {
            for (int w = 0; w < width; w++) {
                buffer.put(0); // R
               buffer.put(0); // G
               buffer.put(255); // B
           }
        }
        buffer.rewind();

        gl.glDrawBuffer(GL.GL_FRONT);
        gl.glRasterPos2i(0, 0);
        gl.glDrawPixels(width, height, GL.GL_RGB, GL.GL_INT, buffer);
       
        //gl.glFinish();

    }

Any idea where I am going wrong.
Thanks

Edit: Woops left in two unrealted functions, now been removed
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (60 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!