当前位置: 首页>>代码示例>>Java>>正文


Java GL2.glGetDoublev方法代码示例

本文整理汇总了Java中com.jogamp.opengl.GL2.glGetDoublev方法的典型用法代码示例。如果您正苦于以下问题:Java GL2.glGetDoublev方法的具体用法?Java GL2.glGetDoublev怎么用?Java GL2.glGetDoublev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jogamp.opengl.GL2的用法示例。


在下文中一共展示了GL2.glGetDoublev方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPixelFromPoint

import com.jogamp.opengl.GL2; //导入方法依赖的package包/类
/**
     * Finds the chip pixel from a ChipCanvas point. From
     * <a href="http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1176483247">this
     * forum link</a>.
     *
     * @param mp a Point in ChipCanvas pixels.
     * @return the AEChip pixel, clipped to the bounds of the AEChip.
     */
    public Point getPixelFromPoint(final Point mp) {
        final double wcoord[] = new double[3];// wx, wy, wz;// returned xyz coords
        // this method depends on current GL context being the one that is used for rendering.
        // the display method should not push/pop the matrix stacks!!
        if (mp == null) {
            // log.warning("null Point (outside entire canvas?), returning center pixel");
            return new Point(chip.getSizeX() / 2, chip.getSizeY() / 2);
        }
//        synchronized (drawable.getTreeLock()) {
        try {
            if (hasAppleRetinaDisplay()) {
                mp.x *= 2;
                mp.y *= 2;
            }
            final int ret = drawable.getContext().makeCurrent();
            if (ret != GLContext.CONTEXT_CURRENT) {
                throw new GLException("couldn't make context current");
            }

            final int viewport[] = new int[4];
            final double mvmatrix[] = new double[16];
            final double projmatrix[] = new double[16];
            int realy = 0;// GL y coord pos
            // set up a floatbuffer to get the depth buffer value of the mouse position
            final FloatBuffer fb = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asFloatBuffer();
            final GL2 gl = drawable.getContext().getGL().getGL2();
            checkGLError(gl, glu, "before getting mouse point");
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GLMatrixFunc.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GLMatrixFunc.GL_PROJECTION_MATRIX, projmatrix, 0);
            /* note viewport[3] is height of window in pixels */
            realy = viewport[3] - (int) mp.getY() - 1;
            // Get the depth buffer value at the mouse position. have to do height-mouseY, as GL puts 0,0 in the bottom
            // left, not top left.
            checkGLError(gl, glu, "after getting modelview and projection matrices in getMousePoint");
//                gl.glReadPixels(mp.x, realy, 1, 1, GL2ES2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, fb);
//                checkGLError(gl, glu, "after readPixels in getMousePoint");
            final float z = 0; // fb.getString(0); // assume we want z=0 value of mouse point
            glu.gluUnProject(mp.getX(), realy, z, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            checkGLError(gl, glu, "after gluUnProject in getting mouse point");
        } catch (final GLException e) {
            log.warning("couldn't make GL context current, mouse position meaningless: " + e.toString());
        } finally {
            drawable.getContext().release();
        }
//        }
        final Point p = new Point();
        p.x = (int) Math.round(wcoord[0]);
        p.y = (int) Math.round(wcoord[1]);
        if ((p.x < 0) || (p.x > (chip.getSizeX() - 1)) || ((p.y < 0) | (p.y > (chip.getSizeY() - 1)))) {
            mouseWasInsideChipBounds = false;
        } else {
            mouseWasInsideChipBounds = true;
        }
        clipPoint(p);

        // log.info("Mouse xyz=" + mp.getX() + "," + realy + "," + z + "   Pixel x,y=" + p.x + "," + p.y);
        return p;
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:68,代码来源:ChipCanvas.java


注:本文中的com.jogamp.opengl.GL2.glGetDoublev方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。