VPN termux about China.net

Wednesday 28 August 2024

glBegin world's on sdl2 c4

 #include <iostream>

#include <vector>

#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 <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "SDL_opengles.h"

// Struktura do przechowywania wierzchołków

int gl;

struct Vertex

{

 float x, y, z;

};

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

// Globalne zmienne przechowujące aktualnie rysowane prymitywy

//PrimitiveType currentPrimitiveType;

std::vector < Vertex > vertices;


// Uproszczona funkcja glBegin tutaj zamiast enum misialem uzyc int gl bo juz jest zdwfiniowane w sdl_opengl.h jako int i nie chcialo puscic 

void glBegin(int gl)

{

 //currentPrimitiveType = primitiveType;

 vertices.clear(); // Wyczyść bufor wierzchołków

}


// Uproszczona funkcja glVertex3f

void glVertex3f(float x, float y, float z)

{

 vertices.push_back({x, y, z});

}


// Uproszczona funkcja glEnd

void glEnd() {

    switch (gl) {

        case GL_POINTS:

            for (const auto &vertex : vertices) {

                std::cout << "Point: (" << vertex.x << ", " << vertex.y << ", " << vertex.z << ")" << std::endl;

            }

            glEnableClientState(GL_COLOR_ARRAY);

            glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);

            glEnableClientState(GL_VERTEX_ARRAY);

            glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)vertices.data());

            glDrawArrays(GL_POINTS, 0, vertices.size());

            break;


        case GL_TRIANGLES:

            if (vertices.size() % 3 != 0) {

                std::cerr << "Warning: Number of vertices is not a multiple of 3 for GL_TRIANGLES" << std::endl;

            }

            for (size_t i = 0; i < vertices.size(); i += 3) {

                std::cout << "Triangle: (" << vertices[i].x << ", " << vertices[i].y << ", " << vertices[i].z << ") -> ("

                          << vertices[i + 1].x << ", " << vertices[i + 1].y << ", " << vertices[i + 1].z << ") -> ("

                          << vertices[i + 2].x << ", " << vertices[i + 2].y << ", " << vertices[i + 2].z << ")" << std::endl;

            }

            glEnableClientState(GL_COLOR_ARRAY);

            glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);

            glEnableClientState(GL_VERTEX_ARRAY);

            glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)vertices.data());

            glDrawArrays(GL_TRIANGLES, 0, vertices.size());

            break;


        default:

            std::cerr << "Unsupported primitive type!" << std::endl;

            break;

    }

}



struct mouse_handle

{

 int x = 1;

 int y = 1;

} mouse;

/* this */

SDLTest_CommonState *state;

SDL_Event *event;

static SDL_GLContext *context;

struct obj

{

 float x;

 float y;

 float z;

 int Render()

 {

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

//gluPerspective(45.0, (double)screen_width/screen_height, 1.0, 200.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

//glTranslatef(0.0f, 0.0f, -5.0f); // Odsunięcie kamery


 glEnable(GL_LIGHTING);

  glEnable(GL_LIGHT0);


  GLfloat light_position[] = { 0.2, 1.0, 10.0, 1.0 };

glPointSize(10.0f); // Ustawia rozmiar punktu na 10 pikseli


     glBegin(GL_POINTS);

    glVertex3f(0.4f, 0.0f, 0.0f);

 

   // glVertex3f(mouse.x, mouse.y, 0.0f);

    glVertex3f(0.0f, 0.5f, 0.0f);

    glVertex3f(1.0f, 0.5f, 1.0f);

    glVertex3f(0.0f, -0.5f, 0.0f);

    glEnd();



  return 1;

 }

};




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

{

 SDL_DisplayMode mode;

 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);

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  

   /* 

draw() */

   obj gg;

   gg.x = 0.2f;

   gg.y = 0.4f;

   gg.z = 0.6f;

   gg.Render();

   SDL_GL_SwapWindow(*state->windows);

  }

 }

 return 0;

}

No comments:

Post a Comment