本文整理匯總了Java中javax.media.opengl.GL2.glCreateShader方法的典型用法代碼示例。如果您正苦於以下問題:Java GL2.glCreateShader方法的具體用法?Java GL2.glCreateShader怎麽用?Java GL2.glCreateShader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.media.opengl.GL2
的用法示例。
在下文中一共展示了GL2.glCreateShader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initShader
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Inicializuje Vertex/Fragment shader.
*
* @param gl graficky kontext
* @param shaderType typ shaderu
* @param shaderString obsah shaderu
* @return ID shaderu
*/
protected int initShader(GL2 gl, int shaderType, String shaderString) {
int shaderId = gl.glCreateShader(shaderType);
gl.glShaderSource(shaderId, 1, new String[]{shaderString}, new int[]{shaderString.length()}, 0);
gl.glCompileShader(shaderId);
checkShaderStatus(gl, shaderId, 2);
return shaderId;
}
示例2: compileShader
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Compile a shader from a file.
*
* @param context Class context for loading the resource file.
* @param gl GL context
* @param type
* @param name
* @return Shader program number.
* @throws ShaderCompilationException When compilation failed.
*/
public static int compileShader(Class<?> context, GL2 gl, int type, String name) throws ShaderCompilationException {
int prog = -1;
try (InputStream in = context.getResourceAsStream(name)) {
int[] error = new int[1];
String shaderdata = FileUtil.slurp(in);
prog = gl.glCreateShader(type);
gl.glShaderSource(prog, 1, new String[] { shaderdata }, null, 0);
gl.glCompileShader(prog);
// This worked best for me to capture error messages:
gl.glGetObjectParameterivARB(prog, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, error, 0);
if(error[0] > 1) {
byte[] info = new byte[error[0]];
gl.glGetInfoLogARB(prog, info.length, error, 0, info, 0);
String out = new String(info);
gl.glDeleteShader(prog);
throw new ShaderCompilationException("Shader compilation error in '" + name + "': " + out);
}
// Different way of catching errors.
gl.glGetShaderiv(prog, GL2.GL_COMPILE_STATUS, error, 0);
if(error[0] > 1) {
throw new ShaderCompilationException("Shader compilation of '" + name + "' failed.");
}
}
catch(IOException e) {
throw new ShaderCompilationException("IO error loading shader: " + name, e);
}
return prog;
}