Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JOGL (GL3) not rendering a single thing  (Read 298 times)
0 Members and 1 Guest are viewing this topic.
Offline Pavelcz

Junior Newbie





« Posted 2013-07-13 17:19:06 »

I've spent whole day trying to make this render my triangle. Didn't happen. What am I doing wrong ? Syntax is OK. Screen gets filled with background color of Z-Buffer and no triangle appears. I've been used to old glBegin(), glEnd() style and I have almost no idea what am I doing now.

What I understand:

1. How buffers work,
2. How to reference buffers with IntBuffer
3. How to feed them with data using glBufferData.
4. Binding buffers.

What I do not understand:

1. What gl.glEnableVertexAttribArray(0); does ?
2. How do I change color of those vertices ? Are they drawn the same color as background, so they're invisible ?

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  
package opengltest;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;

import jogamp.graph.font.typecast.ot.table.Program;

public class SceneRenderer implements GLEventListener {

   private GLU glu = new GLU();

   private float triangle[] = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
         1.0f, 0.0f };
   private FloatBuffer verticesBuffer = FloatBuffer.wrap(triangle);
   private IntBuffer vbos = IntBuffer.allocate(1);

   @Override
   public void init(GLAutoDrawable drawable) {
      GL3 gl = drawable.getGL().getGL3();

      gl.glEnable(GL3.GL_DEPTH_TEST);
      gl.glDepthFunc(GL3.GL_LEQUAL);
      gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

      gl.glGenBuffers(1, vbos);


      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbos.get(0));

      gl.glBufferData(GL3.GL_ARRAY_BUFFER, 9 * 4, verticesBuffer,
            GL3.GL_STATIC_DRAW);

      gl.glFinish();
     
   }

   @Override
   public void dispose(GLAutoDrawable drawable) {

   }

   @Override
   public void display(GLAutoDrawable drawable) {

      GL3 gl = drawable.getGL().getGL3();
      gl.glClear(GL3.GL_DEPTH_BUFFER_BIT | GL3.GL_COLOR_BUFFER_BIT);

      gl.glEnableVertexAttribArray(0);
      gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbos.get(0));
      gl.glVertexAttribPointer(0, 3, GL3.GL_FLOAT, true, 0, 0);

      gl.glDrawArrays(GL3.GL_TRIANGLES, 0, 3);
      gl.glDisableVertexAttribArray(0);
      gl.glFinish();
      gl.glFlush();

   }

   @Override
   public void reshape(GLAutoDrawable drawable, int x, int y, int width,
         int height) {
      float aspect = (float) width / (float) height;
      glu.gluPerspective(85.0f, aspect, 0.1f, 100.0f);
      drawable.getGL().glViewport(0, 0, width, height);
     

   }

}
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (52 views)
2014-10-17 03:59:02

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

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

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

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

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

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

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

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

BurntPizza (86 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!