本文整理匯總了Java中com.ra4king.opengl.util.ShaderProgram.end方法的典型用法代碼示例。如果您正苦於以下問題:Java ShaderProgram.end方法的具體用法?Java ShaderProgram.end怎麽用?Java ShaderProgram.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.ra4king.opengl.util.ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram.end方法的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")));
}
示例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);
}
示例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();
}
示例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());
}
示例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());
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例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.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);
}
示例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.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);
}
示例13: 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);
}
示例14: 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);
}
示例15: init
import com.ra4king.opengl.util.ShaderProgram; //導入方法依賴的package包/類
@Override
public void init() {
glClearColor(0, 0, 0, 0);
glClearDepth(1);
program = new ShaderProgram(readFromFile("example5.5.vert"), readFromFile("example5.5.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_LESS);
glDepthRange(0, 1);
}