Java 类org.lwjgl.opengl.GL20 实例源码

项目:OcclusionQueries    文件:ShaderProgram.java   
private int loadShader(MyFile file, int type) {
    StringBuilder shaderSource = new StringBuilder();
    try {
        BufferedReader reader = file.getReader();
        String line;
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("//\n");
        }
        reader.close();
    } catch (Exception e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }
    int shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);
    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
        System.err.println("Could not compile shader "+ file);
        System.exit(-1);
    }
    return shaderID;
}
项目:EcoSystem-Official    文件:ShaderProgram.java   
public ShaderProgram(MyFile vertexFile, MyFile geometryFile, MyFile fragmentFile, String... inVariables) {
    int vertexShaderID = loadShader(vertexFile, GL20.GL_VERTEX_SHADER);
    int geometryShaderID = loadShader(geometryFile, GL32.GL_GEOMETRY_SHADER);
    int fragmentShaderID = loadShader(fragmentFile, GL20.GL_FRAGMENT_SHADER);
    programID = GL20.glCreateProgram();
    GL20.glAttachShader(programID, vertexShaderID);
    GL20.glAttachShader(programID, geometryShaderID);
    GL20.glAttachShader(programID, fragmentShaderID);
    bindAttributes(inVariables);
    GL20.glLinkProgram(programID);
    GL20.glDetachShader(programID, vertexShaderID);
    GL20.glDetachShader(programID, geometryShaderID);
    GL20.glDetachShader(programID, fragmentShaderID);
    GL20.glDeleteShader(vertexShaderID);
    GL20.glDeleteShader(geometryShaderID);
    GL20.glDeleteShader(fragmentShaderID);
}
项目:candlelight    文件:Shader.java   
public Shader(String source, int type)
{
    this.type = type;

    this.handle = GL20.glCreateShader(this.type);
    if (this.handle == 0)
    {
        throw new GLException("Unable to create main.shader!");
    }

    GL20.glShaderSource(this.handle, source);
    GL20.glCompileShader(this.handle);

    int status = GL20.glGetShaderi(this.handle, GL20.GL_COMPILE_STATUS);
    if (status == GL11.GL_FALSE)
    {
        String infolog = GL20.glGetShaderInfoLog(this.handle);
        GL20.glDeleteShader(this.handle);
        this.handle = 0;

        throw new GLException(infolog);
    }

    SHADERS.add(this);
}
项目:LowPolyWater    文件:ShaderProgram.java   
private int loadShader(MyFile file, int type) {
    StringBuilder shaderSource = new StringBuilder();
    try {
        BufferedReader reader = file.getReader();
        String line;
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("//\n");
        }
        reader.close();
    } catch (Exception e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }
    int shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);
    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
        System.err.println("Could not compile shader "+ file);
        System.exit(-1);
    }
    return shaderID;
}
项目:candlelight    文件:Program.java   
public void setUniform(String uniformName, Matrix4fc matrix)
{
    try (MemoryStack stack = MemoryStack.stackPush())
    {
        FloatBuffer fb = stack.mallocFloat(16);
        matrix.get(fb);
        GL20.glUniformMatrix4fv(this.findUniformLocation(uniformName), false, fb);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glDeleteShader(int p_153180_0_)
{
    if (arbShaders)
    {
        ARBShaderObjects.glDeleteObjectARB(p_153180_0_);
    }
    else
    {
        GL20.glDeleteShader(p_153180_0_);
    }
}
项目:candlelight    文件:Mesh.java   
public Mesh setVertexArrayBuffer(int location, int size, int stride, VBO buffer)
{
    GL30.glBindVertexArray(this.handle);
    buffer.bind();

    GL20.glVertexAttribPointer(location, size, buffer.getType(), buffer.isNormalized(), stride, 0);
    if (this.vertexBuffers.length <= location)
    {
        this.vertexBuffers = Arrays.copyOf(this.vertexBuffers, location + 1);
    }

    VBO vbo = this.vertexBuffers[location];
    if (vbo != null)
    {
        try
        {
            vbo.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    this.vertexBuffers[location] = buffer;

    buffer.unbind();
    GL30.glBindVertexArray(0);

    return this;
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glUniformMatrix2(int location, boolean transpose, FloatBuffer matrices)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniformMatrix2ARB(location, transpose, matrices);
    }
    else
    {
        GL20.glUniformMatrix2(location, transpose, matrices);
    }
}
项目:MRCEngine    文件:EntityRenderer.java   
private void unbindTexturedModel() {
    MasterRenderer.enableCulling();
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
}
项目:CustomWorldGen    文件:OpenGlHelper.java   
public static void glUniform3(int location, IntBuffer values)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniform3ARB(location, values);
    }
    else
    {
        GL20.glUniform3(location, values);
    }
}
项目:SerenityCE    文件:Shader.java   
public void setSampler2d(String label, int value){
    int loc = getUniform(label);
    GL20.glUniform1i(loc, 0);
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, value);
}
项目:candlelight    文件:Mesh.java   
public void bind()
{
    GL30.glBindVertexArray(this.handle);

    for(int i = 0; i < this.vertexBuffers.length; ++i)
    {
        if (this.vertexBuffers[i] != null)
        {
            GL20.glEnableVertexAttribArray(i);
        }
    }
}
项目:Terrain    文件:Loader.java   
private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    FloatBuffer buffer = storeDataInFloatBuffer(data);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);   // store data in the buffer - static data after it is stored in VBO
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);    // store into the VAO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // un-bind VBO
}
项目:CustomWorldGen    文件:OpenGlHelper.java   
public static void glShaderSource(int shaderIn, ByteBuffer string)
{
    if (arbShaders)
    {
        ARBShaderObjects.glShaderSourceARB(shaderIn, string);
    }
    else
    {
        GL20.glShaderSource(shaderIn, string);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glLinkProgram(int program)
{
    if (arbShaders)
    {
        ARBShaderObjects.glLinkProgramARB(program);
    }
    else
    {
        GL20.glLinkProgram(program);
    }
}
项目:LD38    文件:Quad.java   
public void draw(){
    GL30.glBindVertexArray(vao);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);

    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL30.glBindVertexArray(vao);
}
项目:EcoSystem-Official    文件:UniformVec2.java   
public void loadVec2(float x, float y) {
    if (!used || x != currentX || y != currentY) {
        this.currentX = x;
        this.currentY = y;
        used = true;
        GL20.glUniform2f(super.getLocation(), x, y);
    }
}
项目:open-world    文件:Shader.java   
/**
    * Adds the specified uniform to the lookup table and shader
    * @param uniform
    */
   public void addUniform(String uniform) {
// The location in memory of the uniform
int location = GL20.glGetUniformLocation(pid, uniform);

// If the uniform does not exist
if(location == -1) {
    System.err.println("Error in Shader.addUniform(): uniform [" + uniform + "] does not exist");
    System.exit(1);
}

// Add the uniform to the lookup table
uniforms.put(uniform, location);
   }
项目:DecompiledMinecraft    文件:OpenGlHelper.java   
public static void glUniformMatrix4(int location, boolean transpose, FloatBuffer matrices)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniformMatrix4ARB(location, transpose, matrices);
    }
    else
    {
        GL20.glUniformMatrix4(location, transpose, matrices);
    }
}
项目:Backmemed    文件:OpenGlHelper.java   
public static void glUniform4(int location, IntBuffer values)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniform4ARB(location, values);
    }
    else
    {
        GL20.glUniform4(location, values);
    }
}
项目:CustomWorldGen    文件:OpenGlHelper.java   
public static void glUniformMatrix4(int location, boolean transpose, FloatBuffer matrices)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniformMatrix4ARB(location, transpose, matrices);
    }
    else
    {
        GL20.glUniformMatrix4(location, transpose, matrices);
    }
}
项目:bia-engine    文件:ShaderProgram.java   
public void cleanUp() {
    LOGGER.debug("Cleaning resources for program - {} vertex - {} fragment - {}", programId, vertShaderId, fragShaderId);
    stop();
    GL20.glDetachShader(programId, vertShaderId);
    GL20.glDetachShader(programId, fragShaderId);
    GL20.glDeleteShader(vertShaderId);
    GL20.glDeleteShader(fragShaderId);
    GL20.glDeleteProgram(programId);
}
项目:EcoSystem-Official    文件:UniformFloat.java   
public void loadFloat(float value) {
    if (!used || currentValue != value) {
        GL20.glUniform1f(super.getLocation(), value);
        used = true;
        currentValue = value;
    }
}
项目:Terrain    文件:ShaderProgram.java   
public ShaderProgram(String vertexFile, String fragmentFile) {
    vertexShaderID = loadShader(vertexFile, GL20.GL_VERTEX_SHADER);
    fragmentShaderID = loadShader(fragmentFile, GL20.GL_FRAGMENT_SHADER);
    programID = GL20.glCreateProgram();
    GL20.glAttachShader(programID, vertexShaderID);
    GL20.glAttachShader(programID, fragmentShaderID);
    bindAttributes();
    GL20.glLinkProgram(programID);
    GL20.glValidateProgram(programID);
    getAllUniformLocations();
}
项目:bia-engine    文件:ShaderProgram.java   
protected void loadBoolean(final int location, final boolean value) {
    float toLoad = 0;
    if (value) {
        toLoad = 1;
    }
    GL20.glUniform1f(location, toLoad);
}
项目:CustomWorldGen    文件:OpenGlHelper.java   
public static void glDeleteShader(int shaderIn)
{
    if (arbShaders)
    {
        ARBShaderObjects.glDeleteObjectARB(shaderIn);
    }
    else
    {
        GL20.glDeleteShader(shaderIn);
    }
}
项目:LD38    文件:Shader.java   
/** Set an array or individual float(s)
 * 
 * @param uniform name of a uniform
 * @param floats float(s) to set
 */
public void set(String uniform, float...floats){
    if(floats.length == 1){
        GL20.glUniform1f(getUniform(uniform), floats[0]);
    }else if(floats.length == 2){
        GL20.glUniform2f(getUniform(uniform), floats[0], floats[1]);
    }else if(floats.length == 3){
        GL20.glUniform3f(getUniform(uniform), floats[0], floats[1], floats[2]);
    }else if(floats.length >= 4){
        GL20.glUniform4f(getUniform(uniform), floats[0], floats[1], floats[2], floats[3]);
    }
}
项目:candlelight    文件:Shader.java   
@Override
public void close() throws Exception
{
    GL20.glDeleteShader(this.handle);
    this.handle = 0;

    SHADERS.remove(this);
}
项目:EcoSystem-Official    文件:UniformSampler.java   
public void loadTexUnit(int texUnit) {
    if (!used || currentValue != texUnit) {
        GL20.glUniform1i(super.getLocation(), texUnit);
        used = true;
        currentValue = texUnit;
    }
}
项目:LowPolyWater    文件:UniformVec3.java   
public void loadVec3(float x, float y, float z) {
    if (!used || x != currentX || y != currentY || z != currentZ) {
        this.currentX = x;
        this.currentY = y;
        this.currentZ = z;
        used = true;
        GL20.glUniform3f(super.getLocation(), x, y, z);
    }
}
项目:Elgin-Plant-Game    文件:TerrainRenderer.java   
/**
 * Binds texture for shaders and rendering
 * @param terrain - terrain containing the texture.
 */
private void prepareTerrain(Terrain terrain) {
    RawModel rawModel = terrain.getModel();
    GL30.glBindVertexArray(rawModel.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    bindTextures(terrain);
    UniformList.terrainShineDamper.loadData(1);
    UniformList.terrainReflectivity.loadData(0);
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glUseProgram(int program)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUseProgramObjectARB(program);
    }
    else
    {
        GL20.glUseProgram(program);
    }
}
项目:BaseClient    文件:Shaders.java   
public static void clearRenderBuffer()
{
    if (isShadowPass)
    {
        checkGLError("shadow clear pre");
        EXTFramebufferObject.glFramebufferTexture2DEXT(36160, 36096, 3553, sfbDepthTextures.get(0), 0);
        GL11.glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
        GL20.glDrawBuffers(programsDrawBuffers[30]);
        checkFramebufferStatus("shadow clear");
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        checkGLError("shadow clear");
    }
    else
    {
        checkGLError("clear pre");
        GL20.glDrawBuffers(36064);
        GL11.glClear(16384);
        GL20.glDrawBuffers(36065);
        GL11.glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glClear(16384);

        for (int i = 2; i < usedColorBuffers; ++i)
        {
            GL20.glDrawBuffers(36064 + i);
            GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
            GL11.glClear(16384);
        }

        setDrawBuffers(dfbDrawBuffers);
        checkFramebufferStatus("clear");
        checkGLError("clear");
    }
}
项目:CustomWorldGen    文件:OpenGlHelper.java   
public static void glCompileShader(int shaderIn)
{
    if (arbShaders)
    {
        ARBShaderObjects.glCompileShaderARB(shaderIn);
    }
    else
    {
        GL20.glCompileShader(shaderIn);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glCompileShader(int shaderIn)
{
    if (arbShaders)
    {
        ARBShaderObjects.glCompileShaderARB(shaderIn);
    }
    else
    {
        GL20.glCompileShader(shaderIn);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glUniform2(int location, IntBuffer values)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniform2ARB(location, values);
    }
    else
    {
        GL20.glUniform2(location, values);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glUniform3(int location, FloatBuffer values)
{
    if (arbShaders)
    {
        ARBShaderObjects.glUniform3ARB(location, values);
    }
    else
    {
        GL20.glUniform3(location, values);
    }
}
项目:BaseClient    文件:OpenGlHelper.java   
public static void glShaderSource(int shaderIn, ByteBuffer string)
{
    if (arbShaders)
    {
        ARBShaderObjects.glShaderSourceARB(shaderIn, string);
    }
    else
    {
        GL20.glShaderSource(shaderIn, string);
    }
}
项目:DecompiledMinecraft    文件:OpenGlHelper.java   
public static void glLinkProgram(int program)
{
    if (arbShaders)
    {
        ARBShaderObjects.glLinkProgramARB(program);
    }
    else
    {
        GL20.glLinkProgram(program);
    }
}
项目:OcclusionQueries    文件:UniformSampler.java   
public void loadTexUnit(int texUnit) {
    if (!used || currentValue != texUnit) {
        GL20.glUniform1i(super.getLocation(), texUnit);
        used = true;
        currentValue = texUnit;
    }
}