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

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