Java Code Examples for org.lwjgl.system.Platform#MACOSX
The following examples show how to use
org.lwjgl.system.Platform#MACOSX .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModernOpenGLDraw.java From recast4j with zlib License | 4 votes |
@Override public void init() { String NK_SHADER_VERSION = Platform.get() == Platform.MACOSX ? "#version 150\n" : "#version 300 es\n"; String vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n"// + "uniform mat4 ViewMtx;\n"// + "in vec3 Position;\n"// + "in vec2 TexCoord;\n"// + "in vec4 Color;\n"// + "out vec2 Frag_UV;\n"// + "out vec4 Frag_Color;\n"// + "out float Frag_Depth;\n"// + "void main() {\n"// + " Frag_UV = TexCoord;\n"// + " Frag_Color = Color;\n"// + " vec4 VSPosition = ViewMtx * vec4(Position, 1);\n"// + " Frag_Depth = -VSPosition.z;\n"// + " gl_Position = ProjMtx * VSPosition;\n"// + "}\n"; String fragment_shader = NK_SHADER_VERSION + "precision mediump float;\n"// + "uniform sampler2D Texture;\n"// + "uniform float UseTexture;\n"// + "uniform float EnableFog;\n"// + "uniform float FogStart;\n"// + "uniform float FogEnd;\n"// + "const vec4 FogColor = vec4(0.32f, 0.31f, 0.30f, 1.0f);\n"// + "in vec2 Frag_UV;\n"// + "in vec4 Frag_Color;\n"// + "in float Frag_Depth;\n"// + "out vec4 Out_Color;\n"// + "void main(){\n"// + " Out_Color = mix(FogColor, Frag_Color * mix(vec4(1), texture(Texture, Frag_UV.st), UseTexture), 1.0 - EnableFog * clamp( (Frag_Depth - FogStart) / (FogEnd - FogStart), 0.0, 1.0) );\n"// + "}\n"; program = glCreateProgram(); int vert_shdr = glCreateShader(GL_VERTEX_SHADER); int frag_shdr = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(vert_shdr, vertex_shader); glShaderSource(frag_shdr, fragment_shader); glCompileShader(vert_shdr); glCompileShader(frag_shdr); if (glGetShaderi(vert_shdr, GL_COMPILE_STATUS) != GL_TRUE) { throw new IllegalStateException(); } if (glGetShaderi(frag_shdr, GL_COMPILE_STATUS) != GL_TRUE) { throw new IllegalStateException(); } glAttachShader(program, vert_shdr); glAttachShader(program, frag_shdr); glLinkProgram(program); if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) { throw new IllegalStateException(); } uniformTexture = glGetUniformLocation(program, "Texture"); uniformUseTexture = glGetUniformLocation(program, "UseTexture"); uniformFog = glGetUniformLocation(program, "EnableFog"); uniformFogStart = glGetUniformLocation(program, "FogStart"); uniformFogEnd = glGetUniformLocation(program, "FogEnd"); uniformProjectionMatrix = glGetUniformLocation(program, "ProjMtx"); uniformViewMatrix = glGetUniformLocation(program, "ViewMtx"); int attrib_pos = glGetAttribLocation(program, "Position"); int attrib_uv = glGetAttribLocation(program, "TexCoord"); int attrib_col = glGetAttribLocation(program, "Color"); // buffer setup vbo = glGenBuffers(); ebo = glGenBuffers(); vao = glGenVertexArrays(); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glEnableVertexAttribArray(attrib_pos); glEnableVertexAttribArray(attrib_uv); glEnableVertexAttribArray(attrib_col); glVertexAttribPointer(attrib_pos, 3, GL_FLOAT, false, 24, 0); glVertexAttribPointer(attrib_uv, 2, GL_FLOAT, false, 24, 12); glVertexAttribPointer(attrib_col, 4, GL_UNSIGNED_BYTE, true, 24, 20); glBindTexture(GL_TEXTURE_2D, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindVertexArray(0); }
Example 2
Source File: NuklearGL.java From recast4j with zlib License | 4 votes |
public NuklearGL(NuklearUI context) { this.context = context; nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE); vertexLayout = NkDrawVertexLayoutElement.create(4)// .position(0).attribute(NK_VERTEX_POSITION).format(NK_FORMAT_FLOAT).offset(0)// .position(1).attribute(NK_VERTEX_TEXCOORD).format(NK_FORMAT_FLOAT).offset(8)// .position(2).attribute(NK_VERTEX_COLOR).format(NK_FORMAT_R8G8B8A8).offset(16)// .position(3).attribute(NK_VERTEX_ATTRIBUTE_COUNT).format(NK_FORMAT_COUNT).offset(0)// .flip(); String NK_SHADER_VERSION = Platform.get() == Platform.MACOSX ? "#version 150\n" : "#version 300 es\n"; String vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n" + "in vec2 TexCoord;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n" + "void main() {\n" + " Frag_UV = TexCoord;\n" + " Frag_Color = Color;\n" + " gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n" + "}\n"; String fragment_shader = NK_SHADER_VERSION + "precision mediump float;\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main(){\n" + " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" + "}\n"; program = glCreateProgram(); int vert_shdr = glCreateShader(GL_VERTEX_SHADER); int frag_shdr = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(vert_shdr, vertex_shader); glShaderSource(frag_shdr, fragment_shader); glCompileShader(vert_shdr); glCompileShader(frag_shdr); if (glGetShaderi(vert_shdr, GL_COMPILE_STATUS) != GL_TRUE) { throw new IllegalStateException(); } if (glGetShaderi(frag_shdr, GL_COMPILE_STATUS) != GL_TRUE) { throw new IllegalStateException(); } glAttachShader(program, vert_shdr); glAttachShader(program, frag_shdr); glLinkProgram(program); if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) { throw new IllegalStateException(); } uniform_tex = glGetUniformLocation(program, "Texture"); uniform_proj = glGetUniformLocation(program, "ProjMtx"); int attrib_pos = glGetAttribLocation(program, "Position"); int attrib_uv = glGetAttribLocation(program, "TexCoord"); int attrib_col = glGetAttribLocation(program, "Color"); // buffer setup vbo = glGenBuffers(); ebo = glGenBuffers(); vao = glGenVertexArrays(); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glEnableVertexAttribArray(attrib_pos); glEnableVertexAttribArray(attrib_uv); glEnableVertexAttribArray(attrib_col); glVertexAttribPointer(attrib_pos, 2, GL_FLOAT, false, 20, 0); glVertexAttribPointer(attrib_uv, 2, GL_FLOAT, false, 20, 8); glVertexAttribPointer(attrib_col, 4, GL_UNSIGNED_BYTE, true, 20, 16); // null texture setup int nullTexID = glGenTextures(); null_texture.texture().id(nullTexID); null_texture.uv().set(0.5f, 0.5f); glBindTexture(GL_TEXTURE_2D, nullTexID); try (MemoryStack stack = stackPush()) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, stack.ints(0xFFFFFFFF)); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindVertexArray(0); default_font = setupFont(); nk_style_set_font(context.ctx, default_font); }