VPN termux about China.net

Vertex3f() found obj C4 load car Picasso

 /*picasso.c */

#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"

#include <vector>

#include <fstream>

#include <sstream>

#include <iostream>

#include <vector>

 int nrTrangles=0;

GLuint car;

float carrot;

struct Vec2 {

    float x, y, z;

};

struct Vec3 {

    float x, y, z;

};

std::vector<Vec2> vertics_2;

std::vector<Vec3> faces;

void myVertex3f(float x, float y, float z) {

    Vec2 vertex = {x, y, z};

    vertics_2.push_back(vertex);

}

void myFaceVertex3f(int x, int y, int z) {

    Vec3 vertex = {x, y, z};

    faces.push_back(vertex);

}


/*

struct Face {

    int v1, v2, v3;

};


std::vector<Vec3> vertices;

std::vector<Face> faces;*/

void loadObj(char *fname)

{

   FILE *fp;

   int read;

   GLfloat x, y, z;

   int v1,v2,v3;

   char ch;

   //car=glGenLists(1);

   fp=fopen(fname,"r");

   if (!fp)

  {

    printf("can't open file %s\n", fname);

    exit(1);

  }

  

    glPushMatrix();

   /*glPointSize(2.0);

   glNewList(car, GL_COMPILE);

   {

    glBegin(GL_POINTS);*/

    while(!(feof(fp)))

    {

     read=fscanf(fp,"%c %f %f %f",&ch,&x,&y,&z);

     if(read==4&&ch=='v')

    {

     myVertex3f(x,y,z);

     }

     if(read==4&&ch=='f'){

     

        myFaceVertex3f(v1,v2,v3);

     }

     nrTrangles+=1;

   }

  // glEnd();

   

   glPopMatrix();

   //glEndList();

   fclose(fp);

}

/*

bool loadOBJ(const char* path) {

    std::ifstream file(path);

    if (!file.is_open()) {

        std::cerr << "Failed to open file: " << path << std::endl;

        return false;

    }


    std::string line;

    while (std::getline(file, line)) {

        std::stringstream ss(line);

        std::string prefix;

        ss >> prefix;


        if (prefix == "v") {

            Vec3 vertex;

            ss >> vertex.x >> vertex.y >> vertex.z;

            vertices.push_back(vertex);

        } else if (prefix == "f") {

            Face face;

            char slash; // To skip '/' characters if present

            ss >> face.v1 >> slash >> face.v2 >>slash >> face.v3;

            faces.push_back(face);

        }

    }


    return true;

}

*/

static SDLTest_CommonState *state;

SDL_Window *win = NULL;

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

 


static SDL_GLContext *context = NULL;

struct mouse_handle{

int x;

int y;

}mouse;

void Render()

{

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

};

glPushMatrix();

/* Do our drawing, too. */

glClearColor(1.0, 1.0, 0.0, 1.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glTranslatef(0,0,-2);

/* Draw the cube */

glColorPointer(4, GL_UNSIGNED_BYTE, 4, color);

glRotatef(mouse.x, mouse.y, 1.0+mouse.x,1.0+mouse.y); glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, (void*)myVertex3f);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLES, nrTrangles, GL_UNSIGNED_BYTE,  (void*)&myFaceVertex3f);


glMatrixMode(GL_MODELVIEW);

glPopMatrix();

glFlush();

}


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

{

loadObj("/sdcard/cat.obj");

// loadOBJ("cube.obj");

SDL_DisplayMode mode;


state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);

SDL_Event event;

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

 //SDL_GL_CreateContext(*state->event);


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

       SDL_SetRenderDrawColor(renderer, 255, 255, 25, 255); // Biały kolor


        SDL_RenderFillRect(renderer, &rect);

        SDL_RenderPresent(renderer);

        SDL_GL_SwapWindow(win);

Render();

SDL_GL_SwapWindow(*state->windows);

}


return 0;

}


No comments:

Post a Comment