VPN termux about China.net

Wednesday 7 August 2024

NEW OpenGL i SDL2 work's im C4droid


#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <math.h>

#include "SDL2/SDL.h"

#include "SDL_test_common.h"

#if defined(__IPHONEOS__) || defined(__ANDROID__)

#define HAVE_OPENGLES

#endif

#include "SDL_opengles.h"

struct mouse_handle {

    int x = 1;

    int y = 1;

} mouse;

 SDLTest_CommonState *state;

SDL_Window *win = NULL;

 SDL_Renderer* renderer= SDL_CreateRenderer(win, -1, SDL_WINDOW_OPENGL);

  SDL_Event *event;


static SDL_GLContext *context;


void Render()

{

    static GLubyte color[3][4] = { {255, 0, 0, 255}, {0, 255, 0, 255}, {0, 0, 255, 255} };

    static GLfloat vertices[3][3] = { {0.0f, 0.5f, 0.0f}, {-0.5f, -0.5f, 0.0f}, {0.5f, -0.5f, 0.0f} };

    static GLubyte indices[3] = {0, 1, 2};


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);

    glEnableClientState(GL_COLOR_ARRAY);

    glVertexPointer(3, GL_FLOAT, 0, vertices);

    glEnableClientState(GL_VERTEX_ARRAY);

    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, indices);


    glDisableClientState(GL_VERTEX_ARRAY);

    glDisableClientState(GL_COLOR_ARRAY);


    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

  

}

int main(int argc, char *argv[])

{

SDL_DisplayMode mode;


   //SDL_GL_MakeCurrent(win,context);

state = SDLTest_CommonCreateState(argv, SDL_INIT_EVERYTHING);


SDLTest_CommonInit(state); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 0);

bool sdlmainloop=true;

    bool running = true;

    while (running) {

        SDL_Event event;

        while (SDL_PollEvent(&event)) {

            if (event.type == SDL_QUIT) {

                running = false;

            }

              if (event.type == SDL_MOUSEMOTION)

  {

   mouse.x = event.motion.x;

   mouse.y = event.motion.y;

SDL_GL_CreateContext(*state->windows);

       

// OpenGL Window 

  glRotatef(mouse.x % 360, mouse.y % 360, mouse.x % 360, mouse.y % 360);

Render();

SDL_GL_SwapWindow(*state->windows);

  }    

      /*Sdl2 Window*/

SDL_GLContext glcontext = SDL_GL_CreateContext(win);


SDL_Rect rect = {100, 100, 200, 200};

       SDL_SetRenderDrawColor(*state->renderers, 255, 255, 25, 255); // Biały kolor 

     SDL_RenderFillRect(*state->renderers, &rect);

        SDL_RenderPresent(*state->renderers);

    }

}

return 0;

}


No comments:

Post a Comment