/** * Returns a copy of the specified buffer, with the specified new size. The new size must be greater than or equal * to the specified buffer's size. If the new size is greater than the specified buffer's size, this returns a new * buffer which is partially filled with the contents of the specified buffer. The returned buffer is a backed by a * direct ByteBuffer if and only if the specified buffer is direct. * * @param buffer the buffer to copy. * @param newSize the new buffer's size, in floats. * * @return the new buffer, with the specified size. * * @throws ArgumentException if the buffer is null, if the new size is negative, or if the new size is less * than the buffer's remaing elements. */ public static FloatBuffer copyOf(FloatBuffer buffer, int newSize) { if (newSize < 0 || newSize < buffer.remaining()) { String message = Logging.getMessage("generic.SizeOutOfRange", newSize); Logging.logger().severe(message); throw new ArgumentException(message); } FloatBuffer newBuffer = newFloatBuffer(newSize, buffer.isDirect()); int pos = buffer.position(); // Save the input buffer's current position. try { newBuffer.put(buffer); newBuffer.rewind(); } finally { buffer.position(pos); // Restore the input buffer's original position. } return(newBuffer); }
public MyRenderer(BasicCustomVideoRenderer parent) { this.mCustomVideoRenderer = parent; ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0f, 0.5f, 0f // (x3, y3, z3) }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _vertexBuffer.position(0); _indexBuffer.position(0); }
private void initTriangle() { float[] coords = { -0.5f, -0.5f, 0.5f, // 0 0.5f, -0.5f, 0.5f, // 1 0f, -0.5f, -0.5f, // 2 0f, 0.5f, 0f, // 3 }; _nrOfVertices = coords.Length; float[] colors = { 1f, 0f, 0f, 1f, // point 0 red 0f, 1f, 0f, 1f, // point 1 green 0f, 0f, 1f, 1f, // point 2 blue 1f, 1f, 1f, 1f, // point 3 white }; short[] indices = new short[] { 0, 1, 3, // rwg 0, 2, 1, // rbg 0, 3, 2, // rbw 1, 2, 3, // bwg }; // float has 4 bytes, coordinate * 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(coords.Length * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes, indices * 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(indices.Length * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, colors (RGBA) * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(colors.Length * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); _vertexBuffer.put(coords); _indexBuffer.put(indices); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
/** * Draws a cube. */ private void drawCube() { // Pass in the position information mCubePositions.position(0); opengl.glVertexAttribPointer(mPositionHandle, mPositionDataSize, opengl.GL_FLOAT, false, 0, mCubePositions); opengl.glEnableVertexAttribArray(mPositionHandle); // Pass in the color information mCubeColors.position(0); opengl.glVertexAttribPointer(mColorHandle, mColorDataSize, opengl.GL_FLOAT, false, 0, mCubeColors); opengl.glEnableVertexAttribArray(mColorHandle); // Pass in the normal information mCubeNormals.position(0); opengl.glVertexAttribPointer(mNormalHandle, mNormalDataSize, opengl.GL_FLOAT, false, 0, mCubeNormals); opengl.glEnableVertexAttribArray(mNormalHandle); // Pass in the texture coordinate information mCubeTextureCoordinates.position(0); opengl.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, opengl.GL_FLOAT, false, 0, mCubeTextureCoordinates); opengl.glEnableVertexAttribArray(mTextureCoordinateHandle); // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix // (which currently contains model * view). Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); // Pass in the modelview matrix. gl.uniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0); // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix // (which now contains model * view * projection). Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); // Pass in the combined matrix. gl.uniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); // Pass in the light position in eye space. gl.uniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]); // Draw the cube. gl.drawArrays(opengl.GL_TRIANGLES, 0, 36); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 4 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, 4 colors (RGBA) * number of vertices * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(4 * _nrOfVertices * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0.5f, 0.5f, 0f // (x3, y3, z3) }; float[] colors = { 1f, 0f, 0f, 1f, // point 1 0f, 1f, 0f, 1f, // point 2 0f, 0f, 1f, 1f, // point 3 }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
public MyRenderer() { ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
/** * Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices. * * @param indices the triangle indices. * @param inBuf the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ... * @param outBuf the buffer in which to place the expanded triangle vertices. The buffer must have a limit * sufficient to hold the output vertices. * * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer * size is insufficient. */ public static void expandTriangleFan(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf) { if (indices == null) { string msg = Logging.getMessage("nullValue.ListIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (inBuf == null || outBuf == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } int nunTriangles = indices.Count - 2; if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position()) { string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position()); Logging.logger().severe(msg); throw new ArgumentException(msg); } int k = indices[0] * 3; float v0x = inBuf.get(k); float v0y = inBuf.get(k + 1); float v0z = inBuf.get(k + 2); for (int i = 1; i < indices.Count - 1; i++) { outBuf.put(v0x).put(v0y).put(v0z); k = indices[i] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i + 1] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); } }
public static FloatBuffer getDirectBuffer(int size, FloatBuffer buffer) { if (buffer == null) { return(buffer); } size = Round4(size); if (buffer.Direct) { buffer.limit((size >> 2) + buffer.position()); return(buffer); } FloatBuffer directBuffer = allocateDirectBuffer(size).asFloatBuffer(); directBuffer.put((FloatBuffer)((FloatBuffer)buffer).slice().limit(size >> 2)); directBuffer.rewind(); return(directBuffer); }
/** * Compute the intersections of a line with a collection of triangles. * * @param line the line to intersect. * @param vertices the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle). * * @return the list of intersections with the line and the triangles, or null if there are no intersections. * * @throws ArgumentException if the line or vertex buffer is null. */ public static List <Intersection> intersectTriangles(Line line, FloatBuffer vertices) { if (line == null) { string msg = Logging.getMessage("nullValue.LineIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (vertices == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } List <Intersection> intersections = null; vertices.rewind(); while (vertices.limit() - vertices.position() >= 9) { Intersection intersection = intersect(line, vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get()); if (intersection != null) { if (intersections == null) { intersections = new List <Intersection>(); } intersections.Add(intersection); } } return(intersections); }
/** * Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices. * * @param indices the triangle indices. * @param inBuf the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ... * @param outBuf the buffer in which to place the expanded triangle vertices. The buffer must have a limit * sufficient to hold the output vertices. * * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer * size is insufficient. */ public static void expandTriangleStrip(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf) { if (indices == null) { string msg = Logging.getMessage("nullValue.ListIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (inBuf == null || outBuf == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } int nunTriangles = indices.Count - 2; if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position()) { string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position()); Logging.logger().severe(msg); throw new ArgumentException(msg); } for (int i = 2; i < indices.Count; i++) { int k = indices[i - 2] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i % 2 == 0 ? i : i - 1] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i % 2 == 0 ? i - 1 : i] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); } }
public void onSurfaceCreated(javax.microedition.khronos.egl.EGLConfig value) { Console.WriteLine("enter AndroidCardboardExperiment 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); var fcolors = 0xA26D41; // rgb to float //[javac] return __Enumerable.<Float>AsEnumerable(__SZArrayEnumerator_1.<Float>Of(x)); //[javac] ^ //[javac] required: T#1[] //[javac] found: float[] //[javac] reason: actual argument float[] cannot be converted to Float[] by method invocation conversion // var FLOOR_COLORS = ( // from i in Enumerable.Range(0, 6) // select new float[] { 0xA2 / 1.0f, 0x6D / 1.0f, 0x41 / 1.0f, 1.0f } //).SelectMany(x => x).ToArray(); #region floorColors var FLOOR_COLORS = new float[4 * 6]; for (int i = 0; i < FLOOR_COLORS.Length; i += 4) { FLOOR_COLORS[i + 0] = 0xA2 / 100.0f; FLOOR_COLORS[i + 1] = 0x6D / 100.0f; FLOOR_COLORS[i + 2] = 0x41 / 100.0f; FLOOR_COLORS[i + 3] = 1.0f; } FloatBuffer floorColors; ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.Length * 4); bbFloorColors.order(ByteOrder.nativeOrder()); floorColors = bbFloorColors.asFloatBuffer(); //floorColors.put(WorldLayoutData.FLOOR_COLORS); floorColors.put(FLOOR_COLORS); floorColors.position(0); #endregion #region loadGLShader Func <int, ScriptCoreLib.GLSL.Shader, int> loadGLShader = (type, xshader) => { var code = xshader.ToString(); 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); }; #endregion int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, new AndroidCardboardExperiment.Shaders.light_vertexVertexShader()); int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, new Shaders.xgrid_fragmentFragmentShader()); int passthroughShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, new AndroidCardboardExperiment.Shaders.passthrough_fragmentFragmentShader()); 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); //GLES20.glEnable(GLES20.GL_FOG); checkGLError("onSurfaceCreated"); Console.WriteLine("exit AndroidCardboardExperiment onSurfaceCreated"); vFinishFrame = (com.google.vrtoolkit.cardboard.Viewport v) => { // GPU thread stops now.. FrameOne.Stop(); }; // I/System.Console(28103): CardboardForEdgeExperiment { ProcessorCount = 8, MODEL = SM-G925F, CurrentManagedThreadId = 11305, FrameCounter = 28, LastFrameMilliseconds = 40, codeFPS = 25.0, pitch = 1.579644, yaw = 1.6225219 } #region vNewFrame vNewFrame = (com.google.vrtoolkit.cardboard.HeadTransform headTransform) => { // http://stackoverflow.com/questions/11851343/raise-fps-on-android-tablet-above-60-for-opengl-game // http://gafferongames.com/game-physics/fix-your-timestep/ #region FrameWatch if (FrameWatch.ElapsedMilliseconds >= 1000) { var codeFPS = 1000.0 / FrameOne.ElapsedMilliseconds; // we now know how many frames did fit into it // need 60 or more! Console.WriteLine("CardboardForEdgeExperiment " + new { // static System.Environment.ProcessorCount, android.os.Build.MODEL, System.Environment.CurrentManagedThreadId, FrameCounter, // dynamic LastFrameMilliseconds = FrameOne.ElapsedMilliseconds, codeFPS, // very dynamic pitch, yaw }); // I/System.Console(28117): CardboardForEdgeExperiment { ProcessorCount = 2, MODEL = Nexus 9, CurrentManagedThreadId = 1647, FrameCounter = 60, LastFrameMilliseconds = 6, codeFPS = 166.66666666666666, pitch = 1.5978987, yaw = -2.0770574 } FrameWatch.Restart(); FrameCounter = 0; } #endregion // GPU thread starts now.. FrameOne.Restart(); FrameCounter++; //Console.WriteLine("AndroidCardboardExperiment onNewFrame"); headTransform.getHeadView(headView, 0); checkGLError("onReadyToDraw"); // I/System.Console(27769): CardboardForEdgeExperiment { FrameCounter = 61, LastFrameMilliseconds = 0, codeFPS = Infinity, CurrentManagedThreadId = 1637, ProcessorCount = 2, MODEL = Nexus 9 } // add placeholder slowdown //System.Threading.Thread.Sleep(5); // I/System.Console(27840): CardboardForEdgeExperiment { FrameCounter = 60, LastFrameMilliseconds = 6, codeFPS = 166.66666666666666, CurrentManagedThreadId = 1642, ProcessorCount = 2, MODEL = Nexus 9 } }; #endregion // if we define it here, we get to see it in vr... var modelCube = new float[16]; // I/System.Console(19917): CardboardForEdgeExperiment { ProcessorCount = 8, MODEL = SM-G925F, CurrentManagedThreadId = 9959, FrameCounter = 46, LastFrameMilliseconds = 6, codeFPS = 166.66666666666666, pitch = 0.9070491, yaw = -0.3660261 } #region vDrawEye vDrawEye = (com.google.vrtoolkit.cardboard.Eye eye) => { // VIDEO via "X:\util\android-sdk-windows\tools\ddms.bat" var camera = new float[16]; // static void setLookAtM(float[] rm, int rmOffset, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) // Build the camera matrix and apply it to the ModelView. Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); #region glClearColor // skybox/video instead? GLES20.glClearColor( 0x87 / 255f, 0xCE / 255f, 0xEB / 255f, 1.0f ); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); #endregion var view = new float[16]; // can we strafe? // Apply the eye transformation to the camera. Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0); // we tapped into it. this strafes ius! Matrix.translateM(view, 0, (float)Math.Sin(TotalTime.ElapsedMilliseconds * 0.0001f) * objectDistance * 2.5f, // up down //(float)Math.Sin(TotalTime.ElapsedMilliseconds * 0.001f) * floorDepth * 0.5f, (float)Math.Cos(TotalTime.ElapsedMilliseconds * 0.001f) * floorDepth * 0.1f, 0 ); // Set the position of the light Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, LIGHT_POS_IN_WORLD_SPACE, 0); // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR); // just a buffer? var modelView = new float[16]; #region drawCube() Action <float, float, float> drawCube = (tx, ty, tz) => { #region isLookingAtObject Func <bool> isLookingAtObject = () => { float[] initVec = { 0, 0, 0, 1.0f }; float[] objPositionVec = new float[4]; // Convert object space to camera space. Use the headView from onNewFrame. Matrix.multiplyMM(modelView, 0, headView, 0, modelCube, 0); Matrix.multiplyMV(objPositionVec, 0, modelView, 0, initVec, 0); pitch = (float)Math.Atan2(objPositionVec[1], -objPositionVec[2]); yaw = (float)Math.Atan2(objPositionVec[0], -objPositionVec[2]); if (Math.Abs(pitch) < PITCH_LIMIT) { if (Math.Abs(yaw) < YAW_LIMIT) { return(true); } } return(false); }; #endregion // Object first appears directly in front of user. Matrix.setIdentityM(modelCube, 0); // cant see it? var scale = 5.0f; //Matrix.scaleM(modelCube, 0, scale, scale, scale); Matrix.translateM(modelCube, 0, tx, ty, tz); Matrix.multiplyMM(modelView, 0, view, 0, modelCube, 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); // public static void scaleM (float[] m, int mOffset, float x, float y, float z) // Build the Model part of the ModelView matrix. //Matrix.rotateM(modelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f); // cant see rotation? Matrix.rotateM(modelCube, 0, TotalTime.ElapsedMilliseconds * 0.01f, // upwards rot. //0.5f, 0f, // sideways, left to right 0.5f , 0.0f); // http://developer.android.com/reference/android/opengl/Matrix.html#translateM(float[], int, float, float, float) // the cube rotates in front of us. // do we need to use a special program to draw a cube? // how can we make it bigger? GLES20.glUseProgram(cubeProgram); GLES20.glUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0); // Set the Model in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(cubeModelParam, 1, false, modelCube, 0); // Set the ModelView in the shader, used to calculate lighting GLES20.glUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0); // Set the position of the cube GLES20.glVertexAttribPointer(cubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, cubeVertices); // Set the ModelViewProjection matrix in the shader. GLES20.glUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0); // Set the normal positions of the cube, again for shading GLES20.glVertexAttribPointer(cubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, cubeNormals); #region cubeColors var cc = cubeColors; if (!isLookingAtObject()) { cc = cubeFoundColors; } GLES20.glVertexAttribPointer(cubeColorParam, 4, GLES20.GL_FLOAT, false, 0, cc); #endregion GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36); checkGLError("Drawing cube"); }; #endregion #region drawCube drawCube(0, objectDistance, objectDistance * -1.0f); drawCube(0, 0, objectDistance * -2.0f); // looks like an airstrip // low fps? //var endOfMatrix = 64; var endOfMatrix = 20; for (int i = -endOfMatrix; i < endOfMatrix; i++) { drawCube(objectDistance, -floorDepth, objectDistance * -2.0f * i); drawCube(-objectDistance, -floorDepth, objectDistance * -2.0f * i); drawCube(objectDistance * 0.5f, 0, objectDistance * -2.0f * i); drawCube(objectDistance * -0.5f, 0, objectDistance * -2.0f * i); } #endregion var modelFloor = new float[16]; Matrix.setIdentityM(modelFloor, 0); Matrix.translateM(modelFloor, 0, // the floor escapes! //TotalTime.ElapsedMilliseconds * 0.01f, 0, -floorDepth, 0); // Floor appears below user. // Set modelView for the floor, so we draw floor in the correct location Matrix.multiplyMM(modelView, 0, view, 0, modelFloor, 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); #region drawFloor // called by onDrawEye Action drawFloor = delegate { GLES20.glUseProgram(floorProgram); // Set ModelView, MVP, position, normals, and color. GLES20.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0); GLES20.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0); GLES20.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0); GLES20.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0); GLES20.glVertexAttribPointer(floorPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, floorVertices); GLES20.glVertexAttribPointer(floorNormalParam, 3, GLES20.GL_FLOAT, false, 0, floorNormals); GLES20.glVertexAttribPointer(floorColorParam, 4, GLES20.GL_FLOAT, false, 0, floorColors); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); checkGLError("drawing floor"); }; drawFloor(); #endregion }; #endregion }
public void onDrawFrame(GL10 glUnused) { gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Do a complete rotation every 10 seconds. long time = SystemClock.uptimeMillis() % 10000L; float angleInDegrees = (360.0f / 10000.0f) * ((int)time); // Set our per-vertex lighting program. gl.useProgram(mPerVertexProgramHandle); // Set program handles for cube drawing. mMVPMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix"); mMVMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVMatrix"); mLightPosHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_LightPos"); mPositionHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Position"); mColorHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Color"); mNormalHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Normal"); // Calculate position of the light. Rotate and then push into the distance. Matrix.setIdentityM(mLightModelMatrix, 0); Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f); Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f); Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f); Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0); Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0); #region drawCube Action drawCube = delegate { // Pass in the position information mCubePositions.position(0); opengl.glVertexAttribPointer(mPositionHandle, mPositionDataSize, (int)gl.FLOAT, false, 0, mCubePositions); gl.enableVertexAttribArray((uint)mPositionHandle); // Pass in the color information mCubeColors.position(0); opengl.glVertexAttribPointer(mColorHandle, mColorDataSize, (int)gl.FLOAT, false, 0, mCubeColors); gl.enableVertexAttribArray((uint)mColorHandle); // Pass in the normal information mCubeNormals.position(0); opengl.glVertexAttribPointer(mNormalHandle, mNormalDataSize, (int)gl.FLOAT, false, 0, mCubeNormals); gl.enableVertexAttribArray((uint)mNormalHandle); // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix // (which currently contains model * view). Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); // Pass in the modelview matrix. gl.uniformMatrix4fv(mMVMatrixHandle, false, mMVPMatrix); // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix // (which now contains model * view * projection). Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); // Pass in the combined matrix. gl.uniformMatrix4fv(mMVPMatrixHandle, false, mMVPMatrix); // Pass in the light position in eye space. gl.uniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]); // Draw the cube. gl.drawArrays(gl.TRIANGLES, 0, 36); }; #endregion // Draw some cubes. Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f); drawCube(); #region drawLight Action drawLight = delegate { var pointMVPMatrixHandle = gl.getUniformLocation(mPointProgramHandle, "u_MVPMatrix"); var pointPositionHandle = gl.getAttribLocation(mPointProgramHandle, "a_Position"); // Pass in the position. gl.vertexAttrib3f((uint)pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]); // Since we are not using a buffer object, disable vertex arrays for this attribute. gl.disableVertexAttribArray((uint)pointPositionHandle); // Pass in the transformation matrix. Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); gl.uniformMatrix4fv(pointMVPMatrixHandle, false, mMVPMatrix); // Draw the point. gl.drawArrays(gl.POINTS, 0, 1); }; #endregion // Draw a point to indicate the light. gl.useProgram(mPointProgramHandle); drawLight(); }
public void onDrawFrame(GL10 glUnused) { if (mBlending) { gl.clear(gl.COLOR_BUFFER_BIT); } else { gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); } // Do a complete rotation every 10 seconds. long time = SystemClock.uptimeMillis() % 10000L; float angleInDegrees = (360.0f / 10000.0f) * ((int)time); // Set our program gl.useProgram(mProgramHandle); // Set program handles for cube drawing. mMVPMatrixHandle = gl.getUniformLocation(mProgramHandle, "u_MVPMatrix"); mPositionHandle = gl.getAttribLocation(mProgramHandle, "a_Position"); mColorHandle = gl.getAttribLocation(mProgramHandle, "a_Color"); #region drawCube Action drawCube = delegate { // Pass in the position information mCubePositions.position(0); GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, (int)gl.FLOAT, false, 0, mCubePositions); gl.enableVertexAttribArray((uint)mPositionHandle); // Pass in the color information mCubeColors.position(0); GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, (int)gl.FLOAT, false, 0, mCubeColors); gl.enableVertexAttribArray((uint)mColorHandle); // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix // (which currently contains model * view). Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix // (which now contains model * view * projection). Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); // Pass in the combined matrix. gl.uniformMatrix4fv(mMVPMatrixHandle, false, mMVPMatrix); // Draw the cube. gl.drawArrays(gl.TRIANGLES, 0, 36); }; #endregion // Draw some cubes. Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f); drawCube(); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f); Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f); drawCube(); }
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"); }
private void drawTexture(IRenderingEngine re, int x, int y, int projectionWidth, int projectionHeight, bool scaleToCanvas, bool redWriteEnabled, bool greenWriteEnabled, bool blueWriteEnabled, bool alphaWriteEnabled) { re.startDirectRendering(true, false, true, true, true, projectionWidth, projectionHeight); re.setColorMask(redWriteEnabled, greenWriteEnabled, blueWriteEnabled, alphaWriteEnabled); if (scaleToCanvas) { re.setViewport(0, 0, Modules.sceDisplayModule.CanvasWidth, Modules.sceDisplayModule.CanvasHeight); } else { re.setViewport(0, 0, projectionWidth, projectionHeight); } IREBufferManager bufferManager = re.BufferManager; ByteBuffer drawByteBuffer = bufferManager.getBuffer(drawBufferId); drawByteBuffer.clear(); FloatBuffer drawFloatBuffer = drawByteBuffer.asFloatBuffer(); drawFloatBuffer.clear(); drawFloatBuffer.put(texS); drawFloatBuffer.put(texT); drawFloatBuffer.put(x + width); drawFloatBuffer.put(y + height); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(texT); drawFloatBuffer.put(x); drawFloatBuffer.put(y + height); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(x); drawFloatBuffer.put(y); drawFloatBuffer.put(texS); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(x + width); drawFloatBuffer.put(y); if (re.VertexArrayAvailable) { re.bindVertexArray(0); } re.setVertexInfo(null, false, false, true, -1); re.enableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_TEXTURE); re.disableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR); re.disableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_NORMAL); re.enableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_VERTEX); bufferManager.setTexCoordPointer(drawBufferId, 2, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FLOAT, 4 * SIZEOF_FLOAT, 0); bufferManager.setVertexPointer(drawBufferId, 2, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FLOAT, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT); bufferManager.setBufferData(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_ARRAY_BUFFER, drawBufferId, drawFloatBuffer.position() * SIZEOF_FLOAT, drawByteBuffer.rewind(), pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DYNAMIC_DRAW); re.drawArrays(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_QUADS, 0, 4); re.endDirectRendering(); }