java 1f_Java GL20.glUniform1f方法代码示例

import org.lwjgl.opengl.GL20; //导入方法依赖的package包/类

public static void runShader() {

Minecraft mc = Minecraft.getMinecraft();

//TODO remove

if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD5)) {

destroyShader();

createShader();

}

//Use shader program

GL20.glUseProgram(shader.getShaderProgram());

//TODO third person view

Entity entity = mc.getRenderViewEntity();

float partialTicks = mc.getRenderPartialTicks();

double entityPosX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;

double entityPosY = entity.lastTickPosY + entity.getEyeHeight() + (entity.posY - entity.lastTickPosY) * (double)partialTicks;

double entityPosZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;

float fov = (float) Math.toRadians(mc.entityRenderer.getFOVModifier(partialTicks, true));

//Set uniform values

int texUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "tex");

GL20.glUniform1i(texUniform, 0);

int cameraPosUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "cameraPos");

GL20.glUniform3f(cameraPosUniform, (float)entityPosX%16, (float)entityPosY%16, (float)entityPosZ%16);

int cameraDirUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "cameraDir");

GL20.glUniform3f(cameraDirUniform, -(float)Math.toRadians(entity.rotationPitch), (float)Math.toRadians(180+entity.rotationYaw), 0);

int fovyUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "fovy");

GL20.glUniform1f(fovyUniform, fov);

int fovxUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "fovx");

GL20.glUniform1f(fovxUniform, fov*Display.getWidth()/(float)Display.getHeight());

int sphericalUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "spherical");

GL20.glUniform1i(sphericalUniform, RayTracerSettings.spherical ? 1 : 0);

int stereoscopicUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "stereoscopic3d");

GL20.glUniform1i(stereoscopicUniform, RayTracerSettings.stereoscopic ? 1 : 0);

int eyeWidthUniform = GL20.glGetUniformLocation(shader.getShaderProgram(), "eyeWidth");

GL20.glUniform1f(eyeWidthUniform, 0.063f); //TODO input eyeWidth option

if (!pauseRendering) {

if (worldLoader == null) {

worldLoader = new WorldLoader();

}

if (worldLoader.dimension != mc.world.provider.getDimension()) {

worldLoader.dimension = mc.world.provider.getDimension();

}

worldLoader.updateWorld(entityPosX, entityPosY, entityPosZ, shader);

//Setup view

GL11.glMatrixMode(GL11.GL_PROJECTION);

GL11.glPushMatrix();

GL11.glLoadIdentity();

GL11.glOrtho(-1, 1, -1, 1, -1, 1);

GL11.glMatrixMode(GL11.GL_MODELVIEW);

GL11.glPushMatrix();

GL11.glLoadIdentity();

//Bind vbo and texture

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, shader.getVbo());

GL20.glEnableVertexAttribArray(0);

GL20.glVertexAttribPointer(0, 2, GL11.GL_BYTE, false, 0, 0L);

GL11.glBindTexture(GL11.GL_TEXTURE_2D, 8);

//Render

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

//Reset vbo and texture

GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

GL20.glDisableVertexAttribArray(0);

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

//Reset view

GL11.glMatrixMode(GL11.GL_PROJECTION);

GL11.glPopMatrix();

GL11.glMatrixMode(GL11.GL_MODELVIEW);

GL11.glPopMatrix();

}

//Stop using shader program

GL20.glUseProgram(0);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值