Hello everyone,
I have recently witten a ray tracer for a school project (I am working with Windows XP). Currently, I am simply writing my images out to .bmp files. However, I really want to display them on the screen using OpenGL and GLUT. All the images created by my program are represented by my Image class. The .h header for my Image class is shown below:

/**
*  Class for representing 2d images with alpha blending. Uses float precision.
*
*  @author Colin Braley
*  @date Feb 6, 2008
*/
class Image {

public:

    /**
    * Create a new image with the specified width and height (in pixels).
    * The image will be filled completeley with the specified color.
    * 
    * @param theWidth is the width of the image in pixels.  This defaults to 100.
    * @param theHeight is the height of the image in pixels.  This defaults to 100.
    * @param bgColor is the Color the image should be filled with.  Defaults to (0,0,0,0).
    */
    Image(unsigned int theWidth = 100, unsigned int theHeight = 100,
        Color bgColor = Color(0,0,0,0));

    /**
    * Copy constructor for the Image class.  Copies the image specified
    * by the parameter "other" into the Image being constructed.  This copy
    * is a "deep copy," not a bitwise copy.
    * 
    * @param other is the Image to copy
    */
    Image(const Image& other);

    /**
    * Overloaded assignment operator.  Provides "deep copying" of images.
    * 
    * @param other is the Image to copy
    * @return a reference to the current Image, to allow chained assignment.
    */
    Image& operator=(const Image& other);

    /**
    * Image destructor.  Deallocates all memory associated with the image.
    * Should not be called by client code under normal circumstances.
    */
    virtual ~Image();

    /**
    * Get the color of the image pixel located at (x,y) where the coordinate system in use
    * is defined as having its origin in the upper left-hand corner of the image.
    * 
    * @param x is the zero-based x coordinate of the pixel to sample
    * @param y is the zero-based y coordinate of the pixel to sample
    * @return the Color at the location
    * @precondition is that the coordinate (x,y) is within rage, otherwise an assertion will fail
    */
    Color getColorAt(unsigned int x, unsigned int y) const;

    /**
    * Set the color of the image pixel located at (x,y) where the coordinate system in use
    * is defined as having its origin in the upper left-hand corner of the image.
    * 
    * @param x is the zero-based x coordinate of the pixel to set
    * @param y is the zero-based y coordinate of the pixel to set
    * @param newColor is the new color to be put at the specified pixel
    * @precondition is that the coordinate (x,y) is within rage, otherwise an assertion will fail
    */
    void setColorAt(unsigned int x, unsigned int y, Color& newColor);

    /**
    * Get the width(in pixels) of the Image.
    * 
    * @return the width as an unsigned int
    */
    unsigned int getWidth() const;

    /**
    * Get the height(in pixels) of the Image.
    * 
    * @return the height as an unsigned int
    */
    unsigned int getHeight() const;

    /**
    * Fills the image with the specified color.
    * 
    * @param newColor is the color to fill the image with.
    */
    void fillImage(Color& newColor);

    /**
    * Invert the colors in the image.
    */
    void invert(bool includeAlpha = false);

    /**
    * Desaturate the specified image.
    */
    void desaturate();

    /**
    * Brightens the image by the amount specified by "add."  YOu can brighten specified
    * channels of the image only through the bool parameters of the method.
    * 
    * @param add is added to the image
    * @param affectRed is true if you want to brightn the red channel, false otherwise.  
    * Defaults to true.
    * @param affectGreen is true if you want to brightn the green channel, false otherwise.
    *  Defaults to true.
    * @param affectBlue is true if you want to brightn the blue channel, false otherwise.  
    * Defaults to true.
    * @param affectAlpha is true if you want to brightn the alpha channel, false otherwise. 
    * Defaults to false.
    */
    void brighten(float add, bool affectRed = true, bool affectGreen = true,
        bool affectBlue = true, bool affectAlpha = false);

    /**
    * Darkens the image by the amount specified by "add."  YOu can brighten specified
    * channels of the image only through the bool parameters of the method.
    * 
    * @param subtract is subtracted from the image
    * @param affectRed is true if you want to darken the red channel, false otherwise.  
    * Defaults to true.
    * @param affectGreen is true if you want to darken the green channel, false otherwise.  
    * Defaults to true.
    * @param affectBlue is true if you want to darken the blue channel, false otherwise.   
    * Defaults to true.
    * @param affectAlpha is true if you want to darken the alpha channel, false otherwise.  
    * Defaults to false.
    */
    void darken(float subtract, bool affectRed = true,
        bool affectGreen = true, bool affectBlue = true,
        bool affectAlpha = false);

    /**
    * Convert the specified image to a black-and-white binary image.
    */
    void toBinary();


    /**
      * Writes the image to a .bmp file located in the working directory.
      * 
      * @param imageName is the name you want the file to have, not including .bmp
      * @return true if succesful, false otherwise
      */
	bool writeToBmp(string imageName) const;

   /**
    *  Return a pointer to the pixel array.  May be useful for OpenGL.
    *  
    *  @return a pointer to a 1d array of Color objects.
    */
    Color* getPixPointer() const;

    private:
    unsigned int width;
    unsigned int height;
    unsigned int totalPix;
    Color* pix;
};

This class makes use of a Color class I created, which simply represents RGBA colors with float precision. Each channel is represented by a float in the range [0,1.0]. The code for this class is given below:

/**
* RGBA Color class using float precision.
* Note that a color channel value of 1.0 indicates 100% of that color.
* Also, note that an alpha channel value of 0.0 inicates transparecy
* 
* @author Colin Braley
* @version 1.0 - Febuary 6, 2008
*
*/
class Color {

public:
    float r, g, b, a;//No need for accessors or modifers for something this simple

    enum basicColors { RED , GREEN , BLUE , YELLOW , BLACK , WHITE , ORANGE , GRAY };//Used for constructor
    
    //-----------------------------------------------------

    /**
    * Default constructor for the Color class.  Creates an all back color 
    * with a non-transparent alpha channel.
    * This default color is represented by r = g = b = 0 and a = 1.
    */
    Color();

    //-----------------------------------------------------

    /**
     *  Constructor for creating a Color consisting of a basic Color.
     *  Uses the basicColors enum.  Colors produced by this are initially
     *  non-transparent.
     *
     *  @param fillColor is a value from the enum such as RED or GREEN
     */
    Color( basicColors fillColor );

    //-----------------------------------------------------

    /**
    * Create a color with the specified r, g, b, and a components.
    *
    * @param myR is the amount of red, ranging from 0 red to 1.0 (full red)
    * @param myG is the amount of green, ranging from 0 green to 1.0 (full green)
    * @param myB is the amount of blue, ranging from 0 blue to 1.0 (full blue)
    * @param myA is the amount of opacity, ranging from 0 (fully transpareent)
    *    to 1.0 (fully opaque)
    */
    Color( float myR, float myG, float myB, float myA = 1 );

    //-----------------------------------------------------

    /**
    * Color destructor.  Deallocates all memory associated with the current Color.
    */
    virtual ~Color();

    //-----------------------------------------------------

    /**
     *  Compare two colors for equality.  Two colors will be considererd
     *  equal IFF each of their color channel values differs by less than
     *  the prescribed tolerance in Constants.h
     *
     *  @param other is the color to compare to *this
     *  @return true if they are equal, false otherwise
     */
    bool operator==(Color& other) const;

    //-----------------------------------------------------

     /**
     *  Compare two colors for inequality.  Two colors will be considererd
     *  unequal IFF each of their color channel differ by more than the 
     *  prescribed difference in Constants.h
     *
     *  @param other is the color to compare to *this
     *  @return true if they are equal, false otherwise
     */
    bool operator!=(Color& other) const;

    //-----------------------------------------------------

    /**
     *  Invert the color.
     *
     * @param includeAlpha is whether to also invert the alpha channel.  Defaults to false.
     */
    void invert(bool includeAlpha = false);
};

Note that if anyone requests, I can supply the .cpp implementation files for these classes.


Anyway, given an object of the Image class, I need to draw it to the screen using GLUT and OpenGL. Curently when I try to draw an Image all I get is a bunch of strangely colored pixels, which to not match up with the results I get when writing the image out to a .bmp. If anyone needs, I can post my attempt at drawing the Image to screen with OGL and GLUT, but I won't post it now for brevity's sake. Thanks in advance for the help, and sorry for the long post.


~Colin Braley
<url snipped>

Hello everyone,
I have recently witten a ray tracer for a school project (I am working with Windows XP). Currently, I am simply writing my images out to .bmp files. However, I really want to display them on the screen using OpenGL and GLUT. All the images created by my program are represented by my Image class. The .h header for my Image class is shown below:

Hellow ..
dear i need your help in graphics ..designing in my C++ project .. i need that cpp file also you mentioned in this post .. i shall be grateful to you , if you can send me thsee files over my gmail id <snipped email>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.