vrtc / jgltut (public) (License: GPLv3) (since 2020-10-12) (hash sha1)
Implement [gltut](https://paroj.github.io/gltut/) examples with [LWJGL3](https://www.lwjgl.org/).
List of commits:
Subject Hash Author Date (UTC)
feat: Render white triangle on navy background 771bf33b7a05d2f43c30b57c59f0e6e80a4d7070 Vladyslav Bondarenko 2020-10-07 22:57:25
feat!: Improve mock renderer fd45e6ac8a05602140bc30a9153f1e10c4815db1 Vladyslav Bondarenko 2020-10-07 16:29:47
Feat: add mock renderer a9270982088c680cd9b2462fd14ddbc048b314bd Vladyslav Bondarenko 2020-09-26 12:37:55
Initial commit 860d5debdc468cc159f2cbba261e5d8abb0abe38 Vladyslav Bondarenko 2020-09-21 12:45:18
Commit 771bf33b7a05d2f43c30b57c59f0e6e80a4d7070 - feat: Render white triangle on navy background
Author: Vladyslav Bondarenko
Author date (UTC): 2020-10-07 22:57
Committer name: Vladyslav Bondarenko
Committer date (UTC): 2020-10-07 22:57
Parent(s): fd45e6ac8a05602140bc30a9153f1e10c4815db1
Signer:
Signing key:
Signing status: N
Tree: da4868a327d9304aee5e58b7edc5e542d18bf25d
File Lines added Lines deleted
src/org.jgltut.tutaa/src/org/jgltut/tutaa/RendererAA.java 40 10
src/org.jgltut.tutaa/src/org/jgltut/tutaa/ShaderProgram.java 2 1
File src/org.jgltut.tutaa/src/org/jgltut/tutaa/RendererAA.java changed (mode: 100644) (index 00acb16..83071d7)
... ... import org.lwjgl.opengl.GL33C;
6 6 import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
7 7 import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
8 8 import static org.lwjgl.opengl.GL33C.GL_ARRAY_BUFFER; import static org.lwjgl.opengl.GL33C.GL_ARRAY_BUFFER;
9 import static org.lwjgl.opengl.GL33C.GL_ARRAY_BUFFER_BINDING;
9 10 import static org.lwjgl.opengl.GL33C.GL_COLOR_BUFFER_BIT; import static org.lwjgl.opengl.GL33C.GL_COLOR_BUFFER_BIT;
10 11 import static org.lwjgl.opengl.GL33C.GL_FALSE; import static org.lwjgl.opengl.GL33C.GL_FALSE;
11 12 import static org.lwjgl.opengl.GL33C.GL_FLOAT; import static org.lwjgl.opengl.GL33C.GL_FLOAT;
13 import static org.lwjgl.opengl.GL33C.GL_NO_ERROR;
12 14 import static org.lwjgl.opengl.GL33C.GL_STATIC_DRAW; import static org.lwjgl.opengl.GL33C.GL_STATIC_DRAW;
13 15 import static org.lwjgl.opengl.GL33C.GL_TRIANGLES; import static org.lwjgl.opengl.GL33C.GL_TRIANGLES;
14 16 import static org.lwjgl.opengl.GL33C.glBindBuffer; import static org.lwjgl.opengl.GL33C.glBindBuffer;
17 import static org.lwjgl.opengl.GL33C.glBindVertexArray;
15 18 import static org.lwjgl.opengl.GL33C.glBufferData; import static org.lwjgl.opengl.GL33C.glBufferData;
16 19 import static org.lwjgl.opengl.GL33C.glClear; import static org.lwjgl.opengl.GL33C.glClear;
17 20 import static org.lwjgl.opengl.GL33C.glClearColor; import static org.lwjgl.opengl.GL33C.glClearColor;
 
... ... import static org.lwjgl.opengl.GL33C.glDisableVertexAttribArray;
21 24 import static org.lwjgl.opengl.GL33C.glDrawArrays; import static org.lwjgl.opengl.GL33C.glDrawArrays;
22 25 import static org.lwjgl.opengl.GL33C.glEnableVertexAttribArray; import static org.lwjgl.opengl.GL33C.glEnableVertexAttribArray;
23 26 import static org.lwjgl.opengl.GL33C.glGenBuffers; import static org.lwjgl.opengl.GL33C.glGenBuffers;
27 import static org.lwjgl.opengl.GL33C.glGenVertexArrays;
28 import static org.lwjgl.opengl.GL33C.glGetError;
29 import static org.lwjgl.opengl.GL33C.glGetInteger;
24 30 import static org.lwjgl.opengl.GL33C.glUseProgram; import static org.lwjgl.opengl.GL33C.glUseProgram;
25 31 import static org.lwjgl.opengl.GL33C.glVertexAttribPointer; import static org.lwjgl.opengl.GL33C.glVertexAttribPointer;
26 import static org.lwjgl.opengl.GL33C.glGetError;
27 import static org.lwjgl.opengl.GL33C.GL_NO_ERROR;
28 32
29 33 final class RendererAA extends Renderer final class RendererAA extends Renderer
30 34 { {
 
... ... final class RendererAA extends Renderer
47 51 try { try {
48 52 /* Close stack in RendererAA#close */ /* Close stack in RendererAA#close */
49 53 final var stack = MemoryStack.stackPush(); final var stack = MemoryStack.stackPush();
54 validate();
50 55 final int bufferHandle = glGenBuffers(); final int bufferHandle = glGenBuffers();
51 56 validate(); validate();
57 final int vao = glGenVertexArrays();
58 validate();
59 glBindVertexArray(vao);
60 validate();
52 61 glBindBuffer(GL_ARRAY_BUFFER, bufferHandle); glBindBuffer(GL_ARRAY_BUFFER, bufferHandle);
53 62 validate(); validate();
54 63 final float[] vertexData = new float[] { final float[] vertexData = new float[] {
 
... ... final class RendererAA extends Renderer
58 67 }; };
59 68 final FloatBuffer floatBuffer = stack.callocFloat(vertexData.length); final FloatBuffer floatBuffer = stack.callocFloat(vertexData.length);
60 69 floatBuffer.put(vertexData, 0, vertexData.length); floatBuffer.put(vertexData, 0, vertexData.length);
70 /* Invokation of FloatBuffer#flip is required. */
61 71 floatBuffer.flip(); floatBuffer.flip();
62 72 glBufferData(GL_ARRAY_BUFFER, floatBuffer, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, floatBuffer, GL_STATIC_DRAW);
63 73 validate(); validate();
64 74 glBindBuffer(GL_ARRAY_BUFFER, GL_FALSE); glBindBuffer(GL_ARRAY_BUFFER, GL_FALSE);
65 75 validate(); validate();
76 glBindVertexArray(GL_FALSE);
77
66 78
67 /* FIXME Shader program handle */
68 79 final var spb = new ShaderProgramBuilder(); final var spb = new ShaderProgramBuilder();
69 80 spb.setShaderFragSrc(SHADER_FRAG); spb.setShaderFragSrc(SHADER_FRAG);
70 81 spb.setShaderVertSrc(SHADER_VERT); spb.setShaderVertSrc(SHADER_VERT);
71 82 final var sp = spb.get(); final var sp = spb.get();
72 83 final var renderer = new RendererAA( final var renderer = new RendererAA(
73 floatBuffer, stack, bufferHandle, sp);
84 floatBuffer, stack, bufferHandle, sp, vao);
74 85 return renderer; return renderer;
75 86 } catch (Exception e) { } catch (Exception e) {
76 87 final String msg = "could not init renderer"; final String msg = "could not init renderer";
 
... ... final class RendererAA extends Renderer
99 110 private final MemoryStack memoryStack; private final MemoryStack memoryStack;
100 111 private final ShaderProgram program; private final ShaderProgram program;
101 112 private final int bufferHandle; private final int bufferHandle;
113 private final int vao;
102 114
103 115 RendererAA(final FloatBuffer floatBuffer, final MemoryStack memoryStack, RendererAA(final FloatBuffer floatBuffer, final MemoryStack memoryStack,
104 final int bufferHandle, final ShaderProgram program)
116 final int bufferHandle, final ShaderProgram program, final int vao)
105 117 { {
106 118 assert (memoryStack != null); assert (memoryStack != null);
119 assert (bufferHandle != GL_FALSE);
107 120 this.floatBuffer = floatBuffer; this.floatBuffer = floatBuffer;
108 121 this.memoryStack = memoryStack; this.memoryStack = memoryStack;
109 122 this.bufferHandle = bufferHandle; this.bufferHandle = bufferHandle;
110 123 this.program = program; this.program = program;
124 assert (vao != GL_FALSE);
125 this.vao = vao;
111 126 } }
112 127
113 128 @Override public final void close() @Override public final void close()
 
... ... final class RendererAA extends Renderer
134 149 program.apply(); program.apply();
135 150 validate(); validate();
136 151
152 glBindVertexArray(vao);
153 int index = program.getAttributeLocation("position");
154 glEnableVertexAttribArray(index);
155 validate();
137 156 glBindBuffer(GL_ARRAY_BUFFER, bufferHandle); glBindBuffer(GL_ARRAY_BUFFER, bufferHandle);
138 157 validate(); validate();
139 158 glBufferData(GL_ARRAY_BUFFER, floatBuffer, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, floatBuffer, GL_STATIC_DRAW);
140 159 validate(); validate();
141 glEnableVertexAttribArray(0);
142 validate();
143 glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
160
161 int size = 4;
162 int dataType = GL_FLOAT;
163 boolean isNormalised = false;
164 int stride = 0;
165 long offset = 0;
166 int vbo = glGetInteger(GL_ARRAY_BUFFER_BINDING);
167 System.out.println("vbo" + String.valueOf(vbo));
168 if (GL_FALSE == vbo && bufferHandle == vbo) {
169 throw new IllegalStateException("no buffer bound");
170 }
171 glVertexAttribPointer(index, size, dataType, isNormalised, stride, offset);
144 172 validate(); validate();
145 173
146 glDrawArrays(GL_TRIANGLES, 0, 3);
174 int quantity = 3;
175 glDrawArrays(GL_TRIANGLES, 0, quantity);
147 176 validate(); validate();
148 177
149 glDisableVertexAttribArray(0);
178 glDisableVertexAttribArray(index);
150 179 validate(); validate();
180 glBindVertexArray(GL_FALSE);
151 181 program.unapply(); program.unapply();
152 182 } }
153 183 } }
File src/org.jgltut.tutaa/src/org/jgltut/tutaa/ShaderProgram.java changed (mode: 100644) (index 10bb03e..65f09f3)
... ... final class ShaderProgram implements AutoCloseable
58 58 glUseProgram(programHandle); glUseProgram(programHandle);
59 59 } }
60 60
61 protected final int getAttributeLocation(final String name)
61 /* FIXME getAttributeLocation must be protected. */
62 final int getAttributeLocation(final String name)
62 63 { {
63 64 if (isClosed) { if (isClosed) {
64 65 throw new IllegalStateException("already closed"); throw new IllegalStateException("already closed");
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/jgltut

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/jgltut

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/jgltut

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main