website logo
Auteur
avatar
hunoppc

Forum » » Logiciels » » Sondage et tutos Warp3D Nova / OpenGL ES


Posté : 14-09-2016 20:08 icone du post

Salut Alain
Merci pour tout (corrections et félicitations)
Moi aussi je te félicite pour ton travail
Donc oui cela facilite la tâche à tous voici le code exemple de la démo vidéo YOUTUBE

---------------------------------------------------------------- -------------------
/*
 * Book:      OpenGL(R) ES 2.0 Programming Guide
 * Authors:   Aaftab Munshi, Dan Ginsburg, Dave Shreiner
 * ISBN-10:   0321502795
 * ISBN-13:   9780321502797
 * Publisher: Addison-Wesley Professional
 * URLs:      http: *safari.informit.com/9780321563835
 *     &nbs p;      http: *www.opengles-book.com
 */

/*
 * triangles.c draw Working on AmigaOS4 now !!!
 *
 * This is a simple example that draws a single triangle with a
 * minimal vertex/fragment shader.  The purpose of this example is to
 * demonstrate the basic concepts of OpenGL ES 2.0 rendering.
 */
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "egl_wrap.h"

typedef struct
{
    /* Handle to a program object. */
    GLuint programObject;

    /* Angle of rotation. */
    float rotationAngle;

} UserData;

/* Initialize the shader and program object. */
int init(ESContext *esContext)
{
    esContext->userData = malloc(sizeof(UserData));

    UserData *userData = (UserData*)esContext->userData;
    const char *vShaderStr = 
        "uniform mat4 u_mvpMatrix;    \n"
        "attribute vec4 a_position;   \n"
        "attribute vec4 a_color;      \n"
        "varying vec4 v_color;        \n"
        "void main()            & nbsp;     \n"
        "{              ;                \n"
        "   gl_Position = u_mvpMatrix * a_position; \n"
        "   v_color = a_color;        \n"
        "}              ;                \n";
  
    const char *fShaderStr = 
        "precision mediump float;            & nbsp;        \n"
        "varying vec4 v_color;             ;            \n"
        "void main()            & nbsp;            &n bsp;        \n"
        "{              ;                           & nbsp;    \n"
        "  gl_FragColor = v_color;             ;        \n"
        "}              ;                           & nbsp;    \n";

    GLuint vertexShader;
    GLuint fragmentShader;
    GLuint programObject;
    GLint linked;

    /* Load the vertex/fragment shaders. */
    vertexShader = esLoadShader(GL_VERTEX_SHADER, vShaderStr);
    fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fShaderStr);

    /* Create the program object. */
    programObject = glCreateProgram();
  
    if (programObject == 0) {
        return 0;
    }

    glAttachShader(programObject, vertexShader);
    glAttachShader(programObject, fragmentShader);

    /* Bind artributes. */
    glBindAttribLocation(programObject, 0, "a_position");
    glBindAttribLocation(programObject, 1, "a_color");

    /* Link the program and check linking result. */
    glLinkProgram(programObject);
    glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
    if (!linked) {
        GLint infoLen = 0;

        glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
     
        if (infoLen > 1) {
            char* infoLog = (char*)malloc(sizeof(char) * infoLen);

          &n bsp; glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
            esLogMessage("Error linking program:\n%s\n", infoLog);           
            free(infoLog);
        }

        glDeleteProgram(programObject);
        return GL_FALSE;
    }

    /* Store the program object. */
    userData->programObject = programObject;

    glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    return GL_TRUE;
}

/* Update the state. */
void update(ESContext *esContext, float deltaTime)
{
    UserData *userData = (UserData*)esContext->userData;
    userData->rotationAngle += (32.0 * M_PI * deltaTime);
}

///
// Cleanup
//
void ShutDown ( ESContext *esContext )
{
   UserData *userData = (UserData*)esContext->userData;

   // Delete program object
   glDeleteProgram ( userData->programObject );

   //shutdown context opengl-es AOS4
   esShutdown(esContext);
}

//
// Handle keyboard input
//
void Key ( ESContext *esContext, unsigned char key, int x, int y)
{
    //here add your action keyboard on your program
   switch ( key )
   {
   case '1':
      //printf( "FPS Activated now !!\n" );
      // Activate FPS counter
    esActivateFPS(1);
      break;

   case '2':
      //printf( "FPS disabled now !!\n" );
      // Disable FPS counter
    esActivateFPS(0);
      break;

   case 033: // ASCII Escape Key
    //printf( "Saw an 'Escape' \n" );
    //New function for Unload context and shutdown a lib EGL for Opengl-ES AOS4
    esShutdown(esContext);
       break;
   }
}


/* Draw a triangle using the shader pair created in Init() */
void draw(ESContext *esContext)
{
    static GLfloat vertices[] = {0.0f,  0.5f, 0.0f,1.0f,
            ;                       -0.5f, -0.5f, 0.0f, 1.0f,
           &nbs p;              ;        0.5f, -0.5f, 0.0f, 1.0f};

    static GLfloat colors[] = {1.0f, 0.0f, 0.0f, 1.0f,
            &nb sp;            &nbs p;     0.0f, 1.0f, 0.0f, 1.0f,
            &nb sp;            &nbs p;     0.0f, 0.0f, 1.0f, 1.0f};

    UserData *userData = (UserData*)esContext->userData;
     
    /* Set the viewport. */
    glViewport(0, 0, esContext->width, esContext->height);
  
    /* Clear the color buffer. */
    glClear(GL_COLOR_BUFFER_BIT);

    /* Use the program object. */
    glUseProgram(userData->programObject);

    /* Load the vertex and color data. */
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, vertices);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, colors);
    glEnableVertexAttribArray(1);

    /* Create and load a rotation matrix uniform. */
    ESMatrix rotationMatrix;
    esMatrixLoadIdentity(&rotationMatrix);
    esRotate(&rotationMatrix, userData->rotationAngle, 0.0f, 1.0f, 0.0f);
    glUniformMatrix4fv(0, 1, GL_FALSE, (GLfloat*) &rotationMatrix.m[0]);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}

int main(int argc, char *argv[])
{
    ESContext esContext;
    UserData userData;

     //activate FPS
    esActivateFPS(1);

     //activate Fullscreen mode
    eglFullScreenActivated(1);

    esInitContext(&esContext);
    esContext.userData = &userData;

    esCreateWindow(&esContext, "Hello Triangle", 800, 600, ES_WINDOW_ALPHA);

    if (!init(&esContext)) {
        return EXIT_FAILURE;
    }

    esRegisterUpdateFunc(&esContext, update);
    esRegisterDrawFunc(&esContext, draw);
    esRegisterKeyFunc( &esContext, Key );
    esMainLoop(&esContext);

    return EXIT_SUCCESS;
}

----------------------------------------------------- -------------------------------------------

Je pourrais te faire pousser une version de la lib ce soir mais pas encore fini tout pour la gui
cela peut te faire faire des tests sur ta vache
HunoPPC

AmigaOs4 Rulez
- X1000 Nemo - 1800 Mhz 4 Go de Ram - Radeon HD R9 280X Version Toxic 3GO
Soundblaster live 5.1, Siil 3114 PCIe 1X, Port Serial debug
X5000/40 RX560 4Go

Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x
https://amiga-ng.org/viewtopic.php?topic=2343&forum=4