Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Java-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLES20; import android.opengl.GLSurfaceView.Renderer; import android.opengl.Matrix; public class GLRenderer implements Renderer { // neu: ByteBuffer bb; ByteBuffer dlb; // Our matrices private final float[] mtrxProjection = new float[16]; private final float[] mtrxView = new float[16]; private final float[] mtrxProjectionAndView = new float[16]; // Geometric variables public static float vertices[]; public static short indices[]; public FloatBuffer vertexBuffer; public ShortBuffer drawListBuffer; // Our screenresolution float mScreenWidth = 1280; float mScreenHeight = 768; // Misc Context mContext; long mLastTime; int mProgram; public GLRenderer(Context c) { mContext = c; mLastTime = System.currentTimeMillis() + 100; } public void onPause() { /* Do stuff to pause the renderer */ } public void onResume() { /* Do stuff to resume the renderer */ mLastTime = System.currentTimeMillis(); } @Override public void onDrawFrame(GL10 unused) { // Get the current time long now = System.currentTimeMillis(); // We should make sure we are valid and sane if (mLastTime > now) return; // Get the amount of time the last frame took. // long elapsed = now - mLastTime; // Update our example // Render our example Render(mtrxProjectionAndView); // Save the current time to see how long it took :). mLastTime = now; } private void Render(float[] m) { // clear Screen and Depth Buffer, we have set the clear color as black. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // get handle to vertex shader's vPosition member int mPositionHandle = GLES20.glGetAttribLocation(riGraphicTools.sp_SolidColor, "vPosition"); // Enable generic vertex attribute array GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer); // Get handle to shape's transformation matrix int mtrxhandle = GLES20.glGetUniformLocation(riGraphicTools.sp_SolidColor, "uMVPMatrix"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, m, 0); // Draw the triangle GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { SetupTriangle(); // We need to know the current width and height. mScreenWidth = width; mScreenHeight = height; // Redo the Viewport, making it fullscreen. GLES20.glViewport(0, 0, (int)mScreenWidth, (int)mScreenHeight); // Clear our matrices for(int i=0;i<16;i++) { mtrxProjection[i] = 0.0f; mtrxView[i] = 0.0f; mtrxProjectionAndView[i] = 0.0f; } // Setup our screen width and height for normal sprite translation. Matrix.orthoM(mtrxProjection, 0, 0f, mScreenWidth, 0.0f, mScreenHeight, 0, 50); // Set the camera position (View matrix) Matrix.setLookAtM(mtrxView, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Calculate the projection and view transformation Matrix.multiplyMM(mtrxProjectionAndView, 0, mtrxProjection, 0, mtrxView, 0); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // Create the triangle // Set the clear color to black GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1); // Create the shaders int vertexShader = riGraphicTools.loadShader(GLES20.GL_VERTEX_SHADER, riGraphicTools.vs_SolidColor); int fragmentShader = riGraphicTools.loadShader(GLES20.GL_FRAGMENT_SHADER, riGraphicTools.fs_SolidColor); riGraphicTools.sp_SolidColor = GLES20.glCreateProgram(); // create empty OpenGL ES Program GLES20.glAttachShader(riGraphicTools.sp_SolidColor, vertexShader); // add the vertex shader to program GLES20.glAttachShader(riGraphicTools.sp_SolidColor, fragmentShader); // add the fragment shader to program GLES20.glLinkProgram(riGraphicTools.sp_SolidColor); // creates OpenGL ES program executables // Set our shader programm GLES20.glUseProgram(riGraphicTools.sp_SolidColor); } public void SetupTriangle() { // We have to create the vertices of our triangle. vertices = new float[] {Andereclass.opengleck, 200f, 0.0f, //oben X Achse Nullpunkt ganz links //oben y Achse Nullpunkt unten 10.0f, 100f, 0.0f, //links X Achse Nullpunkt ganz links // links y Achse Nullpunkt unten 100f, 100f, 0.0f, // 50.0f, 200f, 0.0f, //oben X Achse Nullpunkt ganz links //oben y Achse Nullpunkt unten //50.0f, 100f, 0.0f, //links X Achse Nullpunkt ganz links // links y Achse Nullpunkt unten //300f, 100f, 0.0f, }; indices = new short[] {0, 1, 2, }; // The order of vertexrendering. // The vertex buffer. bb = ByteBuffer.allocateDirect(vertices.length * 4); bb.order(ByteOrder.nativeOrder()); vertexBuffer = bb.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); // initialize byte buffer for the draw list dlb = ByteBuffer.allocateDirect(indices.length * 2); dlb.order(ByteOrder.nativeOrder()); drawListBuffer = dlb.asShortBuffer(); drawListBuffer.put(indices); drawListBuffer.position(0); } } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige