Java Code Examples for org.lwjgl.opengl.GL20#glEnableVertexAttribArray()

The following examples show how to use org.lwjgl.opengl.GL20#glEnableVertexAttribArray() . 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: GL33Helper.java    From ldparteditor with MIT License 7 votes vote down vote up
public static void drawLinesRGB_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    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);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 2
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 3
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_Triangle(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_triangle);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertices);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_triangle);
    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, 6, GL11.GL_UNSIGNED_INT, 0);
}
 
Example 4
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 5
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 6
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst) {
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	}
	final int mirrors = OPTION_DANCE_MIRROR.state ? this.mirrors : 1;
	for (int i = 0; i < mirrors; i++) {
		if (pointsToRender == null) {
			renderCurve(from, to, i);
		} else {
			renderCurve(i);
		}
		//from++;
		//to++;
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 7
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int to) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform4f(staticState.colLoc, color.r, color.g, color.b, color.a);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);

	float lastSegmentX = to == 0 ? curve[1].x - curve[0].x : curve[to].x - curve[to-1].x;
	float lastSegmentY = to == 0 ? curve[1].y - curve[0].y : curve[to].y - curve[to-1].y;
	float lastSegmentInvLen = 1.f/(float)Math.hypot(lastSegmentX, lastSegmentY);
	GL20.glUniform4f(staticState.endPointLoc, curve[to].x, curve[to].y, lastSegmentX * lastSegmentInvLen, lastSegmentY * lastSegmentInvLen);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);

	GL11.glColorMask(false,false,false,false);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glColorMask(true,true,true,true);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glDepthFunc(GL11.GL_EQUAL);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glDepthFunc(GL11.GL_LESS);

	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 8
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 9
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawTriangle_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    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);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 10
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawTrianglesIndexedTextured_GeneralSlow(float[] vertices, int[] indices) {
    int VAO_general = GL30.glGenVertexArrays();
    int VBO_general = GL15.glGenBuffers();
    int EBO_general = GL15.glGenBuffers();
    GL30.glBindVertexArray(VAO_general);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

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

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

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

    GL20.glEnableVertexAttribArray(TEX_COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(TEX_COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 24);

    GL20.glEnableVertexAttribArray(UV_SHADER_LOCATION);
    GL20.glVertexAttribPointer(UV_SHADER_LOCATION, 2, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 40);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

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

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(VAO_general);
    GL15.glDeleteBuffers(VBO_general);
    GL15.glDeleteBuffers(EBO_general);
}
 
Example 11
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void drawTrianglesWithTextureColored(TextureHandle textureid, GeometryHandle shapeHandle, GeometryHandle colorHandle, int offset, int lines, int width, int stride, float x, float y) {
	bindTexture(textureid);

	if(backgroundVAO == -1) {
		if(glcaps.GL_ARB_vertex_array_object) {
			backgroundVAO = ARBVertexArrayObject.glGenVertexArrays();
			bindFormat(backgroundVAO);
		}
		GL20.glEnableVertexAttribArray(0);
		GL20.glEnableVertexAttribArray(1);
		GL20.glEnableVertexAttribArray(2);

		bindGeometry(shapeHandle);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * 4, 0);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * 4, 3 * 4);

		bindGeometry(colorHandle);
		GL20.glVertexAttribPointer(2, 1, GL11.GL_FLOAT, false, 0, 0);

		setObjectLabel(GL11.GL_VERTEX_ARRAY, backgroundVAO, "background-vao");
		setObjectLabel(KHRDebug.GL_BUFFER, shapeHandle.getInternalId(), "background-shape");
		setObjectLabel(KHRDebug.GL_BUFFER, colorHandle.getInternalId(), "background-color");
	}
	int starti = offset < 0 ? (int)Math.ceil(-offset/(float)stride) : 0;

	useProgram(prog_background);

	GL20.glUniform2f(prog_background.ufs[TRANS], x, y);

	bindFormat(backgroundVAO);
	for (int i = starti; i != lines; i++) {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, (offset + stride * i) * 3, width * 3);
	}
}
 
Example 12
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);
}
 
Example 13
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 14
Source File: ShaderHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void glEnableVertexAttribArray(int index) {
	GL20.glEnableVertexAttribArray(index);
}
 
Example 15
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 4 votes vote down vote up
public static void createVBO_PrimitiveArea() {
    VBO_triangle = GL15.glGenBuffers();
    EBO_triangle = GL15.glGenBuffers();
    VBO_quad = GL15.glGenBuffers();
    EBO_quad = GL15.glGenBuffers();
    VBO_line = GL15.glGenBuffers();
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_quad);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[48], GL15.GL_DYNAMIC_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_quad);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, new int[12], GL15.GL_DYNAMIC_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);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_triangle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[36], GL15.GL_DYNAMIC_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_triangle);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, new int[6], GL15.GL_DYNAMIC_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);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_line);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[12], GL15.GL_DYNAMIC_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);
}
 
Example 16
Source File: vboWithIndices.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {
    
    Matrix4f.setIdentity(viewport);
    shaderProgram = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    shaderProgram.use();
    
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.primitive_background_Colour_r[0], View.primitive_background_Colour_g[0], View.primitive_background_Colour_b[0], 1.0f);
    
    new Thread(new Runnable() {
        
        @Override
        public void run() {

            while (isRendering.get()) {
                
                final float zoom = cp.getZoom();
                final Matrix4f viewport_translation = cp.getTranslation();
                final float STEP = 22f * zoom * View.PIXEL_PER_LDU;
                cp.setRotationWidth(STEP);
                
                Matrix4f viewport_transform = new Matrix4f();
                Matrix4f.setIdentity(viewport_transform);
                Matrix4f.scale(new Vector3f(zoom, zoom, zoom), viewport_transform, viewport_transform);
                Matrix4f.mul(viewport_transform, viewport_translation, viewport_transform);
                cp.setViewport(viewport_transform);
                viewport = viewport_transform;
                
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.5f, -0.5f, 0.0f,  // Bottom Right
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        -0.5f,  0.5f, 0.0f   // Top Left 
    };
    int[] indices = new int[]{  // Note that we start from 0!
        0, 1, 3,  // First Triangle
        1, 2, 3   // Second Triangle
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    EBO = GL15.glGenBuffers();
    // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
    GL30.glBindVertexArray(VAO);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);

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

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

    GL30.glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO

}
 
Example 17
Source File: vboWithRGBA.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {
    
    Matrix4f.setIdentity(viewport);
    shaderProgram = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    shaderProgram.use();
    
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.primitive_background_Colour_r[0], View.primitive_background_Colour_g[0], View.primitive_background_Colour_b[0], 1.0f);
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.0f,  0.0f, 1.0f,  // Normal
         1.0f, 0.0f, 0.0f, 1.0f, // Colour
         
         0.5f, -0.5f, 0.0f,  // Bottom Right
         0.0f,  0.0f, 1.0f,  // Normal
         0.0f, 1.0f, 0.0f, 1.0f, // Colour
         
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        0.0f,  0.0f, 1.0f,  // Normal
        0.0f, 0.0f, 1.0f, 1.0f, // Colour
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
    GL30.glBindVertexArray(VAO);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 0);
    
    GL20.glEnableVertexAttribArray(NORMAL_SHADER_LOCATION);
    GL20.glVertexAttribPointer(NORMAL_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 3 * 4);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, (3 + 3) * 4);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

    GL30.glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO

}
 
Example 18
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
private void loopCycle() {
    // Logic
    while(Keyboard.next()) {
        // Only listen to events where the key was pressed (down event)
        if (!Keyboard.getEventKeyState()) continue;
         
        // Switch textures depending on the key released
        switch (Keyboard.getEventKey()) {
        case Keyboard.KEY_1:
            textureSelector = 0;
            break;
        case Keyboard.KEY_2:
            textureSelector = 1;
            break;
        }
    }
     
    // Render
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     
    GL20.glUseProgram(pId);
     
    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]);
     
    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
     
    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
     
    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
     
    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
     
    GL20.glUseProgram(0);
     
    this.exitOnGLError("loopCycle");
}
 
Example 19
Source File: FastBlockModelRenderer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public static void renderVertexBuffer(VertexBuffer vertexBuffer) {
    // Check if optifine shaders are currently loaded.
    final boolean areOptifineShadersEnabled = GibsModelRegistry.isOptifineShadersEnabled();

    GlStateManager.pushMatrix();
    GlStateManager.resetColor();

    GlStateManager.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
    GlStateManager.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
    GlStateManager.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
    GlStateManager.glEnableClientState(GL11.GL_COLOR_ARRAY);

    // Extra OpenGL states that must be enabled when shaders are enabled.
    if (areOptifineShadersEnabled) {
        GL11.glEnableClientState(32885);
        GL20.glEnableVertexAttribArray(11);
        GL20.glEnableVertexAttribArray(12);
        GL20.glEnableVertexAttribArray(10);
    }

    GlStateManager.pushMatrix();
    vertexBuffer.bindBuffer();

    // Even more OpenGL states that must be enabled when shaders are enabled.
    if (areOptifineShadersEnabled) {
        int vertexSizeI = 14;
        GL11.glVertexPointer(3, 5126, 56, 0L);
        GL11.glColorPointer(4, 5121, 56, 12L);
        GL11.glTexCoordPointer(2, 5126, 56, 16L);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
        GL11.glTexCoordPointer(2, 5122, 56, 24L);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
        GL11.glNormalPointer(5120, 56, 28L);
        GL20.glVertexAttribPointer(11, 2, 5126, false, 56, 32L);
        GL20.glVertexAttribPointer(12, 4, 5122, false, 56, 40L);
        GL20.glVertexAttribPointer(10, 3, 5122, false, 56, 48L);
    } else {

        GlStateManager.glVertexPointer(3, 5126, 28, 0);
        GlStateManager.glColorPointer(4, 5121, 28, 12);
        GlStateManager.glTexCoordPointer(2, 5126, 28, 16);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
        GlStateManager.glTexCoordPointer(2, 5122, 28, 24);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
    }

    vertexBuffer.drawArrays(7);
    GlStateManager.popMatrix();
    vertexBuffer.unbindBuffer();
    GlStateManager.resetColor();

    for (VertexFormatElement vertexformatelement : DefaultVertexFormats.BLOCK.getElements()) {
        VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement
            .getUsage();
        int i = vertexformatelement.getIndex();

        switch (vertexformatelement$enumusage) {
            case POSITION:
                GlStateManager.glDisableClientState(32884);
                break;
            case UV:
                OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit + i);
                GlStateManager.glDisableClientState(32888);
                OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
                break;
            case COLOR:
                GlStateManager.glDisableClientState(32886);
                GlStateManager.resetColor();
        }
    }

    OpenGlHelper.glBindBuffer(OpenGlHelper.GL_ARRAY_BUFFER, 0);

    // Finally disable some of those extra OpenGL states that were be enabled due to shaders.
    if (areOptifineShadersEnabled) {
        GL11.glDisableClientState(32885);
        GL20.glDisableVertexAttribArray(11);
        GL20.glDisableVertexAttribArray(12);
        GL20.glDisableVertexAttribArray(10);
    }

    GlStateManager.resetColor();
    GlStateManager.popMatrix();
}
 
Example 20
Source File: GearGL33.java    From ldparteditor with MIT License 3 votes vote down vote up
public void draw(GLMatrixStack stack, GLShader shader, float x, float y, float z, float r, float g, float b) {
    
    final GLShader backup = stack.getShader();
    
    stack.setShader(shader);
    shader.use();
    
    stack.glPushMatrix();
    stack.glLoadIdentity();
    stack.glTranslatef(x, y, z);

    final int colour = shader.getUniformLocation("color"); //$NON-NLS-1$
    GL20.glUniform3f(colour, r, g, b);
    final int VBO = GL15.glGenBuffers();
    final int EBO = GL15.glGenBuffers();        
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bvertices, GL15.GL_STREAM_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, bindices, GL15.GL_STREAM_DRAW);
    
    GL20.glEnableVertexAttribArray(0);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 12, 0);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawElements(GL11.GL_TRIANGLES, bindices.capacity(), GL11.GL_UNSIGNED_INT, 0);

    GL15.glDeleteBuffers(VBO);
    GL15.glDeleteBuffers(EBO);

    stack.setShader(backup);
    backup.use();
    
    stack.glPopMatrix();
}