本文整理汇总了Java中com.ra4king.opengl.util.ShaderProgram.getUniformLocation方法的典型用法代码示例。如果您正苦于以下问题:Java ShaderProgram.getUniformLocation方法的具体用法?Java ShaderProgram.getUniformLocation怎么用?Java ShaderProgram.getUniformLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ra4king.opengl.util.ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram.getUniformLocation方法的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: 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();
}
示例3: init
import com.ra4king.opengl.util.ShaderProgram; //导入方法依赖的package包/类
@Override
public void init() {
glClearColor(0, 0, 0, 0);
program = new ShaderProgram(readFromFile("example4.1.vert"), readFromFile("example4.1.frag"));
offsetUniform = program.getUniformLocation("offset");
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);
}
示例4: 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());
}
示例5: init
import com.ra4king.opengl.util.ShaderProgram; //导入方法依赖的package包/类
@Override
public void init() {
glClearColor(0, 0, 0, 0);
program = new ShaderProgram(readFromFile("example3.2.vert"), readFromFile("example3.2.frag"));
offsetLocation = program.getUniformLocation("offset");
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);
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);
}
示例7: 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);
}
示例8: 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);
}
示例9: init
import com.ra4king.opengl.util.ShaderProgram; //导入方法依赖的package包/类
@Override
public void init() {
glClearColor(0, 0, 0, 0);
glClearDepth(1);
program = new ShaderProgram(readFromFile("example8.2.vert"), readFromFile("example8.2.frag"));
modelToClipMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
baseColorUniform = program.getUniformLocation("baseColor");
try {
ship = new Mesh(getClass().getResource("example8.2.Ship.xml"));
} catch(Exception exc) {
exc.printStackTrace();
destroy();
}
orientation = new Quaternion();
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glDepthFunc(GL_LEQUAL);
glDepthRange(0, 1);
}
示例10: init
import com.ra4king.opengl.util.ShaderProgram; //导入方法依赖的package包/类
@Override
public void init() {
glClearColor(0, 0, 0, 0);
glClearDepth(1);
program = new ShaderProgram(readFromFile("example8.4.vert"), readFromFile("example8.4.frag"));
modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
baseColorUniform = program.getUniformLocation("baseColor");
try {
ship = new Mesh(getClass().getResource("example8.4.Ship.xml"));
} catch(Exception exc) {
exc.printStackTrace();
destroy();
}
orientation = new Orientation();
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("example8.1.vert"), readFromFile("example8.1.frag"));
modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
baseColorUniform = program.getUniformLocation("baseColor");
cameraToClipMatrix = new Matrix4();
String[] gimbalNames = { "example8.1.LargeGimbal.xml", "example8.1.MediumGimbal.xml", "example8.1.SmallGimbal.xml" };
gimbals = new Mesh[gimbalNames.length];
try {
for(int a = 0; a < gimbalNames.length; a++)
gimbals[a] = new Mesh(getClass().getResource(gimbalNames[a]));
ship = new Mesh(getClass().getResource("example8.1.Ship.xml"));
} catch(Exception exc) {
exc.printStackTrace();
destroy();
}
angles = new GimbalAngles();
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("example8.3.vert"), readFromFile("example8.3.frag"));
modelToCameraMatrixUniform = program.getUniformLocation("modelToCameraMatrix");
cameraToClipMatrixUniform = program.getUniformLocation("cameraToClipMatrix");
baseColorUniform = program.getUniformLocation("baseColor");
try {
ship = new Mesh(getClass().getResource("example8.3.Ship.xml"));
plane = new Mesh(getClass().getResource("example8.3.Plane.xml"));
} catch(Exception exc) {
exc.printStackTrace();
destroy();
}
orientation = new Quaternion();
camTarget = new Vector3(0, 10, 0);
sphereCamRelPos = new Vector3(90, 0, 66);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glDepthFunc(GL_LEQUAL);
glDepthRange(0, 1);
}
示例13: BulletRenderer
import com.ra4king.opengl.util.ShaderProgram; //导入方法依赖的package包/类
public BulletRenderer(BulletManager bulletManager) {
this.bulletManager = bulletManager;
bulletProgram = new ShaderProgram(Utils.readFully(Resources.getInputStream("shaders/bullet.vert")),
Utils.readFully(Resources.getInputStream("shaders/bullet.frag")));
projectionMatrixUniform = bulletProgram.getUniformLocation("projectionMatrix");
modelViewMatrixUniform = bulletProgram.getUniformLocation("modelViewMatrix");
float[] bulletMappings = {
-0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f
};
FloatBuffer bulletMappingsBuffer = BufferUtils.createFloatBuffer(bulletMappings.length);
bulletMappingsBuffer.put(bulletMappings).flip();
vao = RenderUtils.glGenVertexArrays();
RenderUtils.glBindVertexArray(vao);
int bulletMappingsVBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, bulletMappingsVBO);
glBufferData(GL_ARRAY_BUFFER, bulletMappingsBuffer, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
bulletDataBuffer = BufferUtils.createFloatBuffer(BULLET_BUFFER_SIZE / 4);
bulletDataVBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, bulletDataVBO);
glBufferData(GL_ARRAY_BUFFER, BULLET_BUFFER_SIZE, GL_STREAM_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 2 * 4 * 4, 0);
RenderUtils.glVertexAttribDivisor(1, 1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_FLOAT, false, 2 * 4 * 4, 4 * 4);
RenderUtils.glVertexAttribDivisor(2, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
RenderUtils.glBindVertexArray(0);
}
示例14: 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);
}
示例15: 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);
}