Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /examples/util/load-png.h
ViewVC logotype

View of /examples/util/load-png.h

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3349 - (download) (as text) (annotate)
Tue Oct 27 15:16:36 2015 UTC (4 years, 10 months ago) by jhr
File size: 2039 byte(s)
making copyrights consistent for all code in the repository
/*! \file load-png.h
 * \brief This file defines a simple texture loading API on top of libpng.
 * \author John Reppy

 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.

#ifndef _LOAD_PNG_H_
#define _LOAD_PNG_H_

#if defined(__APPLE__) && defined(__MACH__)
#  include <OpenGL/gl.h>
#  include <GL/gl.h>
#include <stdint.h>
#include <stdbool.h>

//! \brief image formats
typedef enum {
    GRAY_IMAGE = GL_LUMINANCE,			/*!< grayscale */
    GRAY_ALPHA_IMAGE = GL_LUMINANCE_ALPHA,	/*!< grayscale with alpha channel */
    RGB_IMAGE = GL_RGB,				/*!< RGB image */
    RGBA_IMAGE = GL_RGBA			/*!< RGBA image */
} ImageFormat_t;

//! \brief a 2D image
typedef struct {
    uint32_t		wid;	//!< the image width
    uint32_t		ht;	//!< the image height
    ImageFormat_t	fmt;	//!< the format of the image
    GLenum		type;	//!< the type of the channel data; will be either GL_UNSIGNED_BYTE
				//!  or GL_UNSIGNED_SHORT.
    uint8_t		*data;	//!< the image data
} Image2D_t;

/*! \brief Load an image with the requested format from the named file.
 *  \param file the path to the PNG file to be loaded
 *  \param fmt the requested format of the file.
 *  \return the loaded image or 0 if there was an error loading the file.
extern Image2D_t *LoadImage (const char *file, bool flip, ImageFormat_t fmt);

/*! \brief Free the storage allocated for an image.
 *  \param img the image to be freed.
extern void FreeImage (Image2D_t *img);

/*! \brief specify a two-dimensional texture image for the current texture unit.
 *  \param img the image to load into the texture unit.
 *  \return returns 0 (GL_NO_ERROR) if there is no error; otherwise returns the
 *          OpenGL error code.
 * To use this function, you should us glBindTexture to make current the OpenGL texture
 * that you wish to load.
extern int TexImage (Image2D_t *img);

#endif /* !_LOAD_PNG_H_ */

ViewVC Help
Powered by ViewVC 1.0.0