Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val vertices = Array(
- -0.5f, 0.5f, 0f, 1f, 0f, 0f,
- -0.5f, -0.5f, 0f, 0f, 1f, 0f,
- 0.5f, -0.5f, 0f, 0f, 0f, 1f,
- 0.5f, -0.5f, 0f, 0f, 0f, 1f,
- 0.5f, 0.5f, 0f, 0f, 1f, 0f,
- -0.5f, 0.5f, 0f, 1f, 0f, 0f
- )
- val buffer = BufferUtils.createFloatBuffer(vertices.length)
- buffer.put(vertices)
- buffer.flip()
- val vao = GL30.glGenVertexArrays()
- GL30.glBindVertexArray(vao)
- val vbo = GL15.glGenBuffers()
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo)
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW)
- //GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 3*4, 0)
- //GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0)
- // GL30.glBindVertexArray(0)
- val vertexShaderID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER)
- GL20.glShaderSource(vertexShaderID, sourceToString("src\\org\\xulufworld\\game\\vertex_shader.glsl"))
- GL20.glCompileShader(vertexShaderID)
- val fragmentShaderID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER)
- GL20.glShaderSource(fragmentShaderID, sourceToString("src\\org\\xulufworld\\game\\fragment_shader.glsl"))
- GL20.glCompileShader(fragmentShaderID)
- val programID = GL20.glCreateProgram()
- GL20.glAttachShader(programID, vertexShaderID)
- GL20.glAttachShader(programID, fragmentShaderID)
- GL30.glBindFragDataLocation(programID, 0, "fragColour")
- GL20.glLinkProgram(programID)
- val status = GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS);
- if (status != GL11.GL_TRUE) {
- throw new RuntimeException(GL20.glGetProgramInfoLog(programID));
- }
- GL20.glUseProgram(programID)
- val posAttrib = GL20.glGetAttribLocation(programID, "position")
- GL20.glEnableVertexAttribArray(posAttrib)
- GL20.glVertexAttribPointer(posAttrib, 3, GL11.GL_FLOAT, false, 6 * 4, 0)
- val colourAttrib = GL20.glGetAttribLocation(programID, "colour")
- GL20.glEnableVertexAttribArray(colourAttrib)
- GL20.glVertexAttribPointer(colourAttrib, 3, GL11.GL_FLOAT, false, 6 * 4, 3 * 4)
- val uniModel = GL20.glGetUniformLocation(programID, "model")
- val model = new Matrix4f()
- GL20.glUniformMatrix4fv(uniModel, false, model.getBuffer)
- val uniView = GL20.glGetUniformLocation(programID, "view")
- val view = new Matrix4f()
- GL20.glUniformMatrix4fv(uniView, false, view.getBuffer)
- val uniProjection = GL20.glGetUniformLocation(programID, "projection")
- val ratio = 640f/480f
- val projection = Matrix4f.orthographic(-ratio, ratio, -1f, 1f, -1f, 1f)
- GL20.glUniformMatrix4fv(uniProjection, false, projection.getBuffer)
- while(GLFW.glfwWindowShouldClose(window) != TRUE) {
- if(resized)
- {
- GL11.glViewport(0, 0, WIDTH, HEIGHT)
- resized = false
- println("Changed viewport")
- }
- GLFW.glfwPollEvents()
- GL11.glClearColor(0.0f, 0.5f, 0.5f, 1)
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)
- GL30.glBindVertexArray(vao)
- GL20.glEnableVertexAttribArray(0)
- GL20.glUseProgram(programID)
- GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6)
- GL20.glDisableVertexAttribArray(0)
- GL30.glBindVertexArray(0)
- GLFW.glfwSwapBuffers(window)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement