Пример #1
0
    // @Override
    public void onDrawFrame(GL10 gl) {
      // 采用平滑着色
      gl.glShadeModel(GL10.GL_SMOOTH);
      // 设置为打开背面剪裁
      gl.glEnable(GL10.GL_CULL_FACE);
      // 清除颜色缓存于深度缓存
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      // 设置当前矩阵为模式矩阵
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      // 设置当前矩阵为单位矩阵
      gl.glLoadIdentity();

      // 设置camera位置
      GLU.gluLookAt(
          gl, cx, // 人眼位置的X
          cy, // 人眼位置的Y
          cz, // 人眼位置的Z
          tx, // 人眼球看的点X
          ty, // 人眼球看的点Y
          tz, // 人眼球看的点Z
          0, 1, 0);

      gl.glPushMatrix();
      gl.glTranslatef(0, -0.1f, 0);
      floor.drawSelf(gl);
      gl.glPopMatrix();

      gl.glPushMatrix();
      for (BallController_2 bfcc : albfc) {
        bfcc.drawSelf(gl);
      }
      gl.glPopMatrix();
    }
Пример #2
0
  public void update(GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // dopisane
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    // gl.glLoadIdentity();

    // koniec
    if (hasChanged) {
      GLU.gluLookAt(gl, xEye, yEye, zEye, xLook, yLook, zLook, xUp, yUp, zUp);
      hasChanged = false;
    }
    // GL11 gl11 = (GL11) gl;
    // gl11.glGetFloatv(GL10.GL_MODELVIEW, modelview, 0); // wystarczyło
    // dopisać 0 i już
    // traktuje jako
    // float
    // gl11.glGetFloatv(GL10.GL_PROJECTION, projection, 0);

    // NIEPOTRZEBNE BO DZIAła i bez tego
    /*
     * gl.glLoadIdentity(); gl.glFrustumf(-aspect, aspect, -1f, 1f, near,
     * far); gl.glRotatef(xAngle * 10, 1f, 0, 0); gl.glRotatef(yAngle * 10,
     * 0, 1f, 0); gl.glRotatef(zAngle, 0f, 0f, 1f); gl.glTranslatef(xPos,
     * yPos, zPos);
     */

  }
Пример #3
0
  public void onDrawFrame(GL10 gl) {
    // gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Reset the Modelview Matrix
    gl.glLoadIdentity();

    if (cameraChanged) {
      // square.drawBackground(gl);

      GLU.gluLookAt(
          gl,
          camera.getEyeX(),
          camera.getEyeY(),
          camera.getEyeZ(),
          camera.getCenterX(),
          camera.getCenterY(),
          camera.getCenterZ(),
          camera.getUpX(),
          camera.getUpY(),
          camera.getUpZ());

      // cameraChanged = false;
    }

    square.draw(gl);
  }
Пример #4
0
 public void setMatrices(GL10 gl) {
   gl.glMatrixMode(GL10.GL_PROJECTION);
   gl.glLoadIdentity();
   GLU.gluPerspective(gl, fieldOfView, aspectRatio, near, far);
   gl.glMatrixMode(GL10.GL_MODELVIEW);
   gl.glLoadIdentity();
   GLU.gluLookAt(
       gl, position.x, position.y, position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
 }
Пример #5
0
  /**
   * Called when the surface is created, and before the first frame is called to be rendered.
   *
   * @param gl The GL10 instance that the game is using.
   * @param config The EGLConfig that we could use if we wanted.
   */
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    // Set the look at point.
    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Set up the GL state.
    PerlinTerrainMenu.setupGLState(gl);
  }
Пример #6
0
  /** Some initialization of the OpenGL stuff (that I don't understand...) */
  protected void init() {
    // Much of this code is from GLSurfaceView in the Google API Demos.
    // I encourage those interested to look there for documentation.
    egl = (EGL10) EGLContext.getEGL();
    dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(dpy, version);

    int[] configSpec = {
      EGL10.EGL_RED_SIZE, 5,
      EGL10.EGL_GREEN_SIZE, 6,
      EGL10.EGL_BLUE_SIZE, 5,
      EGL10.EGL_DEPTH_SIZE, 8,
      EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
    EGLConfig config = configs[0];

    eglContext = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);

    surface = egl.eglCreateWindowSurface(dpy, config, sHolder, null);
    egl.eglMakeCurrent(dpy, surface, surface, eglContext);

    gl = (GL10) eglContext.getGL();

    // Load the buffer and stuff
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepthf(1.0f);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    // Resize... whatever?
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, width, height);
    GLU.gluPerspective(gl, 45.0f, ((float) width) / height, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5.5f, 0, 0, 0, 0, 1, 0);
    gl.glNormal3f(0, 0, 1);
  }
Пример #7
0
    public void onDrawFrame(GL10 gl) {
      checkGLError(gl);
      if (mContextSupportsCubeMap) {
        gl.glClearColor(0, 0, 1, 0);
      } else {
        // Current context doesn't support cube maps.
        // Indicate this by drawing a red background.
        gl.glClearColor(1, 0, 0, 0);
      }
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      gl.glEnable(GL10.GL_DEPTH_TEST);
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
      gl.glRotatef(mAngle, 0, 1, 0);
      gl.glRotatef(mAngle * 0.25f, 1, 0, 0);

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

      checkGLError(gl);

      if (mContextSupportsCubeMap) {
        gl.glActiveTexture(GL10.GL_TEXTURE0);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP);
        checkGLError(gl);
        gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, mCubeMapTextureID);
        checkGLError(gl);
        GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
        gl11ep.glTexGeni(
            GL11ExtensionPack.GL_TEXTURE_GEN_STR,
            GL11ExtensionPack.GL_TEXTURE_GEN_MODE,
            GL11ExtensionPack.GL_REFLECTION_MAP);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
        checkGLError(gl);
        gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
      }

      checkGLError(gl);
      mGrid.draw(gl);

      if (mContextSupportsCubeMap) {
        gl.glDisable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
      }
      checkGLError(gl);

      mAngle += 1.2f;
    }
Пример #8
0
  /**
   * Called when the GLSurfaceView changes shape or size.
   *
   * @param gl The GL10 instance that the game is using.
   * @param width The new width of the GLSurfaceView.
   * @param height The new height of the GLSurfaceView.
   */
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {

    // Set GL_MODELVIEW transformation mode
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity(); // reset the matrix to its default state

    // When using GL_MODELVIEW, you must set the view point
    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 1000.0f);
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Пример #9
0
  protected void drawSetup() {
    // View frustrum

    if (_scene.camera().frustum.isDirty()) {
      updateViewFrustrum();
    }

    // Camera

    _gl.glMatrixMode(GL10.GL_MODELVIEW);
    _gl.glLoadIdentity();

    GLU.gluLookAt(
        _gl,
        _scene.camera().position.x,
        _scene.camera().position.y,
        _scene.camera().position.z,
        _scene.camera().target.x,
        _scene.camera().target.y,
        _scene.camera().target.z,
        _scene.camera().upAxis.x,
        _scene.camera().upAxis.y,
        _scene.camera().upAxis.z);

    // Background color

    if (_scene.backgroundColor().isDirty()) {
      if (_scene.backgroundTransparent() == true) _gl.glClearColor(0, 0, 0, 0);
      else
        _gl.glClearColor(
            (float) _scene.backgroundColor().r() / 255f,
            (float) _scene.backgroundColor().g() / 255f,
            (float) _scene.backgroundColor().b() / 255f,
            (float) _scene.backgroundColor().a() / 255f);
      _scene.backgroundColor().clearDirtyFlag();
    }

    _gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    drawSetupLights();

    // Always on:
    _gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  }
Пример #10
0
    public void run() {
      initEGL();
      initGL();

      CubeSmallGLUT cube = new CubeSmallGLUT(3);
      mGL.glMatrixMode(GL10.GL_MODELVIEW);
      mGL.glLoadIdentity();
      GLU.gluLookAt(mGL, 0, 0, 8f, 0, 0, 0, 0, 1, 0f);
      while (!mDone) {
        mGL.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        mGL.glRotatef(1f, 1f, 1f, 1f);
        mGL.glColor4f(1f, 0f, 0f, 1f);

        cube.draw(mGL);

        mGL.glFlush();
        mEGL.eglSwapBuffers(mGLDisplay, mGLSurface);
      }
    }
  public void onDrawFrame(GL10 gl) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    glDisable(GL_DITHER);

    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*
     * Now we're ready to draw some 3D objects
     */

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, mTextureID);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);
  }
  @Override
  public void onDrawFrame(GL10 gl) {

    // gl color buffer and depth buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    // setting the camera
    GLU.gluLookAt(gl, 0, 0, -6, 0, 0, 0, 0, 2, 0);

    // draw the seat
    // toilet.drawSeat(gl);
    // then draw the inner white toilet
    toilet.draw(gl);

    // first draw water
    bubble.drawWater(gl);

    // draw bubble
    bubble.draw(gl);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    GL11 gl = (GL11) context.getGL();
    int w = getWidth();
    int h = getHeight();

    context.waitNative(canvas, this);

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, w, h);
    GLU.gluPerspective(gl, 45.0f, ((float) w) / h, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5, 0, 0, 0, 0, 1, 0);
    gl.glTranslatef(0, 0, -10);
    gl.glRotatef(30.0f, 1, 0, 0);
    // gl.glRotatef(40.0f, 0, 1, 0);

    gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertices[frame_ix]);
    gl.glNormalPointer(GL10.GL_FIXED, 0, normals);
    gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // gl.glColor4f(1,0,0,1);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
    // gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDrawElements(GL10.GL_TRIANGLES, verts, GL10.GL_UNSIGNED_SHORT, indices);

    frame_ix = (frame_ix + 1) % m.getFrameCount();
    context.waitGL();
  }
    private void drawOnscreen(GL10 gl, int width, int height) {
      gl.glViewport(0, 0, width, height);
      float ratio = (float) width / height;
      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);

      gl.glClearColor(0, 0, 1, 0);
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      gl.glBindTexture(GL10.GL_TEXTURE_2D, mTargetTexture);

      gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

      gl.glActiveTexture(GL10.GL_TEXTURE0);

      long time = SystemClock.uptimeMillis() % 4000L;
      float angle = 0.090f * ((int) time);

      gl.glRotatef(angle, 0, 0, 1.0f);

      mTriangle.draw(gl);

      // Restore default state so the other renderer is not affected.

      gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    }
Пример #15
0
  public void onDrawFrame(GL10 gl) {

    /** Calculate new position */
    if (!updatePosition(false)) {}

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    /*
     * Upon browsing category change we want to clear the screen
     * until the changes have been applied
     */
    if (mIsChangingCat) {
      //        	mIsChangingCat = false; // redundant
      //        	stopRender();
      return;
    }

    /*
     * Now we're ready to draw some 3D objects
     */
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    /*
     * Check if we are doing a click animation
     * 	- it changes the eye spot of the camera
     */
    if (mClickAnimation) {
      logisticFuncResult =
          (float)
              (2
                      * (1
                          / (1
                              + Math.pow(
                                  Math.E,
                                  -(float) this.mClickAnimationStep
                                      / (float) this.MAX_CLICK_ANIMATION_STEPS
                                      * 6)))
                  - 1);
      /* camera eye update */
      mEyeX = (float) (mEyeInitialX + (mEyeTargetX - mEyeInitialX) * logisticFuncResult);
      mEyeY = (float) (mEyeInitialY + (mEyeTargetY - mEyeInitialY) * logisticFuncResult);
      mEyeZ = (float) (mEyeInitialZ + (mEyeTargetZ - mEyeInitialZ) * logisticFuncResult);

      /* camera center update */
      mCenterX =
          (float) (mCenterInitialX + (mCenterTargetX - mCenterInitialX) * logisticFuncResult);
      mCenterY =
          (float) (mCenterInitialY + (mCenterTargetY - mCenterInitialY) * logisticFuncResult);
      mCenterZ =
          (float) (mCenterInitialZ + (mCenterTargetZ - mCenterInitialZ) * logisticFuncResult);

      //        	Log.i(TAG, "growth: "+ logisticFuncResult);

      //        	Log.i(TAG, "X: "+mEyeX+" - "+mEyeTargetX);
      //        	Log.i(TAG, "Y: "+mEyeY+" - "+mEyeTargetY);
      //        	Log.i(TAG, "Z: "+mEyeZ+" - "+mEyeTargetZ);

      if (this.mClickAnimationStep == this.MAX_CLICK_ANIMATION_STEPS) {
        mEyeX = mEyeTargetX;
        mEyeY = mEyeTargetY;
        mEyeZ = mEyeTargetZ;

        mCenterX = mCenterTargetX;
        mCenterY = mCenterTargetY;
        mCenterZ = mCenterTargetZ;

        mClickAnimation = false;
      } else {
        mClickAnimationStep++;
      }
    }
    //        else
    //        {
    //            /* move camera when scrolling cube in Y axis */
    //    	 	if(mTargetPositionY > mPositionY)
    //        	{
    //        		distanceToRotationLimits =
    //            			1.f *
    //            			Math.min(
    //            					mPositionY - mRotationInitialPositionY,
    //            					mTargetPositionY - mPositionY);
    //
    //                mCenterY = distanceToRotationLimits;
    //        	}
    //        	else if(mTargetPositionY < mPositionY)
    //        	{
    //        		distanceToRotationLimits =
    //        			1.f *
    //        			Math.min(
    //        					mRotationInitialPositionY - mPositionY,
    //        					mPositionY - mTargetPositionY);
    //
    //        		mCenterY = -distanceToRotationLimits;
    //        	}
    //        	else
    //        	{
    //        		mCenterY = 0;
    //        	}
    ////	            // adjust the fog
    ////	            gl.glFogf(
    ////	            		GL10.GL_FOG_START,
    ////	            		3.5f + .5f * distanceToRotationLimits);
    ////	            gl.glFogf(
    ////	            		GL10.GL_FOG_END,
    ////	            		4.5f + distanceToRotationLimits);
    //        }

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    /* update textures if needed -- whenever we cross one album */
    try {
      texturesUpdated = updateTextures(gl);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      texturesUpdated = false;
      return;
    }
    /* set the fog distance */
    gl.glFogf(GL10.GL_FOG_START, -mEyeZ - 1.f);
    gl.glFogf(GL10.GL_FOG_END, -mEyeZ + 11.f);
    //        gl.glDisable(GL10.GL_FOG);

    positionYTmp = mPositionY;
    flooredPositionYTmp = flooredPositionY;
    /* draw each cover */
    for (int i = 0; i < mCacheSize; i++) {
      gl.glLoadIdentity();
      GLU.gluLookAt(gl, mEyeX, mEyeY, mEyeZ, mCenterX, mCenterY, mCenterZ, 0f, -1.0f, 0.0f);

      // poor variable name -- dont mind it
      deltaToCenter = mNavItem[i].index - flooredPositionYTmp * 2;
      // make it all positive
      deltaToCenter += mCacheSize / 2 - 1; // (-4) negative numbers go bad with integer divisions

      // optimizations, optimizations
      //        	if(deltaToCenter < 0 || deltaToCenter > 11)
      //        		continue;

      /* place the covers */
      gl.glTranslatef(
          -1.f
              + i % 2
                  * 2.f, // we just dont need to use delta center here because the navigator always
                         // moves by 2 positions (1 row)
          -4.f + deltaToCenter / 2 * 2.f,
          0);
      gl.glTranslatef(0, -(positionYTmp - flooredPositionYTmp) * 2.f, 0);

      mRockOnCover.setTextureId(mTextureId[i]);
      mRockOnCover.draw(gl);
    }

    if (mTargetPositionY == mPositionY && !mClickAnimation && !texturesUpdated) {
      //        	Log.i(TAG, "positions are not final!");
      //        	Log.i(TAG, "mTargetPositionY: "+mTargetPositionY+" mPositionY: "+mPositionY);
      //        	Log.i(TAG, "mTargetPositionX: "+mTargetPositionX+" mPositionX: "+mPositionX);
      //        	Log.i(TAG, "mClickAnimation: "+mClickAnimation);
      //        	Log.i(TAG, "texturesUpdated: "+texturesUpdated);
      stopRender();
    }
  }
  public void onDrawFrame(GL10 gl) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    /*
     * Now we're ready to draw some 3D objects
     */

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0.0f, 0.0f, -2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glActiveTexture(GL10.GL_TEXTURE0);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

    if (false) {
      long time = SystemClock.uptimeMillis();
      if (mLastTime != 0) {
        long delta = time - mLastTime;
        Log.w("time", Long.toString(delta));
      }
      mLastTime = time;
    }

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    gl.glRotatef(angle, 0, 0, 1.0f);
    gl.glScalef(2.0f, 2.0f, 2.0f);

    mTriangle.draw(gl);

    mProjector.getCurrentModelView(gl);
    mLabels.beginDrawing(gl, mWidth, mHeight);
    drawLabel(gl, 0, mLabelA);
    drawLabel(gl, 1, mLabelB);
    drawLabel(gl, 2, mLabelC);
    float msPFX = mWidth - mLabels.getWidth(mLabelMsPF) - 1;
    mLabels.draw(gl, msPFX, 0, mLabelMsPF);
    mLabels.endDrawing(gl);

    drawMsPF(gl, msPFX);
  }
    @Override
    public void onDrawFrame(GL10 gl) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      GL11 gl11 = (GL11) gl;

      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();

      // perspective
      GLU.gluPerspective(gl11, 45, aspect, 0.01f, 100f);
      GLU.gluLookAt(
          gl,
          (float) (Math.cos(angle) * eyeDistance),
          0,
          (float) (Math.sin(angle) * eyeDistance),
          0,
          0,
          0.0f,
          0.0f,
          1.0f,
          0.0f);

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      // set render status
      gl.glEnable(GL10.GL_TEXTURE_2D);
      gl.glEnable(GL10.GL_ALPHA_TEST);
      gl.glAlphaFunc(GL10.GL_EQUAL, 1.0f);
      // gl.glColor4f(1, 1, 1, 1);

      // bind
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
      vbo.bind(gl11);

      // left
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(-1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // right
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(1, 0, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // up
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, -1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // down
      gl11.glPushMatrix();
      {
        gl11.glTranslatef(0, 1, 0);
        ibo.draw(gl11);
      }
      gl11.glPopMatrix();

      // unbind
      vbo.unbind(gl11);
      gl.glDisable(GL10.GL_TEXTURE_2D);

      angle += (float) (1f / 180f * Math.PI);
    }
Пример #18
0
  @Override
  public void onDrawFrame(GL10 gl) {
    try {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      if (positionBuffer != null) {
        gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, positionBuffer);
      }

      synchronized (camera) {
        PointF c = getCameraLocation();
        if (c == camera) {
          GLU.gluLookAt(gl, c.x, c.y, zoom, camera.x, camera.y, 0.0f, 0.0f, 1.0f, 0.0f);
        } else {
          GLU.gluLookAt(
              gl,
              c.x,
              c.y,
              zoom / followHeightFactor,
              camera.x,
              camera.y,
              -FOLLOW_LOOK_AT_HEIGHT,
              0.0f,
              0.0f,
              -1.0f);
        }
      }

      synchronized (areas) {
        for (SimArea area : areas.values()) {
          if (!onlySeenAreas || seenAreas.contains(area.getID())) {
            area.draw(gl);
          }
        }
      }

      if (drawWalls) {
        synchronized (walls) {
          for (SimWall wall : walls) {
            wall.draw(gl);
          }
        }

        synchronized (wallTops) {
          for (SimWallTop wallTop : wallTops) {
            wallTop.draw(gl);
          }
        }
      }

      synchronized (objects) {
        for (SimObject obj : objects.values()) {
          obj.draw(gl);
        }
      }

      synchronized (robots) {
        for (SimRobot robot : robots.values()) {
          robot.draw(gl, drawRedLidar, drawBlueLidar, drawYellowWaypoint);
        }
      }

      synchronized (lastFloorTouch) {
        GLUtil.drawRect(
            gl,
            lastFloorTouch.x - 0.05f,
            lastFloorTouch.y - 0.25f,
            -0.01f,
            0.1f,
            0.5f,
            GLUtil.GRAY);
        GLUtil.drawRect(
            gl,
            lastFloorTouch.x - 0.25f,
            lastFloorTouch.y - 0.05f,
            -0.01f,
            0.5f,
            0.1f,
            GLUtil.GRAY);
      }

    } catch (ConcurrentModificationException e) {
      e.printStackTrace();
    }
  }
Пример #19
0
  public void onDrawFrame(GL10 gl) {
    // Initialize from model
    init(mMainPane.model, gl);
    if (nbPts == 0) return;

    // Textures
    gl.glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glFrontFace(GL10.GL_CCW);

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glPushMatrix();
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 900f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Background always textured
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexturesBuffer[2]);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mBackgroundTexBuffer);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mBackgroundVertexBuffer);
    gl.glNormalPointer(GL10.GL_FLOAT, 0, mBackgroundNormals);
    gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, mBackgroundIndexBuffer);

    // Handle finger rotate on the object
    gl.glRotatef(mAngleX, 0, 1, 0); // Yes there is an inversion between X and Y
    gl.glRotatef(mAngleY, 1, 0, 0);
    // Handle finger zoom, move rotate on
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glPushMatrix();
    gl.glRotatef(mAngleZ, 0, 0, 1);
    gl.glTranslatef(mdx, mdy, mdz);
    // Back to Modelview
    gl.glMatrixMode(GL10.GL_MODELVIEW);

    // Front face
    if (texturesON) {
      gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexturesBuffer[0]);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBufferFront);
    } else {
      gl.glDisable(GL10.GL_LIGHTING);
      gl.glDisable(GL10.GL_TEXTURE_2D);
      gl.glColor4f(145.0f / 255.0f, 199.0f / 255.0f, 1.0f, 1.0f); // rgba => blue
    }
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
    gl.glNormalPointer(GL10.GL_FLOAT, 0, mFNormalsFront);
    gl.glDrawElements(GL10.GL_TRIANGLES, nbPts, GL10.GL_UNSIGNED_SHORT, mIndexBufferFront);

    // Back face
    if (texturesON) {
      gl.glBindTexture(GL10.GL_TEXTURE_2D, mTexturesBuffer[1]);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBufferBack);
    } else {
      gl.glColor4f(1.0f, 249.0f / 255.0f, 145.0f / 255.0f, 1.0f); // rgba => yellow
    }
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
    gl.glNormalPointer(GL10.GL_FLOAT, 0, mFNormalsBack);
    gl.glDrawElements(GL10.GL_TRIANGLES, nbPts, GL10.GL_UNSIGNED_SHORT, mIndexBufferBack);

    // Lines - a mess to get black lines => no texture no light
    gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f); // rgba => black
    gl.glDisable(GL10.GL_TEXTURE_2D);
    gl.glDisable(GL10.GL_LIGHTING);
    gl.glLineWidth(3.0f);
    gl.glClear(GL10.GL_DEPTH_BUFFER_BIT); // See through faces
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
    gl.glDrawElements(GL10.GL_LINES, nbPtsLines, GL10.GL_UNSIGNED_SHORT, mIndexBufferLines);

    if (animated == true) {
      animated = commands.anim();
      requestRender();
    }
  }