Esempio n. 1
0
// Render the cube system
void cube_system::render_system()
{
	/********
	Task 2.1.2.    Program the transformation tree from the exercise sheet. To store the
				   active aggregated transformation matrix on top of a stack use glPushMatrix 
				   and to reactivate and remove the top element of the transformation stack
				   use glPopMatrix. For animation a variable "angle" (which has values
				   between 0 and 359) is defined. Use it for rotations as defined in
				   the transformation tree.
	Aufgabe 2.1.2. Programmieren Sie den Transformationsbaum aus dem Uebungsblatt.
				   Nutzen Sie glPushMatrix um die aktuelle Gesamttransformations-Matrix an die 
				   Spitze eines Stacks zu speichern und glPopMatrix um die vorderste Matrix
				   im Stack zu entfernen und zu reaktivieren. Fuer Animationen steht eine Variable
				   "angle" zur Verfuegung (die Werte zwischen 0 und 359 enthält). Nutzen Sie diese
				   Variable für Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
	*********/


	// Remove the following statement (if wanted) as it just serves 2.1.1.
	// Entfernen Sie die folgende Anweisung gegebenenfalls, da sie lediglich dem Testen
	// von Aufgabe 2.1.1 dient.
	// render_cube();

	glPushMatrix();
	glRotated(angle, 0, 1, 0);
	render_cube();
	glPopMatrix();

	glRotated(-angle, 0, 1, 0);
	glTranslated(5, 0, 0);
	glScaled(0.6, 0.6, 0.6);
	render_cube();

	glPushMatrix();
	glRotated(2 * angle, 0, 0, 1);
	glTranslated(3, 0, 0);
	glScaled(0.5, 0.5, 0.5);
	render_cube();
	glPopMatrix();

	
	glRotated(2 * angle + 180, 0, 0, 1);
	glTranslated(3, 0, 0);
	glScaled(0.5, 0.5, 0.5);
	render_cube();



}
Esempio n. 2
0
void example_3d_primitives::render()
{
	glEnable(GL_DEPTH_TEST);

	// Clear the screen
	glClearColor(1,1,1,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Setup a perspective projection and lighting
	setup_projection();
	setup_light();

	glScaled(0.4, 0.4, 0.4);

	// Move 5 units to the left, save the current transformation
	// and show a rotated tetrahedron
	glTranslated(-5, 0, 0);
	glPushMatrix();
	glRotated(angle, 0, 1, 0);
	glColor3d(1, 1, 0);
	render_tetrahedron();
	glPopMatrix();

	// Move 3 units to the right, save the current transformation
	// and show a rotated cylinder
	glTranslated(3, 0, 0);
	glPushMatrix();
	glRotated(angle, 1, 0, 0);
	glColor3d(0, 1, 0);
	render_cylinder();
	glPopMatrix();

	// Move 3 units to the right, save the current transformation
	// and show a rotated cube
	glTranslated(3, 0, 0);
	glPushMatrix();
	glRotated(angle, 0, 1, 1);
	glColor3d(1, 0, 0);
	render_cube();
	glPopMatrix();

	// Move 3 units to the right, save the current transformation
	// and show a rotated sphere
	glTranslated(3, 0, 0);
	glPushMatrix();
	glRotated(angle, 0, 1, 0);
	glColor3d(0, 0, 1);
	render_sphere();
	glPopMatrix();
}
Esempio n. 3
0
int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_VIDEO);




     gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
      

    SDL_GL_CreateContext(gWindow);

    init_gl();
    resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);

    GLTerminal *t=init_gl_term();
//    gl_term_run(t, "~/qemu_test/qemu.sh");
    gl_term_run(t,"/bin/sh");
    update_gl_term(t);
    SDL_Event e;
    render_gl_term(t);
    while(1) {
        while(SDL_PollEvent(&e)) {
           switch(e.type) {
              case SDL_QUIT:
                exit(0);
              break;
              case SDL_KEYDOWN:
                send_term_keypress(t,(char)e.key.keysym.sym);
              break;
           }
        }
       glClearColor(0.0f,0.0f,1.0f,1.0f);
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       update_gl_term(t);

       render_gl_term(t);

       render_cube(t);

       SDL_GL_SwapWindow(gWindow);
    }
}
Esempio n. 4
0
int do_matrix()
{
	int i,j,k;
	float cx,cy,cz;
	cx=-bwidth/2;
	cy=-bheight/2;
	cz=-bdepth/2;
	for(i=0;i<bwidth;i++){
		for(j=0;j<bheight;j++){
			for(k=0;k<bdepth;k++){
				if(buffer[i+j*bwidth+(k*bwidth*bheight)]){
					int move=0;
					glPushMatrix();
					glTranslatef(cx+i+move,cy+j+move,cz+k+move);
					render_cube();
					glPopMatrix();
				}
			}
		}
	}
}
Esempio n. 5
0
void render_frame() {
    /* Clear the color and depth buffers */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    /* Draw the triangle on the left side*/
    glPushMatrix();
    glTranslatef(-2, 0, 0);  
    render_triangle();
    glPopMatrix();

    /* Draw the cube with some rotation on the right side */
    glPushMatrix();

    /* EDIT: Timing control for the animation! */
    static unsigned previous_time = 0;
    unsigned current_time = SDL_GetTicks();
    unsigned elapsed_time = current_time - previous_time;
    previous_time = current_time;
	
    /* Make the cube rotate around a little */
    static float angle1 = 0.0f;
    static float angle2 = 0.0f;
    angle1 += 0.1f * elapsed_time;
    angle2 += 0.05f * elapsed_time; 

    glTranslatef(2, 0, 0);
    glRotatef(angle1, 0, 1, 0);
    glRotatef(angle2, 1, 0, 0);
    render_cube();
    glPopMatrix();

    /* Present the frame buffer */
    SDL_GL_SwapBuffers();
}
Esempio n. 6
0
int
main (int argc, char* argv[])
{
  int cable_type, quit = 0;
  float rot1 = 0.0, rot2 = 0.0, rot3 = 0.0;
  kos_img_t front_txr, back_txr, tmp_img;
  pvr_ptr_t texaddr;
  GLuint texture[8];
  int blendfunc = 2;
  float eye_rot = 0;

  cable_type = vid_check_cable ();
  
  if (cable_type == CT_VGA)
    vid_init (DM_640x480_VGA, PM_RGB565);
  else
    vid_init (DM_640x480_PAL_IL, PM_RGB565);
  
  init_pvr ();

  glKosInit ();

  sphere = mkspheredata (3, &nstrip, &stripl);

  glGenTextures (8, &texture[0]);

#if 1
  kmg_to_img ("/rd/sky1.kmg", &front_txr);
  texaddr = pvr_mem_malloc (front_txr.byte_count);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, front_txr.w, front_txr.h,
	      texaddr);

  kmg_to_img ("/rd/sky2o.kmg", &back_txr);
  texaddr = pvr_mem_malloc (back_txr.byte_count);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRFMT_VQ_ENABLE);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB4444_TWID | GL_VQ_ENABLE, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  kmg_to_img ("/rd/sky3.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  kmg_to_img ("/rd/sky4.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  kmg_to_img ("/rd/sky5.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  kmg_to_img ("/rd/sky6.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  kmg_to_img ("/rd/sky7.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  kmg_to_img ("/rd/sky8.kmg", &tmp_img);
  texaddr = pvr_mem_malloc (tmp_img.byte_count);
  pvr_txr_load_kimg (&tmp_img, texaddr, PVR_TXRFMT_VQ_ENABLE);
  glKosTex2D (GL_RGB565_TWID | GL_VQ_ENABLE, tmp_img.w, tmp_img.h, texaddr);

#else  
  png_to_img ("/rd/sky1.png", PNG_MASK_ALPHA, &front_txr);
  texaddr = pvr_mem_malloc (front_txr.w * front_txr.h * 2);
  pvr_txr_load_kimg (&front_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&front_txr, 0);
  
  glBindTexture (GL_TEXTURE_2D, texture[0]);
  glKosTex2D (GL_ARGB1555_TWID, front_txr.w, front_txr.h, texaddr);

  png_to_img ("/rd/sky2o.png", PNG_MASK_ALPHA, &back_txr);
  texaddr = pvr_mem_malloc (back_txr.w * back_txr.h * 2);
  pvr_txr_load_kimg (&back_txr, texaddr, PVR_TXRLOAD_INVERT_Y);
  kos_img_free (&back_txr, 0);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  glBindTexture (GL_TEXTURE_2D, texture[1]);
  glKosTex2D (GL_ARGB1555_TWID, back_txr.w, back_txr.h, texaddr);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
  glBindTexture (GL_TEXTURE_2D, texture[2]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky3.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[3]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky4.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[4]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky5.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[5]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky6.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[6]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky7.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);

  glBindTexture (GL_TEXTURE_2D, texture[7]);
  texaddr = pvr_mem_malloc (TEXSIZE * TEXSIZE * 2);
  png_to_texture ("/rd/sky8.png", texaddr, PNG_NO_ALPHA);
  glKosTex2D (GL_RGB565_TWID, TEXSIZE, TEXSIZE, texaddr);
#endif
  
  glEnable (GL_DEPTH_TEST);
  glEnable (GL_CULL_FACE);
  glEnable (GL_TEXTURE_2D);
  glShadeModel (GL_SMOOTH);
  glClearDepth (1.0f);
  glDepthFunc (GL_LEQUAL);
  
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective (60.0,			/* Field of view in degrees.  */
		  640.0 / 480.0,	/* Aspect ratio.  */
		  1.0,			/* Z near.  */
		  50.0);		/* Z far.  */

  glMatrixMode (GL_MODELVIEW);
  
  while (!quit)
    {
      MAPLE_FOREACH_BEGIN (MAPLE_FUNC_CONTROLLER, cont_state_t, st)
        {
	  if (st->buttons & CONT_START)
	    quit = 1;
	  
	  eye_pos[0] = st->joyx / 25.0;
	  eye_pos[1] = st->joyy / 25.0;
	  eye_pos[2] = 5 * sin (eye_rot);
	  
	  if (st->buttons & CONT_A)
	    blendfunc = 0;
	  else if (st->buttons & CONT_B)
	    blendfunc = 1;
	  else if (st->buttons & CONT_X)
	    blendfunc = 2;
	}
      MAPLE_FOREACH_END ()
      
      draw_vectors = 10;
      
      glLoadIdentity ();
      gluLookAt (eye_pos[0], eye_pos[1], eye_pos[2],	/* Eye position.  */
		 0.0,   0.0,   0.0,			/* Centre.  */
		 0.0,   1.0,   0.0);			/* Up.  */

      glGetFloatv (GL_MODELVIEW_MATRIX, &camera[0][0]);

      invcamera[0][0] = camera[0][0];
      invcamera[0][1] = camera[1][0];
      invcamera[0][2] = camera[2][0];
      invcamera[0][3] = 0.0;

      invcamera[1][0] = camera[0][1];
      invcamera[1][1] = camera[1][1];
      invcamera[1][2] = camera[2][1];
      invcamera[1][3] = 0.0;

      invcamera[2][0] = camera[0][2];
      invcamera[2][1] = camera[1][2];
      invcamera[2][2] = camera[2][2];
      invcamera[2][3] = 0.0;

      invcamera[3][0] = 0.0;
      invcamera[3][1] = 0.0;
      invcamera[3][2] = 0.0;
      invcamera[3][3] = 1.0;

      /*dbgio_printf ("inverted camera orthogonality: %f %f %f\n",
		    (double) vec_dot (invcamera[0], invcamera[1]),
		    (double) vec_dot (invcamera[1], invcamera[2]),
		    (double) vec_dot (invcamera[2], invcamera[0]));*/

      /*dbgio_printf ("Inverted camera matrix:\n");
      for (i = 0; i < 4; i++)
	{
	  dbgio_printf ("[ %f %f %f %f ]\n",
                	(double) invcamera[0][i], (double) invcamera[1][i],
	        	(double) invcamera[2][i], (double) invcamera[3][i]);
	}*/

      glKosBeginFrame ();

      /*glPushMatrix ();
      glTranslatef (-camera[3][0], -camera[3][1], -camera[3][2]);*/
      render_cube (&texture[2]);
      /*glPopMatrix ();*/
      
      glPushMatrix ();
      
      #if 1
      glRotatef (rot1, 0.0, 1.0, 0.0);
      rot1 += 0.7;
      glRotatef (rot2, 1.0, 0.0, 0.0);
      rot2 += 0.29;
      #else
      glRotatef (rot1, 0.0, 0.0, 1.0);
      rot1 += 0.7;
      #endif
      
      if (rot1 >= 360)
        rot1 -= 360;

      if (rot2 >= 360)
        rot2 -= 360;
      
      eye_rot += 0.05;
      if (eye_rot >= 2 * M_PI)
        eye_rot -= 2 * M_PI;
      
      blob_phase += 0.05;
      if (blob_phase >= 24 * M_PI)
        blob_phase -= 24 * M_PI;
      
      /* Render front.  */
      glBindTexture (GL_TEXTURE_2D, texture[0]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);

      #if 1
      render_blob (sphere, nstrip, stripl, 1);
      #else
      render_torus (1.0, 0.6, 1);
      #endif
            
      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 1);
      glPopMatrix ();
      
      glKosFinishList ();

      /* Render back.  */
      glBindTexture (GL_TEXTURE_2D, texture[1]);
      glTexEnvi (GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      if (blendfunc == 0)
        glBlendFunc (GL_SRC_ALPHA, GL_ZERO);
      else if (blendfunc == 1)
        glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
      else
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
      #if 1
      //glDisable (GL_TEXTURE_2D);
      render_blob (sphere, nstrip, stripl, 0);
      //glEnable (GL_TEXTURE_2D);
      #else
      render_torus (1.0, 0.6, 0);
      #endif

      glPushMatrix ();
      glRotatef (rot3, 1.0, 0.0, 0.0);
      glTranslatef (2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();
      glPushMatrix ();
      glRotatef (-rot3, 1.0, 0.0, 0.0);
      glTranslatef (-2.9, 0.0, 0.0);
      render_torus (0.8, 0.5, 0);
      glPopMatrix ();

      rot3 += 1;
      if (rot3 >= 360)
        rot3 -= 360;

      glPopMatrix ();
      
      glKosFinishFrame ();
    }
  
  glKosShutdown ();
  
  pvr_shutdown ();
  
  vid_shutdown ();
  /* Make dc-load look nicer.  */
  vid_init (DM_640x480_PAL_IL, PM_RGB565);

  return 0;
}