Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Few things about games by Ihor Homyn

Few things about games by Ihor Homyn

Few things about games by Ihor Homyn

Avatar for GDG Ternopil

GDG Ternopil

July 22, 2015
Tweet

More Decks by GDG Ternopil

Other Decks in Programming

Transcript

  1. Дещо про ігри платформа? • Android! місце, час? • Зустріч

    спільноти Android програмістів Тернополя • EVOLUTION коворкінг, 22.07.2015р. про? • OpenGL ES 2.0 • LibGDX автора? • Ігор Хомин • [email protected]
  2. Чому OpenGL ES 2.0? • Android > 2.2 through Java

    • Apple iOS 5 or later in iPad, iPad Mini, iPhone 3GS or later, and iPod Touch 3rd generation or later • BlackBerry devices with BlackBerry OS 7.0 and Blackberry 10, as well as the BlackBerry PlayBook • Google Native Client • Various Nokia phones (such as Symbian^3 based Nokia N8, MeeGo based Nokia N9, and Maemo based Nokia N900[24]) • Palm webOS, using the Plug-in Development Kit • The Pandora console • The Raspberry Pi • The Odroid • Various Samsung mobile phones (such as the Wave) • Web browsers (WebGL) • The GCW Zero console
  3. Реалізація в OpenGL ES • private GLSurfaceView mGLSurfaceView; • public

    void onCreate(Bundle savedInstanceState) { mGLSurfaceView = new GLSurfaceView(this); mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setRenderer(new MyRenderer()); setContentView(mGLSurfaceView); } • public MyRenderer() { final float[] triangleVerticesData = { -0.5f, -0.25f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, // X, Y, Z, R, G, B, A ... mTriangleVertices = ByteBuffer.allocateDirect(triangle1VerticesData.length * mBytesPerFloat) .order(ByteOrder.nativeOrder()).asFloatBuffer(); mTriangleVertices.put(triangleVerticesData).position(0); ... }
  4. Defining vertex ... • final String vertexShader = "uniform mat4

    u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix. + "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in. + "attribute vec4 a_Color; \n" // Per-vertex color information we will pass in. + "varying vec4 v_Color; \n" // This will be passed into the fragment shader. + "void main() { \n" // The entry point for our vertex shader. + " v_Color = a_Color; \n" // Pass the color through to the fragment shader. // It will be interpolated across the triangle. + " gl_Position = u_MVPMatrix \n" // gl_Position is special var used to store final position + " * a_Position; \n" // Multiply the vertex by the matrix to get the final point in + "} \n"; // normalized screen coordinates.
  5. … and fragment shaders • final String fragmentShader = "precision

    medium p float; \n" // Set default precision to medium. // We don't need high // precision in the fragment shader. + "varying vec4 v_Color; \n" // The color from the vertex shader // interpolated across the // triangle per fragment. + "void main() { \n" // The entry point for our fragment shader. + " gl_FragColor = v_Color; \n" // Pass color directly through the pipeline. + "}
  6. Loading shaders into OpenGL • int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); if

    (vertexShaderHandle != 0) { GLES20.glShaderSource(vertexShaderHandle, vertexShader); // Pass in the shader source. GLES20.glCompileShader(vertexShaderHandle); // Compile the shader. final int[] compileStatus = new int[1]; // Get the compilation status. GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0); if (compileStatus[0] == 0) { GLES20.glDeleteShader(vertexShaderHandle); vertexShaderHandle = 0; } }
  7. І це ще не все! • Linking a vertex and

    fragment shader together into a program • Setting the perspective projection • Drawing stuff to the screen! http://www.learnopengles.com/android-lesson-one-getting-start ed/
  8. Чому libGDX? • весь безлад з шейдерами прихований • Крос-платформність:

    Desktop, Android, HTLM5 та iOS (за допомогою RoboVM) • Чудова продуктивність • Відмінна документація, велика спільнота • Всі основні можливості 2D та 3D ігр • Дружня ліцензія (Apache 2.0) – можна вільно використовувати для комерційних додатків
  9. Реалізація в libGDX • void create() // При запуску додатка

    • void dispose() // При завершенні програми • void pause() // пауза • void resume() // відновлення роботи • void render() // малювання екрану • void resize(int width, int height) // зміна видимої області
  10. libGDX не для... • Запуск додатка (wrapper) • Реклама •

    Придбання з додатка • Введення тексту • Таблиці рекордів
  11. Інфо • https://www.khronos.org/opengles/ • http://libgdx.badlogicgames.com/ • https://github.com/nicolasgramlich/AndEngine • http://robovm.com/ •

    http://www.codeproject.com/Articles/702957/Create-your-first-An droid-Game-with-libgdx • http://developer.android.com/training/graphics/opengl/index.html