home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / OpenGL / fadeflip / texture.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.7 KB  |  177 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include <GL/glu.h>
  38. #include <GL/glx.h>
  39.  
  40. extern "C" {
  41. #include "myimage.h"
  42. };
  43.  
  44. #define DEFAULT_DISPLAY_TYPE        GL_UNSIGNED_BYTE
  45. #define DEFAULT_DISPLAY_FORMAT        GL_RGBA
  46. #define DEFAULT_ALIGNMENT        1
  47. #define DEFAULT_COMPONENTS        4
  48. #define DEFAULT_LEVEL            0
  49.  
  50. #define DEFAULT_ENVIRONMENT        GL_MODULATE
  51.  
  52. #define DEFAULT_MIN_FILTER        GL_LINEAR
  53. #define DEFAULT_MAX_FILTER        GL_LINEAR
  54.  
  55. class texture {
  56.  public:
  57.   texture();
  58.   ~texture();
  59.   
  60.   void open();
  61.  
  62.   void set_display_format(GLenum new_display_format);
  63.   GLenum get_display_format();
  64.  
  65.   void set_display_type(GLenum new_display_type);
  66.   GLenum get_display_type();
  67.  
  68.   void set_alignment(int new_alignment);
  69.   int get_alignment();
  70.  
  71.   void set_components(int new_components);
  72.   int get_components();
  73.  
  74.   void set_level(int new_level);
  75.   int get_level();
  76.  
  77.   void set_environment(GLenum new_environment);
  78.   GLenum get_environment();
  79.  
  80.   void set_min_filter(GLenum new_min_filter);
  81.   GLenum get_min_filter();
  82.   void set_max_filter(GLenum new_max_filter);
  83.   GLenum get_max_filter();
  84.  
  85.   int get_width();
  86.   int get_height();
  87.  
  88.   void create_color(int total_size,
  89.             float r, float g, float b, float a, float l);
  90.   void create_checkerboard(int total_size, int block_size,
  91.                float r1 = 1.0, float g1 = 0.0, float b1 = 0.0,
  92.                float alpha1 = 1.0, float lum1 = 0.299,
  93.                float r2 = 0.0, float g2 = 0.0, float b2 = 1.0,
  94.                float alpha2 = 1.0, float lum2 = 0.114);
  95.   void create_diag_stripes(int total_size, int stripe_width,
  96.                float r1 = 1.0, float g1 = 0.0, float b1 = 0.0,
  97.                float alpha1 = 1.0, float lum1 = 0.299,
  98.                float r2 = 0.0, float g2 = 0.0, float b2 = 1.0,
  99.                float alpha2 = 1.0, float lum2 = 0.114);
  100.   void create_from_file(char *fname);
  101.  
  102.   void map_lum_to_alpha();
  103.  
  104.   void draw_pixels();
  105.   void draw_pixels(int x1, int y1, int x2, int y2);
  106.  
  107.   /* setup_texture() sets up the alignment etc */
  108.   void setup_texture();
  109.   void setup_texture(int x1, int y1, int x2, int y2);
  110.  
  111.   /* specify_texture():
  112.    * 1. Calls setup_texture()
  113.    * 2. Calls glTexImage2D() with a level of level if min_filter is 
  114.    * GL_NEAREST or GL_LINEAR, otherwise calls gluBuild2DMipmaps() */
  115.   void specify_texture();
  116.   void specify_texture(int x1, int y1, int x2, int y2);
  117.  
  118.   /* specify_mipmap()
  119.    * Calls glTexImage2D() with a level of level */
  120.   void specify_mipmap();
  121.   void specify_mipmap(int x1, int y1, int x2, int y2);
  122.  
  123.   void pixels_free();
  124.  
  125.  private:
  126.   void pixels_alloc();
  127.   void pixels_alloc(int size);
  128.  
  129.   void assign_pixel(int x, int y, float r, float g, float b, float a,
  130.             float l);
  131.   void assign_pixel(int x, int y, float r, float g, float b, float a,
  132.             float l, GLenum display_format,
  133.             GLenum display_type, int alignment);
  134.  
  135.   inline void assign_pixel_a(int x, int y, float a);
  136.  
  137.   void reformat(GLenum new_display_format, GLenum new_display_type,
  138.         int new_alignment);
  139.  
  140.   int row_length();
  141.   int row_length(GLenum display_format, GLenum display_type, 
  142.          int alignment);
  143.  
  144.   inline float pixel_r(int x, int y);
  145.   inline float pixel_r(int x, int y, GLenum display_format,
  146.                GLenum display_type, int alignment);
  147.  
  148.   inline float pixel_g(int x, int y);
  149.   inline float pixel_g(int x, int y, GLenum display_format,
  150.                GLenum display_type, int alignment);
  151.  
  152.   inline float pixel_b(int x, int y);
  153.   inline float pixel_b(int x, int y, GLenum display_format,
  154.                GLenum display_type, int alignment);
  155.  
  156.   inline float pixel_alpha(int x, int y);
  157.   inline float pixel_alpha(int x, int y, GLenum display_format,
  158.                GLenum display_type, int alignment);
  159.  
  160.   inline float pixel_lum(int x, int y);
  161.   inline float pixel_lum(int x, int y, GLenum display_format,
  162.              GLenum display_type, int alignment);
  163.  
  164.   int height, width;
  165.   GLvoid *pixels;
  166.   int pixels_size;
  167.   GLenum display_format;
  168.   GLenum display_type;
  169.   int alignment;
  170.   int components;
  171.   int level;
  172.  
  173.   GLenum environment;
  174.  
  175.   GLenum min_filter, max_filter;
  176. };
  177.