org.lwjgl.opengl.GL20 Java Examples

The following examples show how to use org.lwjgl.opengl.GL20. 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: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore the old OpenGL state that's backed up in {@code state}.
 * @param state the old state to restore
 */
private void restoreRenderState(RenderState state) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();
	GL11.glEnable(GL11.GL_BLEND);
	GL20.glUseProgram(state.oldProgram);
	GL13.glActiveTexture(state.texUnit);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer);
	if (!state.depthWriteEnabled)
		GL11.glDepthMask(false);
	if (!state.depthEnabled)
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	if (state.texEnabled)
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	if (state.smoothedPoly)
		GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
	if (!state.blendEnabled)
		GL11.glDisable(GL11.GL_BLEND);
}
 
Example #2
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public void drawTrianglesIndexedRGB_General(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0);
}
 
Example #3
Source File: DesktopComputeJobManager.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
@Override
public JsonObject executeComputeShader() {
  GL20.glUseProgram(program);
  checkError();
  GL43.glDispatchCompute(numGroups[0], numGroups[1], numGroups[2]);
  checkError();
  GL42.glMemoryBarrier(GL43.GL_SHADER_STORAGE_BARRIER_BIT);
  checkError();
  GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject);
  checkError();
  final IntBuffer dataFromComputeShader = GL15.glMapBuffer(GL43.GL_SHADER_STORAGE_BUFFER, GL15.GL_READ_ONLY)
      .asIntBuffer();
  checkError();
  final JsonArray jsonArray = new JsonArray();
  for (int i = 0; i < dataFromComputeShader.limit(); i++) {
    jsonArray.add(dataFromComputeShader.get(i));
  }
  final JsonObject result = new JsonObject();
  result.add("output", jsonArray);
  return result;
}
 
Example #4
Source File: AbstractShaderObject.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void alloc() {
    if (dirty || shaderId == -1) {
        if (shaderId == -1) {
            shaderId = GL20.glCreateShader(type.getGLCode());
            if (shaderId == 0) {
                throw new RuntimeException("Allocation of ShaderObject failed.");
            }
        }
        GL20.glShaderSource(shaderId, getSource());
        GL20.glCompileShader(shaderId);
        if (GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            throw new RuntimeException("ShaderProgram linkage failure. \n" + GL20.glGetShaderInfoLog(shaderId));
        }
    }
}
 
Example #5
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_Quad(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_quad);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0 , vertices);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_quad);
    GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, indices);
   
    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4
   
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    
    GL11.glDrawElements(GL11.GL_TRIANGLES, 12, GL11.GL_UNSIGNED_INT, 0);
}
 
Example #6
Source File: LwjglContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void printContextInitInfo(){
    logger.log(Level.FINE, "Running on thread: {0}", Thread.currentThread().getName());

    logger.log(Level.INFO, "Adapter: {0}", Display.getAdapter());
    logger.log(Level.INFO, "Driver Version: {0}", Display.getVersion());

    String vendor = GL11.glGetString(GL11.GL_VENDOR);
    logger.log(Level.INFO, "Vendor: {0}", vendor);

    String version = GL11.glGetString(GL11.GL_VERSION);
    logger.log(Level.INFO, "OpenGL Version: {0}", version);

    String renderGl = GL11.glGetString(GL11.GL_RENDERER);
    logger.log(Level.INFO, "Renderer: {0}", renderGl);

    if (GLContext.getCapabilities().OpenGL20){
        String shadingLang = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION);
        logger.log(Level.INFO, "GLSL Ver: {0}", shadingLang);
    }
}
 
Example #7
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Cleanup any OpenGL objects that may have been initialized.
 */
private void shutdown() {
	if (gradientTexture != 0) {
		GL11.glDeleteTextures(gradientTexture);
		gradientTexture = 0;
	}

	if (program != 0) {
		GL20.glDeleteProgram(program);
		program = 0;
		attribLoc = 0;
		texCoordLoc = 0;
		colLoc = 0;
		colBorderLoc = 0;
		texLoc = 0;
	}
}
 
Example #8
Source File: ShaderProgram.java    From LowPolyWater with The Unlicense 6 votes vote down vote up
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;
}
 
Example #9
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTriangleVAO_GeneralSlow(float[] vertices) {
    int VAO_general = GL30.glGenVertexArrays();
    int VBO_general = GL15.glGenBuffers();
    GL30.glBindVertexArray(VAO_general);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(VAO_general);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example #10
Source File: GenericShader.java    From LWJGUI with MIT License 6 votes vote down vote up
protected static int createProgram(int vertexShaderId, int[] fragmentShaderIds, String[] attrs, int[] indices) {

		// build the shader program
		int id = GL20.glCreateProgram();
		GL20.glAttachShader(id, vertexShaderId);
		for (int fragmentShaderId : fragmentShaderIds) {
			GL20.glAttachShader(id, fragmentShaderId);
		}

		assert (attrs.length == indices.length);
		for (int i=0; i<attrs.length; i++) {
			GL20.glBindAttribLocation(id, indices[i], attrs[i]);
		}

		GL20.glLinkProgram(id);
		boolean isSuccess = GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_TRUE;
		if (!isSuccess) {
			throw new RuntimeException("Shader program did not link:\n" + GL20.glGetProgramInfoLog(id, 4096));
		}

		return id;
	}
 
Example #11
Source File: GLShader.java    From ldparteditor with MIT License 6 votes vote down vote up
public GLShader(final String vertexPath, final String fragmentPath) {
    final int vertex = createAndCompile(vertexPath, GL20.GL_VERTEX_SHADER);
    final int fragment = createAndCompile(fragmentPath, GL20.GL_FRAGMENT_SHADER);

    program = GL20.glCreateProgram();
    GL20.glAttachShader(program, fragment);
    GL20.glAttachShader(program, vertex);

    GL20.glLinkProgram(program);

    // FIXME Extract parameter locations
    // int baseImageLoc = GL20.glGetUniformLocation(program, "colorMap"); //$NON-NLS-1$

    if (GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        NLogger.error(GLShader.class, "Could not link shader: " + GL20.glGetProgramInfoLog(program, 1024)); //$NON-NLS-1$;
    }

    GL20.glDetachShader(program, fragment);
    GL20.glDetachShader(program, vertex);
    GL20.glDeleteShader(fragment);
    GL20.glDeleteShader(vertex);
}
 
Example #12
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_GeneralSlow(float[] vertices, int[] indices) {
    int VBO_general = GL15.glGenBuffers();
    int EBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0);

    GL15.glDeleteBuffers(VBO_general);
    GL15.glDeleteBuffers(EBO_general);
}
 
Example #13
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Cleanup any OpenGL objects that may have been initialized.
 */
private void shutdown() {
	if (gradientTexture != 0) {
		GL11.glDeleteTextures(gradientTexture);
		gradientTexture = 0;
	}

	if (program != 0) {
		GL20.glDeleteProgram(program);
		program = 0;
		attribLoc = 0;
		texCoordLoc = 0;
		colLoc = 0;
		colBorderLoc = 0;
		texLoc = 0;
	}
}
 
Example #14
Source File: DesktopComputeJobManager.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
@Override
public void createAndCompileComputeShader(String computeShaderSource) {
  Gdx.app.log("DesktopComputeJobManager", "Compiling compute shader.");
  shader = GL20.glCreateShader(GL43.GL_COMPUTE_SHADER);
  checkError();
  GL20.glShaderSource(shader, computeShaderSource);
  checkError();
  GL20.glCompileShader(shader);
  checkError();
}
 
Example #15
Source File: GLMatrixStack.java    From ldparteditor with MIT License 5 votes vote down vote up
public void glLoadIdentity() {
    final Matrix4f ID = new Matrix4f();
    Matrix4f.setIdentity(ID);
    final FloatBuffer ID_buf = BufferUtils.createFloatBuffer(16);
    ID.store(ID_buf);
    ID_buf.position(0);
    currentMatrix = ID;

    int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(model, false, ID_buf);

    int view = shader.getUniformLocation("view" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(view, false, ID_buf);
}
 
Example #16
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
private int createShader(String name, int type) throws IOException {
	int shader = GL20.glCreateShader(type);
	setObjectLabel(KHRDebug.GL_SHADER, shader, name);

	BufferedReader is = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/"+name)));
	StringBuilder source = new StringBuilder();
	String line;

	while((line = is.readLine()) != null) {
		source.append(line).append("\n");
	}

	GL20.glShaderSource(shader, source);
	GL20.glCompileShader(shader);


	String log = GL20.glGetShaderInfoLog(shader);
	if(debugOutput != null && !log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n");

	if(GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == 0) {

		GL20.glDeleteShader(shader);
		throw new Error("Could not compile " + name);
	}

	return shader;
}
 
Example #17
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
protected void specifyFormat(EGeometryFormatType format) {
	GL20.glEnableVertexAttribArray(0);

	if (format.getTexCoordPos() == -1) {
		GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0);
	} else {
		GL20.glEnableVertexAttribArray(1);
		int stride = format.getBytesPerVertexSize();
		GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, stride, 0);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, stride, format.getTexCoordPos());
	}
}
 
Example #18
Source File: GLMatrixStack.java    From ldparteditor with MIT License 5 votes vote down vote up
public void glMultMatrixf(Matrix4f matrix) {

        Matrix4f.mul(currentMatrix, matrix, currentMatrix);

        final FloatBuffer buf = BufferUtils.createFloatBuffer(16);
        currentMatrix.store(buf);
        buf.position(0);

        int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
        GL20.glUniformMatrix4fv(model, false, buf);
    }
 
Example #19
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 5 votes vote down vote up
private int loadShader(String filename, int type) {
    StringBuilder shaderSource = new StringBuilder();
    int shaderID = 0;
     
    try {
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        String line;
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("\n");
        }
        reader.close();
    } catch (IOException e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }
     
    shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);
     
    if (GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader.");
        System.exit(-1);
    }
     
    this.exitOnGLError("loadShader");
     
    return shaderID;
}
 
Example #20
Source File: LitematicaRenderer.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void disableAlphaShader()
{
    if (OpenGlHelper.shadersSupported)
    {
        GL20.glUseProgram(0);
    }
}
 
Example #21
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve.
 */
private RenderState saveRenderState() {
	RenderState state = new RenderState();
	state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
	state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
	state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
	state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
	state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
	state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
	state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
	state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
	GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(true);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

	GL20.glUseProgram(0);

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPushMatrix();
	GL11.glLoadIdentity();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPushMatrix();
	GL11.glLoadIdentity();

	return state;
}
 
Example #22
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
void init() {
	uniform_names = new String[] {"projection", "globalTransform", "transform", "texHandle", "color", "height", "uni_info"};
	shaders = new ArrayList<>();

	prog_background = new ShaderProgram("background");
	prog_unified = new ShaderProgram("tex-unified");
	prog_color = new ShaderProgram("color");
	prog_tex = new ShaderProgram("tex");

	for(ShaderProgram shader : shaders) {
		useProgram(shader);
		if(shader.ufs[TEX] != -1) GL20.glUniform1i(shader.ufs[TEX], 0);
	}
}
 
Example #23
Source File: UniformSampler.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public void loadTexUnit(int texUnit) {
	if (!used || currentValue != texUnit) {
		GL20.glUniform1i(super.getLocation(), texUnit);
		used = true;
		currentValue = texUnit;
	}
}
 
Example #24
Source File: UniformVec2.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
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);
	}
}
 
Example #25
Source File: GLMatrixStack.java    From ldparteditor with MIT License 5 votes vote down vote up
public void clear() {
    stack.clear();
    final Matrix4f ID = new Matrix4f();
    Matrix4f.setIdentity(ID);
    final FloatBuffer ID_buf = BufferUtils.createFloatBuffer(16);
    ID.store(ID_buf);
    ID_buf.position(0);
    currentMatrix = ID;
    int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
    GL20.glUniformMatrix4fv(model, false, ID_buf);
}
 
Example #26
Source File: GLShader.java    From ldparteditor with MIT License 5 votes vote down vote up
public int getUniformLocation(String uniformName) {
    int location = uniformMap.getOrDefault(uniformName, -1);
    if (location == -1) {
        location = GL20.glGetUniformLocation(program, uniformName);
    }
    if (location != -1) {
        uniformMap.put(uniformName, location);
    } else {
        NLogger.error(GLShader.class, "Could not find uniform variable: " + uniformName + "\n" + GL20.glGetProgramInfoLog(program, 1024)); //$NON-NLS-1$ //$NON-NLS-2$;
    }
    return location;
}
 
Example #27
Source File: UniformFloat.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadFloat(float value){
	if(!used || currentValue!=value){
		GL20.glUniform1f(super.getLocation(), value);
		used = true;
		currentValue = value;
	}
}
 
Example #28
Source File: UniformSampler.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadTexUnit(int texUnit) {
	if (!used || currentValue != texUnit) {
		GL20.glUniform1i(super.getLocation(), texUnit);
		used = true;
		currentValue = texUnit;
	}
}
 
Example #29
Source File: UniformBoolean.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadBoolean(boolean bool){
	if(!used || currentBool != bool){
		GL20.glUniform1f(super.getLocation(), bool ? 1f : 0f);
		used = true;
		currentBool = bool;
	}
}
 
Example #30
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public void drawLinesRGB_General(float[] vertices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_LINES, 0, vertices.length);
}