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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1884 - (view) (download) (as text)

1 : jhr 1884 /*! \file load-png.h
2 :     *
3 :     * \brief This file defines a simple texture loading API on top of libpng.
4 :     *
5 :     * \author John Reppy
6 :     */
7 :    
8 :     /*
9 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
10 :     * All rights reserved.
11 :     */
12 :    
13 :     #ifndef _LOAD_PNG_H_
14 :     #define _LOAD_PNG_H_
15 :    
16 :     #if defined(__APPLE__) && defined(__MACH__)
17 :     # include <OpenGL/gl.h>
18 :     #else
19 :     # define GL_GLEXT_PROTOTYPES
20 :     # include <GL/gl.h>
21 :     #endif
22 :     #include <stdint.h>
23 :     #include <stdbool.h>
24 :    
25 :     //! \brief image formats
26 :     typedef enum {
27 :     GRAY_IMAGE = GL_LUMINANCE, /*!< grayscale */
28 :     GRAY_ALPHA_IMAGE = GL_LUMINANCE_ALPHA, /*!< grayscale with alpha channel */
29 :     RGB_IMAGE = GL_RGB, /*!< RGB image */
30 :     RGBA_IMAGE = GL_RGBA /*!< RGBA image */
31 :     } ImageFormat_t;
32 :    
33 :     //! \brief a 2D image
34 :     typedef struct {
35 :     uint32_t wid; //!< the image width
36 :     uint32_t ht; //!< the image height
37 :     ImageFormat_t fmt; //!< the format of the image
38 :     GLenum type; //!< the type of the channel data; will be either GL_UNSIGNED_BYTE
39 :     //! or GL_UNSIGNED_SHORT.
40 :     uint8_t *data; //!< the image data
41 :     } Image2D_t;
42 :    
43 :     /*! \brief Load an image with the requested format from the named file.
44 :     * \param file the path to the PNG file to be loaded
45 :     * \param fmt the requested format of the file.
46 :     * \return the loaded image or 0 if there was an error loading the file.
47 :     */
48 :     extern Image2D_t *LoadImage (const char *file, bool flip, ImageFormat_t fmt);
49 :    
50 :     /*! \brief Free the storage allocated for an image.
51 :     * \param img the image to be freed.
52 :     */
53 :     extern void FreeImage (Image2D_t *img);
54 :    
55 :     /*! \brief specify a two-dimensional texture image for the current texture unit.
56 :     * \param img the image to load into the texture unit.
57 :     * \return returns 0 (GL_NO_ERROR) if there is no error; otherwise returns the
58 :     * OpenGL error code.
59 :     *
60 :     * To use this function, you should us glBindTexture to make current the OpenGL texture
61 :     * that you wish to load.
62 :     */
63 :     extern int TexImage (Image2D_t *img);
64 :    
65 :     #endif /* !_LOAD_PNG_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0