|
| 1 | +package com.nullprogram.noise; |
| 2 | + |
| 3 | +import com.nullprogram.lwjgl.GlFloatBuffer; |
| 4 | +import com.nullprogram.lwjgl.Lwjgl; |
| 5 | +import com.nullprogram.lwjgl.Program; |
| 6 | +import com.nullprogram.lwjgl.Shader; |
| 7 | +import com.nullprogram.lwjgl.VertexShader; |
| 8 | +import com.nullprogram.lwjgl.FragmentShader; |
| 9 | +import java.net.URL; |
| 10 | +import java.nio.FloatBuffer; |
| 11 | +import lombok.SneakyThrows; |
| 12 | +import org.lwjgl.BufferUtils; |
| 13 | +import org.lwjgl.opengl.Display; |
| 14 | +import org.lwjgl.opengl.DisplayMode; |
| 15 | +import org.lwjgl.opengl.GL11; |
| 16 | +import org.lwjgl.opengl.GL15; |
| 17 | + |
| 18 | +public class Launcher { |
| 19 | + |
| 20 | + @SneakyThrows |
| 21 | + public static void main(String[] args) { |
| 22 | + try { |
| 23 | + /* Data */ |
| 24 | + float[] positions = {1f, 1f, 1.5f, -0.5f}; |
| 25 | + FloatBuffer magnitudes |
| 26 | + = BufferUtils.createFloatBuffer(positions.length / 2); |
| 27 | + |
| 28 | + /* OpenGL initialization */ |
| 29 | + Lwjgl.setup(); |
| 30 | + Display.setDisplayMode(new DisplayMode(640, 480)); |
| 31 | + Display.create(); |
| 32 | + GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); |
| 33 | + |
| 34 | + /* Prepare buffers */ |
| 35 | + GlFloatBuffer glPositions = |
| 36 | + new GlFloatBuffer(positions, GL15.GL_ELEMENT_ARRAY_BUFFER); |
| 37 | + GlFloatBuffer glMagnitudes = |
| 38 | + new GlFloatBuffer(magnitudes, GL15.GL_ELEMENT_ARRAY_BUFFER, |
| 39 | + GL15.GL_DYNAMIC_DRAW); |
| 40 | + |
| 41 | + /* Prepare shaders */ |
| 42 | + URL magsrc = Launcher.class.getResource("magnitude.glsl"); |
| 43 | + URL basesrc = Launcher.class.getResource("base.glsl"); |
| 44 | + Shader magnitude = new VertexShader(magsrc); |
| 45 | + Shader base = new FragmentShader(basesrc); |
| 46 | + |
| 47 | + /* Create program */ |
| 48 | + Program program = new Program(); |
| 49 | + program.add(magnitude); |
| 50 | + program.add(base); |
| 51 | + program.link(); |
| 52 | + System.out.println("Link successful?"); |
| 53 | + |
| 54 | + /* Run it */ |
| 55 | + program.attrib(glPositions, "position", 2); |
| 56 | + program.attrib(glMagnitudes, "magnitude", 1); |
| 57 | + program.run(); |
| 58 | + System.out.println("Run successful?"); |
| 59 | + for (magnitudes.position(0); magnitudes.remaining() > 0;) { |
| 60 | + System.out.println(magnitudes.get()); |
| 61 | + } |
| 62 | + Thread.sleep(10000); |
| 63 | + } catch (Throwable t) { |
| 64 | + t.printStackTrace(); |
| 65 | + } |
| 66 | + System.exit(0); // Call this or LWJGL crashes |
| 67 | + } |
| 68 | +} |
0 commit comments