Grafika - alegro - nacitanie zo suboru

Created: 2008-10-28 - 18:36


#include <allegro.h>
#include <alleggl.h>
#include "upjsGl.h"
#include <vector>

using namespace std;

struct BOD{
  float x,y,z;
};

struct STENA{
  int v[3];
};

vector<STENA> stena;
vector<BOD> bod;
int n, m; //pocet vrcholov, stien

int nacitaj(char* subor) {
  FILE *s;
  s = fopen(subor, "r");
  if (s == 0) return 1;
  fscanf(s, "%d", &n);
  for (int i=0; i<n; i++) {
    BOD b;
    fscanf(s, "%f %f %f", &b.x, &b.y, &b.z);
    bod.push_back(b);
  }
  fscanf(s, "%d", &m);
  for (int i = 0; i < m; i++) {
    STENA st;
    fscanf(s, "%d %d %d", &st.v[2], &st.v[1], &st.v[0]);
    for(int j = 0; j < 3; j++) st.v[j]--;
    stena.push_back(st);
  }
  fclose(s);
  return 0;
}

int main (void) {
  if (upjsGl_init(1024,768,32)!=0) {
    allegro_message("zle je!");
  
    upjsGl_exit();
    return 1;
  }
  clear_keybuf();

  allegro_gl_begin();
  glShadeModel(GL_SMOOTH); //plynuly prechod farebny
  glLoadIdentity(); //nastavi maticu transformacie na jednotkovu
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //zmazanie obrazovky
  
  glTranslatef(0.0f,0.0f,-100.0f);
    nacitaj("01.txt");


  while(0==0){
      
  glRotatef(1,0,1,0);
  glRotatef(1,1,0,0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
    glBegin(GL_TRIANGLES);
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 3; j++) {
        glVertex3f(bod[stena[i].v[j]].x, bod[stena[i].v[j]].y, bod[stena[i].v[j]].z);
      }
    }
    glEnd();

  allegro_gl_flip();

  if(key[KEY_ESC]) break;
  }      

  
  allegro_gl_end();
  upjsGl_exit();
  return 0;
}
END_OF_MAIN();