當前位置: 首頁>>代碼示例>>Java>>正文


Java ShaderProgram.begin方法代碼示例

本文整理匯總了Java中com.ra4king.opengl.util.ShaderProgram.begin方法的典型用法代碼示例。如果您正苦於以下問題:Java ShaderProgram.begin方法的具體用法?Java ShaderProgram.begin怎麽用?Java ShaderProgram.begin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.ra4king.opengl.util.ShaderProgram的用法示例。


在下文中一共展示了ShaderProgram.begin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadShaders

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
private void loadShaders() {
	blocksProgram = new ShaderProgram(Utils.readFully(Resources.getInputStream("shaders/blocks.vert")),
			                                 Utils.readFully(Resources.getInputStream("shaders/blocks.frag")));
	
	projectionMatrixUniform = blocksProgram.getUniformLocation("projectionMatrix");
	viewMatrixUniform = blocksProgram.getUniformLocation("viewMatrix");
	normalMatrixUniform = blocksProgram.getUniformLocation("normalMatrix");
	
	blocksProgram.begin();
	glUniform1f(blocksProgram.getUniformLocation("cubeSize"), Chunk.BLOCK_SIZE);
	blocksProgram.end();
	
	deferredProgram = new ShaderProgram(Utils.readFully(Resources.getInputStream("shaders/deferred.vert")),
	                                     Utils.readFully(Resources.getInputStream("shaders/deferred.geom")),
			                                   Utils.readFully(Resources.getInputStream("shaders/deferred.frag")));
}
 
開發者ID:ra4king,項目名稱:OpenGL-Worlds,代碼行數:17,代碼來源:WorldRenderer.java

示例2: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	HashMap<Integer,String> attributes = new HashMap<>();
	attributes.put(0, "position");
	program = new ShaderProgram(readFromFile("example3.3.vert"), readFromFile("example3.3.frag"), attributes);
	timeLocation = glGetUniformLocation(program.getProgram(), "time");
	
	int loopDurationLocation = glGetUniformLocation(program.getProgram(), "loopDuration");
	program.begin();
	glUniform1f(loopDurationLocation, 5);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	
	glBindVertexArray(glGenVertexArrays());
	
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:26,代碼來源:Example3_3.java

示例3: initializePrograms

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
private void initializePrograms() {
	String vertexShader = readFromFile("example16.1.ScreenCoords.vert");
	noGammaProgram = new ShaderProgram(vertexShader, readFromFile("example16.1.TextureNoGamma.frag"));
	
	int projectionBlock = noGammaProgram.getUniformBlockIndex("Projection");
	glUniformBlockBinding(noGammaProgram.getProgram(), projectionBlock, projectionBlockIndex);
	
	int colorTextureUniform = noGammaProgram.getUniformLocation("colorTexture");
	noGammaProgram.begin();
	glUniform1i(colorTextureUniform, gammaRampTextureUnit);
	noGammaProgram.end();
	
	gammaProgram = new ShaderProgram(vertexShader, readFromFile("example16.1.TextureGamma.frag"));
	projectionBlock = gammaProgram.getUniformBlockIndex("Projection");
	glUniformBlockBinding(gammaProgram.getProgram(), projectionBlock, projectionBlockIndex);
	
	colorTextureUniform = gammaProgram.getUniformLocation("colorTexture");
	gammaProgram.begin();
	glUniform1i(colorTextureUniform, gammaRampTextureUnit);
	gammaProgram.end();
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:22,代碼來源:Example16_1.java

示例4: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example3.3.vert"), readFromFile("example3.3.frag"));
	timeLocation = program.getUniformLocation("time");
	
	int loopDurationLocation = program.getUniformLocation("loopDuration");
	program.begin();
	glUniform1f(loopDurationLocation, 5);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:24,代碼來源:Example3_3.java

示例5: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example3.4.vert"), readFromFile("example3.4.frag"));
	timeLocation = program.getUniformLocation("time");
	
	int loopDurationLocation = program.getUniformLocation("loopDuration");
	int fragLoopDuration = program.getUniformLocation("fragLoopDuration");
	program.begin();
	glUniform1f(loopDurationLocation, 5);
	glUniform1f(fragLoopDuration, 10);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:26,代碼來源:Example3_4.java

示例6: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
private void init() {
	Vector2 s = portal.getSize();
	
	final float[] portalData = {
	  0, 0, 0,
	  s.x(), 0, 0,
	  0, s.y(), 0,
	  
	  s.x(), s.y(), 0,
	  0, s.y(), 0,
	  s.x(), 0, 0,
	  };
	
	System.out.println(Arrays.toString(portalData));
	
	int vbo = glGenBuffers();
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(portalData.length).put(portalData).flip(), GL_STATIC_DRAW);
	
	vao = RenderUtils.glGenVertexArrays();
	RenderUtils.glBindVertexArray(vao);
	
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	
	RenderUtils.glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	portalProgram = new ShaderProgram(Utils.readFully(Resources.getInputStream("shaders/portal.vert")),
			                                 Utils.readFully(Resources.getInputStream("shaders/portal.frag")));
	
	portalProgram.begin();
	glUniform1i(portalProgram.getUniformLocation("portalTex"), 0);
	glUniform2f(portalProgram.getUniformLocation("size"), s.x(), s.y());
}
 
開發者ID:ra4king,項目名稱:OpenGL-Worlds,代碼行數:36,代碼來源:PortalRenderer.java

示例7: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	HashMap<Integer,String> attributes = new HashMap<>();
	attributes.put(0, "position");
	program = new ShaderProgram(readFromFile("example3.4.vert"), readFromFile("example3.4.frag"), attributes);
	timeLocation = glGetUniformLocation(program.getProgram(), "time");
	
	int loopDurationLocation = glGetUniformLocation(program.getProgram(), "loopDuration");
	int fragLoopDuration = glGetUniformLocation(program.getProgram(), "fragLoopDuration");
	program.begin();
	glUniform1f(loopDurationLocation, 5);
	glUniform1f(fragLoopDuration, 10);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	
	glBindVertexArray(glGenVertexArrays());
	
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:28,代碼來源:Example3_4.java

示例8: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example4.3.vert"), readFromFile("example4.3.frag"));
	
	offsetUniform = program.getUniformLocation("offset");
	
	int perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix");
	
	float frustumScale = 1, zNear = 0.5f, zFar = 3;
	FloatBuffer perspectiveMatrix = BufferUtils.createFloatBuffer(16);
	perspectiveMatrix.put(0, frustumScale);
	perspectiveMatrix.put(5, frustumScale);
	perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	perspectiveMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:36,代碼來源:Example4_3.java

示例9: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example4.4.vert"), readFromFile("example4.4.frag"));
	
	offsetUniform = program.getUniformLocation("offset");
	
	perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix");
	
	float zNear = 0.5f, zFar = 3;
	perspectiveMatrix = BufferUtils.createFloatBuffer(16);
	perspectiveMatrix.put(0, frustumScale);
	perspectiveMatrix.put(5, frustumScale);
	perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	perspectiveMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:36,代碼來源:Example4_4.java

示例10: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example4.2.vert"), readFromFile("example4.2.frag"));
	
	offsetUniform = program.getUniformLocation("offset");
	
	int frustumScaleUniform = program.getUniformLocation("frustumScale");
	int zNearUniform = program.getUniformLocation("zNear");
	int zFarUniform = program.getUniformLocation("zFar");
	
	program.begin();
	glUniform1f(frustumScaleUniform, 1);
	glUniform1f(zNearUniform, 1);
	glUniform1f(zFarUniform, 3);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:32,代碼來源:Example4_2.java

示例11: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	
	program = new ShaderProgram(readFromFile("example6.3.vert"), readFromFile("example6.3.frag"));
	
	modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
	cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
	
	modelToCameraMatrices = new Matrix4[5];
	for(int a = 0; a < modelToCameraMatrices.length; a++)
		modelToCameraMatrices[a] = new Matrix4();
	
	float zNear = 1, zFar = 61;
	cameraToClipMatrix = new Matrix4();
	cameraToClipMatrix.put(0, frustumScale);
	cameraToClipMatrix.put(5, frustumScale);
	cameraToClipMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	cameraToClipMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	cameraToClipMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(cameraToClipMatrixUniform, false, cameraToClipMatrix.toBuffer());
	program.end();
	
	int vbo1 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	int vbo2 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
	glBufferData(GL_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	vao = glGenVertexArrays();
	glBindVertexArray(vao);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 8 * 3 * 4);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	glBindVertexArray(0);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
	
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0, 1);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:60,代碼來源:Example6_3.java

示例12: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	
	program = new ShaderProgram(readFromFile("example6.1.vert"), readFromFile("example6.1.frag"));
	
	modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
	cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
	
	modelToCameraMatrices = new Matrix4[3];
	for(int a = 0; a < modelToCameraMatrices.length; a++)
		modelToCameraMatrices[a] = new Matrix4();
	
	float zNear = 1, zFar = 45;
	cameraToClipMatrix = new Matrix4();
	cameraToClipMatrix.put(0, frustumScale);
	cameraToClipMatrix.put(5, frustumScale);
	cameraToClipMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	cameraToClipMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	cameraToClipMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(cameraToClipMatrixUniform, false, cameraToClipMatrix.toBuffer());
	program.end();
	
	int vbo1 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	int vbo2 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
	glBufferData(GL_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	vao = glGenVertexArrays();
	glBindVertexArray(vao);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 8 * 3 * 4);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	glBindVertexArray(0);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
	
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0, 1);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:60,代碼來源:Example6_1.java

示例13: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	
	program = new ShaderProgram(readFromFile("example6.2.vert"), readFromFile("example6.2.frag"));
	
	modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
	cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
	
	modelToCameraMatrices = new Matrix4[5];
	for(int a = 0; a < modelToCameraMatrices.length; a++)
		modelToCameraMatrices[a] = new Matrix4();
	
	float zNear = 1, zFar = 61;
	cameraToClipMatrix = new Matrix4();
	cameraToClipMatrix.put(0, frustumScale);
	cameraToClipMatrix.put(5, frustumScale);
	cameraToClipMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	cameraToClipMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	cameraToClipMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(cameraToClipMatrixUniform, false, cameraToClipMatrix.toBuffer());
	program.end();
	
	int vbo1 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	int vbo2 = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
	glBufferData(GL_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	vao = glGenVertexArrays();
	glBindVertexArray(vao);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 8 * 3 * 4);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	glBindVertexArray(0);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
	
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0, 1);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:60,代碼來源:Example6_2.java

示例14: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	
	program = new ShaderProgram(readFromFile("example5.3.vert"), readFromFile("example5.3.frag"));
	
	offsetUniform = program.getUniformLocation("offset");
	
	perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix");
	
	float zNear = 1, zFar = 3;
	perspectiveMatrix = BufferUtils.createFloatBuffer(16);
	perspectiveMatrix.put(0, frustumScale);
	perspectiveMatrix.put(5, frustumScale);
	perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	perspectiveMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix);
	program.end();
	
	int vbo1 = glGenBuffers();
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	int vbo2 = glGenBuffers();
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	
	vao = glGenVertexArrays();
	glBindVertexArray(vao);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 36 * 3 * 4);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	glBindVertexArray(0);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
	
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0, 1);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:55,代碼來源:Example5_3.java

示例15: init

import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example5.1.vert"), readFromFile("example5.1.frag"));
	
	offsetUniform = program.getUniformLocation("offset");
	
	perspectiveMatrixUniform = program.getUniformLocation("perspectiveMatrix");
	
	float zNear = 0.5f, zFar = 3;
	perspectiveMatrix = BufferUtils.createFloatBuffer(16);
	perspectiveMatrix.put(0, frustumScale);
	perspectiveMatrix.put(5, frustumScale);
	perspectiveMatrix.put(10, (zFar + zNear) / (zNear - zFar));
	perspectiveMatrix.put(14, (2 * zFar * zNear) / (zNear - zFar));
	perspectiveMatrix.put(11, -1);
	
	program.begin();
	glUniformMatrix4(perspectiveMatrixUniform, false, perspectiveMatrix);
	program.end();
	
	int vbo1 = glGenBuffers();
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(data.length).put(data).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	int vbo2 = glGenBuffers();
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, (ShortBuffer)BufferUtils.createShortBuffer(indices.length).put(indices).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	
	vao1 = glGenVertexArrays();
	glBindVertexArray(vao1);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 36 * 3 * 4);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	vao2 = glGenVertexArrays();
	glBindVertexArray(vao2);
	
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 36 / 2 * 3 * 4);
	glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, (36 * 3 * 4) + (36 / 2 * 4 * 4));
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2);
	
	glBindVertexArray(0);
	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
}
 
開發者ID:ra4king,項目名稱:LWJGL-OpenGL-Tutorials,代碼行數:58,代碼來源:Example5_1.java


注:本文中的com.ra4king.opengl.util.ShaderProgram.begin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。