// Create a new vertex shader object int vertexShader = glCreateShader(GL_VERTEX_SHADER); // Attach the shader source code to the shader object string vertexShaderCode = "#version 330 core\n" + "layout (location = 0) in vec3 aPos;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" + "}"; glShaderSource(vertexShader, 1, new [] {vertexShaderCode}, null); // Compile the shader glCompileShader(vertexShader);
// Create a new fragment shader object int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); // Attach the shader source code to the shader object string fragmentShaderCode = "#version 330 core\n" + "out vec4 FragColor;\n" + "void main()\n" + "{\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + "}"; glShaderSource(fragmentShader, 1, new [] {fragmentShaderCode}, null); // Compile the shader glCompileShader(fragmentShader);This code creates a new fragment shader object, attaches the shader source code to it, and compiles it. Package library: OpenGL package.