@Test
 public void testAvailableInfo() {
   GLDrawableFactory f = GLDrawableFactory.getDesktopFactory();
   if (null != f) {
     System.err.println(
         JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString());
   }
   f = GLDrawableFactory.getEGLFactory();
   if (null != f) {
     System.err.println(
         JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString());
   }
 }
示例#2
0
文件: GLWindow.java 项目: swkzr/jogl
  /** A most simple JOGL AWT test entry */
  public static void main(String args[]) {
    System.err.println(VersionUtil.getPlatformInfo());
    System.err.println(GlueGenVersion.getInstance());
    System.err.println(JoglVersion.getInstance());

    System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, true).toString());

    final GLProfile glp = GLProfile.getDefault();
    final GLCapabilitiesImmutable caps = new GLCapabilities(glp);

    GLWindow glWindow = GLWindow.create(caps);
    glWindow.setSize(128, 128);

    glWindow.addGLEventListener(
        new GLEventListener() {
          @Override
          public void init(GLAutoDrawable drawable) {
            GL gl = drawable.getGL();
            System.err.println(JoglVersion.getGLInfo(gl, null));
            System.err.println(
                "Requested: "
                    + drawable
                        .getNativeSurface()
                        .getGraphicsConfiguration()
                        .getRequestedCapabilities());
            System.err.println("Chosen   : " + drawable.getChosenGLCapabilities());
          }

          @Override
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}

          @Override
          public void display(GLAutoDrawable drawable) {}

          @Override
          public void dispose(GLAutoDrawable drawable) {}
        });

    glWindow.setVisible(true);
    glWindow.destroy();
  }
  @Override
  public final void init(final GL gl) {
    if (StereoDevice.DEBUG) {
      System.err.println(JoglVersion.getGLInfo(gl, null).toString());
    }
    if (null != sp) {
      throw new IllegalStateException("Already initialized");
    }
    if (!ppAvailable()) {
      return;
    }
    final GL2ES2 gl2es2 = gl.getGL2ES2();

    final String vertexShaderBasename;
    final String fragmentShaderBasename;
    {
      final boolean usesTimewarp = StereoUtil.usesTimewarpDistortion(distortionBits);
      final boolean usesChromatic = StereoUtil.usesChromaticDistortion(distortionBits);

      final StringBuilder sb = new StringBuilder();
      sb.append(shaderPrefix01);
      if (!usesChromatic && !usesTimewarp) {
        sb.append(shaderPlainSuffix);
      } else if (usesChromatic && !usesTimewarp) {
        sb.append(shaderChromaSuffix);
      } else if (usesTimewarp) {
        sb.append(shaderTimewarpSuffix);
        if (usesChromatic) {
          sb.append(shaderChromaSuffix);
        }
      }
      vertexShaderBasename = sb.toString();
      sb.setLength(0);
      sb.append(shaderPrefix01);
      if (usesChromatic) {
        sb.append(shaderChromaSuffix);
      } else {
        sb.append(shaderPlainSuffix);
      }
      fragmentShaderBasename = sb.toString();
    }
    final ShaderCode vp0 =
        ShaderCode.create(
            gl2es2,
            GL2ES2.GL_VERTEX_SHADER,
            GenericStereoDeviceRenderer.class,
            "shader",
            "shader/bin",
            vertexShaderBasename,
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl2es2,
            GL2ES2.GL_FRAGMENT_SHADER,
            GenericStereoDeviceRenderer.class,
            "shader",
            "shader/bin",
            fragmentShaderBasename,
            true);
    vp0.defaultShaderCustomization(gl2es2, true, true);
    fp0.defaultShaderCustomization(gl2es2, true, true);

    sp = new ShaderProgram();
    sp.add(gl2es2, vp0, System.err);
    sp.add(gl2es2, fp0, System.err);
    if (!sp.link(gl2es2, System.err)) {
      throw new GLException("could not link program: " + sp);
    }
    sp.useProgram(gl2es2, true);
    if (0 > texUnit0.setLocation(gl2es2, sp.program())) {
      throw new GLException("Couldn't locate " + texUnit0);
    }
    for (int i = 0; i < eyes.length; i++) {
      eyes[i].linkData(gl2es2, sp);
    }
    sp.useProgram(gl2es2, false);
  }
示例#4
0
  /** A most simple JOGL AWT test entry */
  public static void main(String args[]) {
    final boolean forceES2;
    final boolean forceES3;
    final boolean forceGL3;
    final boolean forceGL4ES3;
    {
      boolean _forceES2 = false;
      boolean _forceES3 = false;
      boolean _forceGL3 = false;
      boolean _forceGL4ES3 = false;
      if (null != args) {
        for (int i = 0; i < args.length; i++) {
          if (args[i].equals("-es2")) {
            _forceES2 = true;
          } else if (args[i].equals("-es3")) {
            _forceES3 = true;
          } else if (args[i].equals("-gl3")) {
            _forceGL3 = true;
          } else if (args[i].equals("-gl4es3")) {
            _forceGL4ES3 = true;
          }
        }
      }
      forceES2 = _forceES2;
      forceES3 = _forceES3;
      forceGL3 = _forceGL3;
      forceGL4ES3 = _forceGL4ES3;
    }
    System.err.println("forceES2    " + forceES2);
    System.err.println("forceES3    " + forceES3);
    System.err.println("forceGL3    " + forceGL3);
    System.err.println("forceGL4ES3 " + forceGL4ES3);

    System.err.println(VersionUtil.getPlatformInfo());
    System.err.println(GlueGenVersion.getInstance());
    System.err.println(JoglVersion.getInstance());

    System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, true).toString());

    final GLProfile glp;
    if (forceGL4ES3) {
      glp = GLProfile.get(GLProfile.GL4ES3);
    } else if (forceGL3) {
      glp = GLProfile.get(GLProfile.GL3);
    } else if (forceES3) {
      glp = GLProfile.get(GLProfile.GLES3);
    } else if (forceES2) {
      glp = GLProfile.get(GLProfile.GLES2);
    } else {
      glp = GLProfile.getDefault();
    }
    final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
    System.err.println("Requesting: " + caps);

    GLWindow glWindow = GLWindow.create(caps);
    glWindow.setSize(128, 128);

    glWindow.addGLEventListener(
        new GLEventListener() {
          @Override
          public void init(GLAutoDrawable drawable) {
            GL gl = drawable.getGL();
            System.err.println(JoglVersion.getGLInfo(gl, null));
            System.err.println(
                "Requested: "
                    + drawable
                        .getNativeSurface()
                        .getGraphicsConfiguration()
                        .getRequestedCapabilities());
            System.err.println("Chosen   : " + drawable.getChosenGLCapabilities());
            System.err.println("GL impl. class " + gl.getClass().getName());
            if (gl.isGL4ES3()) {
              GL4ES3 _gl = gl.getGL4ES3();
              System.err.println("GL4ES3 retrieved, impl. class " + _gl.getClass().getName());
            }
            if (gl.isGL3()) {
              GL3 _gl = gl.getGL3();
              System.err.println("GL3 retrieved, impl. class " + _gl.getClass().getName());
            }
            if (gl.isGLES3()) {
              GLES3 _gl = gl.getGLES3();
              System.err.println("GLES3 retrieved, impl. class " + _gl.getClass().getName());
            }
            if (gl.isGLES2()) {
              GLES2 _gl = gl.getGLES2();
              System.err.println("GLES2 retrieved, impl. class " + _gl.getClass().getName());
            }
          }

          @Override
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}

          @Override
          public void display(GLAutoDrawable drawable) {}

          @Override
          public void dispose(GLAutoDrawable drawable) {}
        });

    glWindow.setVisible(true);
    glWindow.destroy();
  }
示例#5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setFullscreenFeature(getWindow(), true);

    final android.view.ViewGroup viewGroup =
        new android.widget.FrameLayout(getActivity().getApplicationContext());
    getWindow().setContentView(viewGroup);

    final TextView tv = new TextView(getActivity());
    final ScrollView scroller = new ScrollView(getActivity());
    scroller.addView(tv);
    viewGroup.addView(
        scroller,
        new android.widget.FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    tv.setText(
        VersionUtil.getPlatformInfo()
            + Platform.NEWLINE
            + GlueGenVersion.getInstance()
            + Platform.NEWLINE
            + JoglVersion.getInstance()
            + Platform.NEWLINE);

    // create GLWindow (-> incl. underlying NEWT Display, Screen & Window)
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2));
    GLWindow glWindow = GLWindow.create(caps);
    glWindow.setUndecorated(true);
    glWindow.setSize(32, 32);
    glWindow.setPosition(0, 0);
    final android.view.View androidGLView =
        ((WindowDriver) glWindow.getDelegatedWindow()).getAndroidView();
    viewGroup.addView(
        androidGLView,
        new android.widget.FrameLayout.LayoutParams(
            glWindow.getWidth(), glWindow.getHeight(), Gravity.BOTTOM | Gravity.RIGHT));
    registerNEWTWindow(glWindow);

    glWindow.addGLEventListener(
        new GLEventListener() {
          public void init(GLAutoDrawable drawable) {
            GL gl = drawable.getGL();
            final StringBuffer sb = new StringBuffer();
            sb.append(JoglVersion.getGLInfo(gl, null)).append(Platform.NEWLINE);
            sb.append("Requested: ").append(Platform.NEWLINE);
            sb.append(
                    drawable
                        .getNativeSurface()
                        .getGraphicsConfiguration()
                        .getRequestedCapabilities())
                .append(Platform.NEWLINE)
                .append(Platform.NEWLINE);
            sb.append("Chosen: ").append(Platform.NEWLINE);
            sb.append(drawable.getChosenGLCapabilities())
                .append(Platform.NEWLINE)
                .append(Platform.NEWLINE);
            viewGroup.post(
                new Runnable() {
                  public void run() {
                    tv.append(sb.toString());
                    viewGroup.removeView(androidGLView);
                  }
                });
          }

          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}

          public void display(GLAutoDrawable drawable) {}

          public void dispose(GLAutoDrawable drawable) {}
        });
    glWindow.setVisible(true);
    Log.d(MD.TAG, "onCreate - X");
  }
示例#6
0
  @Override
  public void init(final GLAutoDrawable glad) {
    System.err.println(
        Thread.currentThread() + " RedSquareES2.init: tileRendererInUse " + tileRendererInUse);
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    System.err.println("RedSquareES2 init on " + Thread.currentThread());
    System.err.println("Chosen GLCapabilities: " + glad.getChosenGLCapabilities());
    System.err.println("INIT GL IS: " + gl.getClass().getName());
    System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
    if (!gl.hasGLSL()) {
      System.err.println("No GLSL available, no rendering.");
      return;
    }
    st = new ShaderState();
    st.setVerbose(true);
    final ShaderCode vp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    vp0.defaultShaderCustomization(gl, true, true);
    fp0.defaultShaderCustomization(gl, true, true);
    final ShaderProgram sp0 = new ShaderProgram();
    sp0.add(gl, vp0, System.err);
    sp0.add(gl, fp0, System.err);
    st.attachShaderProgram(gl, sp0, true);

    // setup mgl_PMVMatrix
    pmvMatrix = new PMVMatrix();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrixUniform =
        new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
    st.ownUniform(pmvMatrixUniform);
    st.uniform(gl, pmvMatrixUniform);

    // Allocate Vertex Array
    vertices =
        GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    vertices.putf(-2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(-2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.seal(gl, true);
    st.ownAttribute(vertices, true);
    vertices.enableBuffer(gl, false);

    // Allocate Color Array
    colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.seal(gl, true);
    st.ownAttribute(colors, true);
    colors.enableBuffer(gl, false);

    // OpenGL Render Settings
    gl.glEnable(GL.GL_DEPTH_TEST);
    st.useProgram(gl, false);

    t0 = System.currentTimeMillis();
    System.err.println(Thread.currentThread() + " RedSquareES2.init FIN");
  }