/** * Sets a specified texture's OpenGL <code>Texture</code> parameters. * * @param dc the current draw context. * @param texture the texture whose parameters to set. */ protected void setTextureParameters(DrawContext dc, Texture texture) { // Enable the appropriate mip-mapping texture filters if the caller has specified that // mip-mapping should be // enabled, and the texture itself supports mip-mapping. boolean useMipMapFilter = this.useMipMaps && (this.getTextureData().getMipmapData() != null || texture.isUsingAutoMipmapGeneration()); GL gl = dc.getGL(); gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, useMipMapFilter ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); if (this.isUseAnisotropy() && useMipMapFilter) { double maxAnisotropy = dc.getGLRuntimeCapabilities().getMaxTextureAnisotropy(); if (dc.getGLRuntimeCapabilities().isUseAnisotropicTextureFilter() && maxAnisotropy >= 2.0) { gl.glTexParameterf( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, (float) maxAnisotropy); } } }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); synchronized (this._camera) { try { gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame. NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0); this._nyar.update(this._camera); if (this._nyar.isExistMarker(this.ids[0])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } if (this._nyar.isExistMarker(this.ids[1])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } Thread.sleep(1); } catch (Exception e) { e.printStackTrace(); } } }
public void line(Coord c1, Coord c2, double w) { texsel(-1); gl.glLineWidth((float) w); gl.glBegin(GL.GL_LINES); glcolor(); vertex(c1); vertex(c2); gl.glEnd(); checkerr(); }
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadMatrixd(this._nyar.getGlProjectionMatrix(), 0); gl.glEnable(GL.GL_DEPTH_TEST); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Animator animator = new Animator(drawable); animator.start(); return; }
/** Draws circular particle using a display list. */ public void display(GL gl) { if (PARTICLE_DISPLAY_LIST < 0) { // MAKE DISPLAY LIST: int displayListIndex = gl.glGenLists(1); gl.glNewList(displayListIndex, GL.GL_COMPILE); drawParticle(gl, new Point3d(), radius); // /particle at origin gl.glEndList(); System.out.println("MADE LIST " + displayListIndex + " : " + gl.glIsList(displayListIndex)); PARTICLE_DISPLAY_LIST = displayListIndex; } // / COLOR: DEFAULT WHITE; GREEN IF HIGHLIGHTED; ADD RED IF PINNED Color3f c = new Color3f(1, 1, 1); // default: white if (pin) { c.x = 1f; // add red c.y *= 0.2f; c.z = 0; } if (highlight) { c.y = 1; c.z = 0; } if (GooParticle.class.isInstance(this)) { c.x = 0; c.y = 0; // now its blue } gl.glColor3f(c.x, c.y, c.z); // / DRAW ORIGIN-CIRCLE TRANSLATED TO "p": gl.glPushMatrix(); gl.glTranslated(x.x, x.y, x.z); gl.glCallList(PARTICLE_DISPLAY_LIST); gl.glPopMatrix(); }
public void frect(Coord ul, Coord sz) { glcolor(); texsel(-1); gl.glBegin(GL.GL_QUADS); vertex(ul); vertex(ul.add(new Coord(sz.x, 0))); vertex(ul.add(sz)); vertex(ul.add(new Coord(0, sz.y))); gl.glEnd(); checkerr(); }
public void frect(Coord c1, Coord c2, Coord c3, Coord c4) { glcolor(); texsel(-1); gl.glBegin(GL.GL_QUADS); vertex(c1); vertex(c2); vertex(c3); vertex(c4); gl.glEnd(); checkerr(); }
public final void render(G3MRenderContext rc, GLState glState) { GL gl = rc.getGL(); createGLState(); gl.clearScreen(_backgroundColor); Mesh mesh = getMesh(rc); if (mesh != null) { mesh.render(rc, _glState); } }
public void setOrthographicView(int w, int h) { gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0, w, 0.0, h); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public synchronized void bind(GL gl) { combine(); if (id < 0) id = VisUtil.allocateID(); int b[] = blocks.get(0); // the back-end special cases VBO_TYPE_COLOR, and uses gltype = unsigned byte. gl.glColor(Color.white); gl.gldBind(GL.VBO_TYPE_COLOR, id, b.length, 4, b); }
void texsel(int id) { if (id != sh.curtex) { HavenPanel.texmiss++; if (id == -1) { gl.glDisable(GL.GL_TEXTURE_2D); } else { gl.glEnable(GL.GL_TEXTURE_2D); gl.glBindTexture(GL.GL_TEXTURE_2D, id); } sh.curtex = id; } else { HavenPanel.texhit++; } }
protected void setDepthFunc(DrawContext dc, OrderedIcon uIcon, Vec4 screenPoint) { GL gl = dc.getGL(); if (uIcon.icon.isAlwaysOnTop()) { gl.glDepthFunc(GL.GL_ALWAYS); return; } Position eyePos = dc.getView().getEyePosition(); if (eyePos == null) { gl.glDepthFunc(GL.GL_ALWAYS); return; } double altitude = eyePos.getElevation(); if (altitude < (dc.getGlobe().getMaxElevation() * dc.getVerticalExaggeration())) { double depth = screenPoint.z - (8d * 0.00048875809d); depth = depth < 0d ? 0d : (depth > 1d ? 1d : depth); gl.glDepthFunc(GL.GL_LESS); gl.glDepthRange(depth, depth); } else if (uIcon.eyeDistance > uIcon.horizonDistance) { gl.glDepthFunc(GL.GL_EQUAL); gl.glDepthRange(1d, 1d); } else { gl.glDepthFunc(GL.GL_ALWAYS); } }
public void fellipse(Coord c, Coord r, int a1, int a2) { glcolor(); texsel(-1); gl.glBegin(GL.GL_TRIANGLE_FAN); vertex(c); for (int i = a1; i < a2; i += 5) { double a = (i * Math.PI * 2) / 360.0; vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y))); } double a = (a2 * Math.PI * 2) / 360.0; vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y))); gl.glEnd(); checkerr(); }
protected void applyBackgroundTextureState( DrawContext dc, int width, int height, double opacity, WWTexture texture) { super.applyBackgroundTextureState(dc, width, height, opacity, texture); // Setup the texture filters to correspond to the smoothing and mipmap settings. int minFilter = this.isEnableSmoothing() ? (this.isUseMipmaps() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR) : GL.GL_NEAREST; int magFilter = this.isEnableSmoothing() ? GL.GL_LINEAR : GL.GL_NEAREST; GL gl = dc.getGL(); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter); }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glRasterPos2i(1, 1); gl.glDrawPixels( dim.width, dim.height, // GL.GL_RGB, GL.GL_UNSIGNED_BYTE, pixels); gl.glFlush(); }
private void glcolor() { gl.glColor4f( (float) color.getRed() / 255.0f, (float) color.getGreen() / 255.0f, (float) color.getBlue() / 255.0f, (float) color.getAlpha() / 255.0f); }
/** Returns true if a hader compiler is available, otherwise false. */ public static boolean isShaderCompilerAvailable(final GL _gl) { final GL2ES2 gl = _gl.getGL2ES2(); final ProfileInformation info = getProfileInformation(gl); if (null == info.shaderCompilerAvailable) { if (gl.isGLES2()) { boolean queryOK = false; try { final byte[] param = new byte[1]; gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0); final int err = gl.glGetError(); boolean v = GL.GL_NO_ERROR == err && param[0] != (byte) 0x00; if (!v) { final Set<Integer> bfs = getShaderBinaryFormats(gl); if (bfs.size() == 0) { // no supported binary formats, hence a compiler must be available! v = true; } } info.shaderCompilerAvailable = Boolean.valueOf(v); queryOK = true; } catch (final GLException gle) { System.err.println("Caught exception on thread " + Thread.currentThread().getName()); gle.printStackTrace(); } if (!queryOK) { info.shaderCompilerAvailable = Boolean.valueOf(true); } } else if (gl.isGL2ES2()) { info.shaderCompilerAvailable = new Boolean(true); } else { throw new GLException("Invalid OpenGL profile"); } } return info.shaderCompilerAvailable.booleanValue(); }
public GLState(GL gl) { if (INSTANCES_COUNT == 0) { GLState.gl = gl; glTextureObjects = new HashSet<Integer>(); glVertexBuffers = new HashSet<Integer>(); glFrameBuffers = new HashSet<Integer>(); glRenderBuffers = new HashSet<Integer>(); glslPrograms = new HashSet<Integer>(); glslShaders = new HashSet<Integer>(); cgContexts = new HashSet<Object>(); cgPrograms = new HashSet<Object>(); cgEffects = new HashSet<Object>(); getVersionNumbers(); getAvailableExtensions(); int[] val = {0}; gl.glGetIntegerv(GL.GL_MAX_COLOR_ATTACHMENTS_EXT, val, 0); glMaxColorAttach = val[0]; glu = new GLU(); FBO = new GLFramebufferObject(gl); fboStack = new Stack<GLFramebufferObject>(); destTexStack = new Stack<GLTexture[]>(); screenFBO = new GLFramebufferObject(gl, true); currentFBO = screenFBO; emptyDestTex = new GLTexture[0]; currentDestTex = emptyDestTex; singleFBO = false; } INSTANCES_COUNT++; }
public static void checkerr(GL gl) { int err = gl.glGetError(); if (err != 0) { System.out.println("Checkerr error: " + err); throw (new GLException(err)); } }
private void InitGL() { GL.createCapabilities(); System.out.println("OpenGL: " + glGetString(GL_VERSION)); glEnable(GL13.GL_MULTISAMPLE); glEnable(GL_DEPTH_TEST); glViewport(0, 0, pix_width, pix_height); }
static GL15 create(java.util.Set<String> ext, FunctionProvider provider) { if (!ext.contains("OpenGL15")) return null; GL15 funcs = new GL15(provider); boolean supported = checkFunctions( funcs.BindBuffer, funcs.DeleteBuffers, funcs.GenBuffers, funcs.IsBuffer, funcs.BufferData, funcs.BufferSubData, funcs.GetBufferSubData, funcs.MapBuffer, funcs.UnmapBuffer, funcs.GetBufferParameteriv, funcs.GetBufferPointerv, funcs.GenQueries, funcs.DeleteQueries, funcs.IsQuery, funcs.BeginQuery, funcs.EndQuery, funcs.GetQueryiv, funcs.GetQueryObjectiv, funcs.GetQueryObjectuiv); return GL.checkExtension("OpenGL15", funcs, supported); }
public static boolean isProgramStatusValid(final GL _gl, final int programObj, final int name) { final GL2ES2 gl = _gl.getGL2ES2(); final int[] ires = new int[1]; gl.glGetProgramiv(programObj, name, ires, 0); return ires[0] == 1; }
public static boolean createAndLoadShader( final GL _gl, final IntBuffer shader, final int shaderType, final int binFormat, final java.nio.Buffer bin, final PrintStream verboseOut) { final GL2ES2 gl = _gl.getGL2ES2(); int err = gl.glGetError(); // flush previous errors .. if (err != GL.GL_NO_ERROR && null != verboseOut) { verboseOut.println("createAndLoadShader: Pre GL Error: 0x" + Integer.toHexString(err)); } createShader(gl, shaderType, shader); err = gl.glGetError(); if (err != GL.GL_NO_ERROR) { throw new GLException( "createAndLoadShader: CreateShader failed, GL Error: 0x" + Integer.toHexString(err)); } shaderBinary(gl, shader, binFormat, bin); err = gl.glGetError(); if (err != GL.GL_NO_ERROR && null != verboseOut) { verboseOut.println( "createAndLoadShader: ShaderBinary failed, GL Error: 0x" + Integer.toHexString(err)); } return err == GL.GL_NO_ERROR; }
public static void shaderSource(final GL _gl, final int shader, final CharSequence[] source) { final GL2ES2 gl = _gl.getGL2ES2(); if (!isShaderCompilerAvailable(_gl)) { throw new GLException("No compiler is available"); } final int count = (null != source) ? source.length : 0; if (count == 0) { throw new GLException("No sources specified"); } final IntBuffer lengths = Buffers.newDirectIntBuffer(count); for (int i = 0; i < count; i++) { lengths.put(i, source[i].length()); } if (source instanceof String[]) { // rare case .. gl.glShaderSource(shader, count, (String[]) source, lengths); } else { final String[] tmp = new String[source.length]; for (int i = source.length - 1; i >= 0; i--) { final CharSequence csq = source[i]; if (csq instanceof String) { // if ShaderCode.create(.. mutableStringBuilder == false ) tmp[i] = (String) csq; } else { // if ShaderCode.create(.. mutableStringBuilder == true ) tmp[i] = source[i].toString(); } } gl.glShaderSource(shader, count, tmp, lengths); } }
/** * If supported, queries the natively supported shader binary formats using {@link * GL2ES2#GL_NUM_SHADER_BINARY_FORMATS} and {@link GL2ES2#GL_SHADER_BINARY_FORMATS} via {@link * GL2ES2#glGetIntegerv(int, int[], int)}. */ public static Set<Integer> getShaderBinaryFormats(final GL _gl) { final GL2ES2 gl = _gl.getGL2ES2(); final ProfileInformation info = getProfileInformation(gl); if (null == info.shaderBinaryFormats) { info.shaderBinaryFormats = new HashSet<Integer>(); if (gl.isGLES2Compatible()) { try { final int[] param = new int[1]; gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0); final int err = gl.glGetError(); final int numFormats = GL.GL_NO_ERROR == err ? param[0] : 0; if (numFormats > 0) { final int[] formats = new int[numFormats]; gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0); for (int i = 0; i < numFormats; i++) { info.shaderBinaryFormats.add(Integer.valueOf(formats[i])); } } } catch (final GLException gle) { System.err.println("Caught exception on thread " + Thread.currentThread().getName()); gle.printStackTrace(); } } } return info.shaderBinaryFormats; }
/** Array version of: {@link #glWindowPos3dvARB WindowPos3dvARB} */ public static void glWindowPos3dvARB(double[] p) { long __functionAddress = GL.getCapabilities().glWindowPos3dvARB; if (CHECKS) { checkFunctionAddress(__functionAddress); checkBuffer(p, 3); } callPV(__functionAddress, p); }
/** Array version of: {@link #glGetVertexAttribIuivEXT GetVertexAttribIuivEXT} */ public static void glGetVertexAttribIuivEXT(int index, int pname, int[] params) { long __functionAddress = GL.getCapabilities().glGetVertexAttribIuivEXT; if (CHECKS) { checkFunctionAddress(__functionAddress); checkBuffer(params, 4); } callPV(__functionAddress, index, pname, params); }
/** Array version of: {@link #glGetUniformuivEXT GetUniformuivEXT} */ public static void glGetUniformuivEXT(int program, int location, int[] params) { long __functionAddress = GL.getCapabilities().glGetUniformuivEXT; if (CHECKS) { checkFunctionAddress(__functionAddress); checkBuffer(params, 1); } callPV(__functionAddress, program, location, params); }
/** Array version of: {@link #glVertexAttribI2uivEXT VertexAttribI2uivEXT} */ public static void glVertexAttribI2uivEXT(int index, int[] v) { long __functionAddress = GL.getCapabilities().glVertexAttribI2uivEXT; if (CHECKS) { checkFunctionAddress(__functionAddress); checkBuffer(v, 2); } callPV(__functionAddress, index, v); }
/** Draws a canonical circular particle. */ private static void drawParticle(GL gl, Point3d p, double r) { double radius = r; double vectorY1 = p.y; double vectorX1 = p.x; double vectorZ1 = p.z; GLU glu = new GLU(); GLUquadric quadratic = glu.gluNewQuadric(); glu.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); glu.gluQuadricTexture(quadratic, true); gl.glPushMatrix(); gl.glTranslated(p.x, p.y, p.z); glu.gluSphere(quadratic, radius, 12, 12); gl.glPopMatrix(); }