Cvičenie - úvod do allegra

Created: 2008-10-28 - 18:19


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

using namespace std;

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

  //vytvorit ihlan s stvorcovou postavou
  glTranslatef(0.0f,0.0f,-10.0f);
  while(0==0){
  glRotatef(1,0,1,0);
  glRotatef(1,1,0,0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor3f(0.1,0.3,1.0);
  glBegin(GL_TRIANGLES);
  glVertex3f(-1,0,1); 
  glVertex3f(1,0,1);   
  glVertex3f(0,2,0);
  glColor3f(0.9,1.0,1.0);  
  glVertex3f(1,0,1); 
  glVertex3f(1,0,-1);   
  glVertex3f(0,2,0);  
  glColor3f(1.0,0.0,1.0);  
  glVertex3f(1,0,-1); 
  glVertex3f(-1,0,-1);   
  glVertex3f(0,2,0);  
  glColor3f(1.0,0.8,0.5);  
  glVertex3f(-1,0,1); 
  glVertex3f(0,2,0);  
  glVertex3f(-1,0,-1);
  glEnd();    
  glBegin(GL_QUADS);
  glColor3f(1.0,0.5,1.0);  
  glVertex3f(-1,0,-1); 
  glVertex3f(1,0,-1);
  glVertex3f(1,0,1);   
  glVertex3f(-1,0,1); 
  glEnd(); 
  
/*
  glBegin(GL_QUADS);

  glVertex3f(-1,-1,0); 
  glVertex3f(1,-1,0);   
  glVertex3f(1,1,0);
  glVertex3f(-1,1,0); 
  glEnd();        
*/

  allegro_gl_flip();

  if(key[KEY_ESC]) break;
  }      

  //dva trojuholniky vedla seba:
  /*
  glColor3f(0.0,0.0,1.0);
  glTranslatef(0.0f,0.0f,-10.0f); //posun
  glBegin(GL_TRIANGLES);
  //pred kazdym vrcholom ina farba - GL_SMOOTH - takze sa vytvori prechod
    glColor3f(0.0,0.0,1.0);
  glVertex3f(-1,-1,0);
    glColor3f(0.0,1.0,0.0);
  glVertex3f(1,-1,0);
    glColor3f(1.0,0.0,0.0);
  glVertex3f(0,1,0);  
  glEnd();  
  glColor3f(1.0,1.0,0.0);
  glTranslatef(2.0f,0.0f,0.0f); //posun
  glBegin(GL_TRIANGLES);
  glVertex3f(-1,-1,0);
  glVertex3f(1,-1,0);
  glVertex3f(0,1,0);  
  glEnd(); 
  */
  //alebo takto 
  /*
  glTranslatef(2.0f,0.0f,-10.0f); //posun
  glBegin(GL_TRIANGLES);
  glVertex3f(-3,0,0);
  glVertex3f(-2,2,0);
  glVertex3f(-1,0,0);  
  glVertex3f(1,0,0);
  glVertex3f(2,2,0);
  glVertex3f(3,0,0);  
  glEnd(); */
  //pre stvoruholnik
  /*
  glColor3f(0.0,0.0,1.0);
  glTranslatef(-1.0f,0.0f,-10.0f); //posun
  glBegin(GL_QUADS);
  glVertex3f(-1,-1,0);
  glVertex3f(1,-1,0);
  glVertex3f(1,1,0); 
  glVertex3f(-1,1,0);   
  glEnd();  
  glColor3f(1.0,1.0,0.0);
  glTranslatef(2.5f,0.0f,0.0f); //posun
  glRotatef(45.00,0,0,1);
  glBegin(GL_QUADS);
  glVertex3f(-1,-1,0);
  glVertex3f(1,-1,0);
  glVertex3f(1,1,0);   
  glVertex3f(-1,1,0);  
  glEnd();   
  allegro_gl_flip();
  */

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