Inheritance: java.lang.Object
コード例 #1
0
 public void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
     // preparation
     gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
     gl.glEnableClientState(GL10_GL_COLOR_ARRAY);
     initTriangle();
 }
コード例 #2
0
            public void onSurfaceCreated(GL10 glUnused, javax.microedition.khronos.egl.EGLConfig config)
            {
                // and now we still need redux?

                // Set the background clear color to gray.
                gl.clearColor(0.5f, 0.5f, 0.5f, 0.5f);

                // Position the eye behind the origin.
                const float eyeX = 0.0f;
                const float eyeY = 0.0f;
                const float eyeZ = 1.5f;

                // We are looking toward the distance
                const float lookX = 0.0f;
                const float lookY = 0.0f;
                const float lookZ = -5.0f;

                // Set our up vector. This is where our head would be pointing were we holding the camera.
                const float upX = 0.0f;
                const float upY = 1.0f;
                const float upZ = 0.0f;

                // Set the view matrix. This matrix can be said to represent the camera position.
                // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
                // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
                Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);



                // Create a program object and store the handle to it.


                var programHandle = gl.createProgram(
                    new Shaders.TriangleVertexShader(),
                    new Shaders.TriangleFragmentShader()
                    );

                gl.bindAttribLocation(programHandle, 0, "a_Position");
                gl.bindAttribLocation(programHandle, 1, "a_Color");

                gl.linkProgram(programHandle);

                // Set program handles. These will later be used to pass in values to the program.
                mMVPMatrixHandle = gl.getUniformLocation(programHandle, "u_MVPMatrix");
                mPositionHandle  = gl.getAttribLocation(programHandle, "a_Position");
                mColorHandle     = gl.getAttribLocation(programHandle, "a_Color");

                // Tell OpenGL to use this program when rendering.
                gl.useProgram(programHandle);
            }
コード例 #3
0
            public void onSurfaceCreated(GL10 gl, EGLConfig config)
            {
                gl.glMatrixMode(GL10_GL_PROJECTION);
                float size = .01f * (float)java.lang.Math.tan(java.lang.Math.toRadians(45.0) / 2);
                float ratio = _width / _height;
                // perspective:
                gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
                // orthographic:
                //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
                gl.glViewport(0, 0, (int)_width, (int)_height);
                gl.glMatrixMode(GL10_GL_MODELVIEW);
                gl.glEnable(GL10_GL_DEPTH_TEST);

                // define the color we want to be displayed as the "clipping wall"
                gl.glClearColor(0f, 0f, 0f, 1.0f);

                // enable the differentiation of which side may be visible 
                gl.glEnable(GL10_GL_CULL_FACE);
                // which is the front? the one which is drawn counter clockwise
                gl.glFrontFace(GL10_GL_CCW);
                // which one should NOT be drawn
                gl.glCullFace(GL10_GL_BACK);

                gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
                gl.glEnableClientState(GL10_GL_COLOR_ARRAY);

                initTriangle();
            }
コード例 #4
0
        // all setup and data loading goes here
        public void onSurfaceCreated(GL10 arg0, EGLConfig arg1)
        {
            var shaderProgram = gl.createProgram();


            var vs = gl.createShader( new Shaders.GeometryVertexShader() );
            var fs = gl.createShader(  new Shaders.GeometryVertexShader() );


            gl.attachShader(shaderProgram, vs);
            gl.attachShader(shaderProgram, fs);


            gl.linkProgram(shaderProgram);

            
            gl.useProgram(shaderProgram);
            positionAttribLocation = gl.getAttribLocation(shaderProgram, "position");

            // setup geometry
            float[] verticesData = 
            { 
                0.0f, 0.5f, 0.0f, 
                -0.5f, -0.5f, 0.0f, 
                0.5f,  -0.5f, 0.0f 
            };

            vertices = ByteBuffer
                    .allocateDirect(verticesData.Length * 4)
                    .order(ByteOrder.nativeOrder()).asFloatBuffer();
            vertices.put(verticesData).position(0);
        }
コード例 #5
0
 public void onSurfaceCreated(GL10 gl, javax.microedition.khronos.egl.EGLConfig config)
 {
     Console.WriteLine("HybridGLES3JNIActivity onSurfaceCreated, init");
     GLES3JNILib.init();
 }
コード例 #6
0
        public void onSurfaceCreated(javax.microedition.khronos.egl.EGLConfig value)
        {
            Console.WriteLine("onSurfaceCreated");

            GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f);             // Dark background so text shows up well.

            ByteBuffer bbVertices = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COORDS.Length * 4);

            bbVertices.order(ByteOrder.nativeOrder());
            cubeVertices = bbVertices.asFloatBuffer();
            cubeVertices.put(WorldLayoutData.CUBE_COORDS);
            cubeVertices.position(0);

            ByteBuffer bbColors = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COLORS.Length * 4);

            bbColors.order(ByteOrder.nativeOrder());
            cubeColors = bbColors.asFloatBuffer();
            cubeColors.put(WorldLayoutData.CUBE_COLORS);
            cubeColors.position(0);

            ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(
                WorldLayoutData.CUBE_FOUND_COLORS.Length * 4);

            bbFoundColors.order(ByteOrder.nativeOrder());
            cubeFoundColors = bbFoundColors.asFloatBuffer();
            cubeFoundColors.put(WorldLayoutData.CUBE_FOUND_COLORS);
            cubeFoundColors.position(0);

            ByteBuffer bbNormals = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_NORMALS.Length * 4);

            bbNormals.order(ByteOrder.nativeOrder());
            cubeNormals = bbNormals.asFloatBuffer();
            cubeNormals.put(WorldLayoutData.CUBE_NORMALS);
            cubeNormals.position(0);

            // make a floor
            ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COORDS.Length * 4);

            bbFloorVertices.order(ByteOrder.nativeOrder());
            floorVertices = bbFloorVertices.asFloatBuffer();
            floorVertices.put(WorldLayoutData.FLOOR_COORDS);
            floorVertices.position(0);

            ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_NORMALS.Length * 4);

            bbFloorNormals.order(ByteOrder.nativeOrder());
            floorNormals = bbFloorNormals.asFloatBuffer();
            floorNormals.put(WorldLayoutData.FLOOR_NORMALS);
            floorNormals.position(0);

            ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.Length * 4);

            bbFloorColors.order(ByteOrder.nativeOrder());
            floorColors = bbFloorColors.asFloatBuffer();
            floorColors.put(WorldLayoutData.FLOOR_COLORS);
            floorColors.position(0);



            Func <int, string, int> loadGLShader = (int type, string code) =>
            {
                int shader = GLES20.glCreateShader(type);
                GLES20.glShaderSource(shader, code);
                GLES20.glCompileShader(shader);

                // Get the compilation status.
                int[] compileStatus = new int[1];
                GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

                // If the compilation failed, delete the shader.
                if (compileStatus[0] == 0)
                {
                    Console.WriteLine("Error compiling shader: " + GLES20.glGetShaderInfoLog(shader));
                    GLES20.glDeleteShader(shader);
                    shader = 0;
                }

                if (shader == 0)
                {
                    throw new Exception("Error creating shader.");
                }

                return(shader);
            };


            int vertexShader      = loadGLShader(GLES20.GL_VERTEX_SHADER, new Shaders.light_vertexVertexShader().ToString());
            int gridShader        = loadGLShader(GLES20.GL_FRAGMENT_SHADER, new Shaders.grid_fragmentFragmentShader().ToString());
            int passthroughShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, new Shaders.passthrough_fragmentFragmentShader().ToString());

            cubeProgram = GLES20.glCreateProgram();
            GLES20.glAttachShader(cubeProgram, vertexShader);
            GLES20.glAttachShader(cubeProgram, passthroughShader);
            GLES20.glLinkProgram(cubeProgram);
            GLES20.glUseProgram(cubeProgram);

            checkGLError("Cube program");

            cubePositionParam = GLES20.glGetAttribLocation(cubeProgram, "a_Position");
            cubeNormalParam   = GLES20.glGetAttribLocation(cubeProgram, "a_Normal");
            cubeColorParam    = GLES20.glGetAttribLocation(cubeProgram, "a_Color");

            cubeModelParam               = GLES20.glGetUniformLocation(cubeProgram, "u_Model");
            cubeModelViewParam           = GLES20.glGetUniformLocation(cubeProgram, "u_MVMatrix");
            cubeModelViewProjectionParam = GLES20.glGetUniformLocation(cubeProgram, "u_MVP");
            cubeLightPosParam            = GLES20.glGetUniformLocation(cubeProgram, "u_LightPos");

            GLES20.glEnableVertexAttribArray(cubePositionParam);
            GLES20.glEnableVertexAttribArray(cubeNormalParam);
            GLES20.glEnableVertexAttribArray(cubeColorParam);

            checkGLError("Cube program params");

            floorProgram = GLES20.glCreateProgram();
            GLES20.glAttachShader(floorProgram, vertexShader);
            GLES20.glAttachShader(floorProgram, gridShader);
            GLES20.glLinkProgram(floorProgram);
            GLES20.glUseProgram(floorProgram);

            checkGLError("Floor program");

            floorModelParam               = GLES20.glGetUniformLocation(floorProgram, "u_Model");
            floorModelViewParam           = GLES20.glGetUniformLocation(floorProgram, "u_MVMatrix");
            floorModelViewProjectionParam = GLES20.glGetUniformLocation(floorProgram, "u_MVP");
            floorLightPosParam            = GLES20.glGetUniformLocation(floorProgram, "u_LightPos");

            floorPositionParam = GLES20.glGetAttribLocation(floorProgram, "a_Position");
            floorNormalParam   = GLES20.glGetAttribLocation(floorProgram, "a_Normal");
            floorColorParam    = GLES20.glGetAttribLocation(floorProgram, "a_Color");

            GLES20.glEnableVertexAttribArray(floorPositionParam);
            GLES20.glEnableVertexAttribArray(floorNormalParam);
            GLES20.glEnableVertexAttribArray(floorColorParam);

            checkGLError("Floor program params");

            GLES20.glEnable(GLES20.GL_DEPTH_TEST);

            // Object first appears directly in front of user.
            Matrix.setIdentityM(modelCube, 0);
            Matrix.translateM(modelCube, 0, 0, 0, -objectDistance);

            Matrix.setIdentityM(modelFloor, 0);
            Matrix.translateM(modelFloor, 0, 0, -floorDepth, 0);             // Floor appears below user.

            checkGLError("onSurfaceCreated");
        }
コード例 #7
0
            public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
            {
                // Set the background clear color to black.
                gl.clearColor(1.0f, 1.0f, 1.0f, 0.0f);

                // Use culling to remove back faces.
                opengl.glEnable(opengl.GL_CULL_FACE);

                // Enable depth testing
                opengl.glEnable(opengl.GL_DEPTH_TEST);

                // Enable texture mapping
                opengl.glEnable(opengl.GL_TEXTURE_2D);

                // Position the eye in front of the origin.
                float eyeX = 0.0f;
                float eyeY = 0.0f;
                float eyeZ = -0.5f;

                // We are looking toward the distance
                float lookX = 0.0f;
                float lookY = 0.0f;
                float lookZ = -5.0f;

                // Set our up vector. This is where our head would be pointing were we holding the camera.
                float upX = 0.0f;
                float upY = 1.0f;
                float upZ = 0.0f;

                // Set the view matrix. This matrix can be said to represent the camera position.
                // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
                // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
                Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);


                mProgramHandle = gl.createAndLinkProgram(
                    new Shaders.per_pixelVertexShader(),
                    new Shaders.per_pixelFragmentShader(),
                    "a_Position",
                    "a_Color",
                    "a_Normal",
                    "a_TexCoordinate"
                );

                // Define a simple shader program for our point.


                mPointProgramHandle = gl.createAndLinkProgram(
                    new Shaders.per_pixelVertexShader(),
                    new Shaders.per_pixelFragmentShader(),
                      "a_Position"
                );

                // Load the texture
                mTextureDataHandle = TextureHelper.loadTexture(mActivityContext, R.drawable.jsc_24bit);
                mTextureDataHandle2 = TextureHelper.loadTexture(mActivityContext, R.drawable.jsc_black);
            }
コード例 #8
0
 public  void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
     // Do nothing special.
 }
コード例 #9
0
            public void onSurfaceCreated(GL10 gl, EGLConfig config)
            {
                // preparation
                // enable the differentiation of which side may be visible 
                gl.glEnable(GL10_GL_CULL_FACE);
                // which is the front? the one which is drawn counter clockwise
                gl.glFrontFace(GL10_GL_CCW);
                // which one should NOT be drawn
                gl.glCullFace(GL10_GL_BACK);

                gl.glEnableClientState(GL10_GL_VERTEX_ARRAY);
                gl.glEnableClientState(GL10_GL_COLOR_ARRAY);

                initTriangle();
            }
コード例 #10
0
            public void onSurfaceCreated(GL10 unused, EGLConfig config)
            {
                // Set the background frame color
                gl.clearColor(0.5f, 0.5f, 0.5f, 1.0f);

                // initialize the triangle vertex array
                initShapes();

                mProgram = gl.createProgram();

                var vs = gl.createShader(new Shaders.TriangleVertexShader());
                var fs = gl.createShader(new Shaders.TriangleFragmentShader());

                gl.attachShader(mProgram, vs);
                gl.attachShader(mProgram, fs);

                gl.deleteShader(vs);
                gl.deleteShader(fs);



                gl.linkProgram(mProgram);
           
                // get handle to the vertex shader's vPosition member
                maPositionHandle = gl.getAttribLocation(mProgram, "vPosition");
            }