1 /***************************************************************************
2 * Copyright (C) 2005 by Dimitris Saougos & Filippos Papadopoulos *
3 * <psybases@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 #define GL_GLEXT_PROTOTYPES 1
27 #ifdef _WIN32 // an eimaste se Windows
29 #define _USE_MATH_DEFINES
32 /* #define GLX_GLXEXT_PROTOTYPES
34 #include <GL/glxext.h> */
69 This struct represents a 3D vertex
72 <COLOUR_RGBA>, <Graphics::renderVertexArray>, <Graphics::renderTriangle>*/
82 direction of the normal vector for the vertex */
85 3D coordinates for the vertex*/
93 float camx, camy, camz;
94 float lookx, looky, lookz;
103 <Graphics::setLight>, <Graphics::showLight>, <COLOUR_RGBA>*/
107 the type of light. _type_ can be one of
109 + *AM_POINT_LIGHT* specifies a point light. This type of light has a position within the scene but no single direction.
110 They emit their light in all directions. Think of a light-bulb in your house ;)
111 + *AM_DIRECTIONAL_LIGHT* specifies a directional light. This type of light has a direction but not position.
113 + *AM_SPOT_LIGHT* specifies a spot light. *NOTE* currently, spot light is partially implemented. */
116 the diffuse RGBA intensity of the light */
119 the specular RGBA intensity of the light*/
122 the ambient RGBA intensity of the light*/
124 /*fields: posx,posy,posz
125 the position of the point light. *Only* for point lights*/
126 float posx,posy,posz;
128 /*fields: dirx,diry,dirz
129 the direction of the directional light. *Only* for directional lights */
130 float dirx,diry,dirz;
132 only for spot lights*/
134 /*fields: falloff,theta,phi
135 only for spot lights*/
136 float falloff,theta,phi;
140 #define AM_POINT_LIGHT 1
141 #define AM_DIRECTIONAL_LIGHT 2
142 #define AM_SPOT_LIGHT 3
144 #define AM_SOFTWARE_PARTICLE 4
145 #define AM_HARDWARE_PARTICLE 5
147 #define AM_CULL_FRONT 6
148 #define AM_CULL_BACK 7
149 #define AM_CULL_NONE 8
153 #define AM_ANISOTROPIC 11
155 #define AM_TRIANGLE_STRIP 12
156 #define AM_TRIANGLE_FAN 13
157 #define AM_TRIANGLES 14
158 #define AM_POINT_LIST 15
159 #define AM_LINE_LIST 16
160 #define AM_LINE_STRIP 17
180 /*function: COLOUR_RGBA
183 r,g,b,a - the Red, Green, Blue and Alpha colour components */
184 extern colour COLOUR_RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a );
202 Font(const char *name, int size, Graphics *g);
204 void print( const wchar_t *str, int x1, int y1, int x2, int y2, colour c );
205 void print( char *str, int x1, int y1, int x2, int y2, colour c );
209 /* FTGLTextureFont *font;
220 This class is the core class of the Amaltheia library. It handles the display and
221 via its methods you can render 2D and 3D primitives.
228 /* group: Constructors*/
229 /* constructor: Graphics
232 width - the desired width of the display's resolution
233 height - the desired height of the display's resolution
234 fullScreen - if *true* run in full screen, otherwise in a window
235 bpp - the desired Bits Per Pixel for the display
236 alpha - enables/disables alpha blending
237 lighting - enables/disables lighting
241 Graphics( int width = 1024, int height = 768, int bpp = 16, bool fullScreen = false,
242 bool alpha = false, bool lighting = false );
249 Sets the width of the display
252 w - the desired width
256 void setWidth( int w = 1024 );
259 Returns the width of the display
262 the current display's width in pixels
269 Sets the height of the display
272 h - the desired height
276 void setHeight( int h = 768 );
279 Returns the height of the display
282 the height of the display in pixels
289 Sets the Bits per Pixel for the display
296 void setBpp( int bpp = 16);
299 Returns the current BPP of the display
308 void enableVsync( bool b);
312 void enableFullScreen( bool b);
315 /*method: enableLighting
316 Enables/disables lighting in the scene
319 *true* to enable lighting or *false* to disable it
323 void enableLighting( bool );
329 *true* if lighting is enabled, *false* otherwise
335 /*method: enableDepthBuffer
336 Enables/disables the depth (Z) buffer
339 *true* to enable the Z-buffer, *false* to disable it
343 void enableDepthBuffer( bool );
345 /*method: isDepthBuffer
346 Is the depth buffer enabled?
349 *true* if the depth buffer is enabled, *false* otherwise
352 <enableDepthBuffer> */
353 bool isDepthBuffer();
355 /*method: enableAlpha
356 Enables/disables alpha blending
359 *true* to enable alpha blending, *false* to disable it
363 void enableAlpha( bool );
366 Is alpha blending enabled?
369 *true* is alpha blending is enabled, *false* otherwise
376 void enableCursor( bool );
380 /* method: createDisplay
381 Creates the display. You should call this method *once*.
388 You must call this method before starting drawing/rendering primitives to the display.
389 This method does some initializations e.g clears the color and depth buffers, etc...
396 You must call this method after you have finished rendering the current frame and you want
397 to be visible on the screen. <beginScene> and <endScene> methods must be pair, so you must
398 call <beginScene> once, before calling <endScene>.
407 Sets the world tranformations matrices (translation, rotation, scale)
410 transx - number of units to translate in the X axis
411 transy - number of units to translate in the Y axis
412 transz - number of units to translate in the Z axis
413 rotx - degrees to rotate in the X axis
414 roty - degrees to rotate in the Y axis
415 rotz - degrees to rotate in the Z axis
416 scalex - scale factor in the X axis (a factor of 1.0 performs no scale)
417 scaley - scale factor in the Y axis
418 scalez - scale factor in the Z axis */
419 int setWorld( float transx, float transy, float transz,
420 float rotx, float roty, float rotz,
421 float scalex, float scaley, float scalez, int rotationOrder = AM_XYZ);
425 int setWorld2( float transx, float transy, float transz,
426 float rotx, float roty, float rotz,
427 float scalex, float scaley, float scalez );
433 Specifies the position and the direction of the camera.
436 camx - the x coordinate of the camera position
437 camy - the y coordinate of the camera position
438 camz - the z coordinate of the camera position
439 lookx - the x coordinate of the reference point
440 looky - the y coordinate of the reference point
441 lookz - the z coordinate of the reference point
442 upx - the x coordinate of the up vector
443 upy - the y coordinate of the up vector
444 upz - the z coordinate of the up vector
448 int setCamera( float camx, float camy, float camz,
449 float lookx, float looky, float lookz,
450 float upx, float upy, float upz );
453 Returns a <camera> struct containing the position and the direction of the camera
460 struct camera getCamera();
463 /*method: setBackground
464 Sets the background colour of the display.
467 c - the colour to set. Use the COLOUR_RGBA() macro to specify it
471 void setBackground( colour c );
473 /* method: getBackground
476 the colour of the display background
480 colour getBackground();
482 /* method: setTexture
483 Sets which will be the current texture to use.
486 tex - a pointer to a <Texture> object
489 <getTexture>, <Texture> class*/
490 void setTexture( Texture *tex );
495 a pointer to the current <Texture> object
498 <setTexture>, <Texture> class */
499 Texture* getTexture();
501 /*method: setCullingMode
502 Specifies the culling mode to use, whether front or back facets will be culled.
503 The orientation of front-facing polygons is clock-wise.
506 mode - the desired culling mode
508 valid values for _mode_ are
510 + *AM_CULL_BACK* for culling back facets
511 + *AM_CULL_FRONT* for culling front facets
512 + *AM_CULL_NONE* for culling none of the facets
516 void setCullingMode(int mode);
518 /*method: getCullingMode
521 The current culling mode
525 int getCullingMode();
528 /*method: renderTriangle
529 Renders a triangle in the display
532 v1, v2, v3 - the 3 vertices that specify the triangle
535 <vertex> struct, <renderVertexArray> */
536 int renderTriangle(vertex v1, vertex v2, vertex v3 );
538 /*method: renderVertexArray
539 Renders a mesh of vertices
542 array - an array containing the vertices
543 numOfVertices - the number of vertices in the array
544 type - how to connect the vertices
547 valid values for _type_ are
549 + *AM_TRIANGLE_STRIP* renders a connected group of triangles. One triangle is defined for each vertex
550 presented after the first two vertices. For odd i, vertices i, i+1, and i+2 define triangle i.
551 For even i, vertices i+1, i, and i+2 define triangle i. 'numOfVertices-2' triangles are rendered
552 + *AM_TRIANGLE_FAN* renders a connected group of triangles. One triangle is defined for each vertex
553 presented after the first two vertices. Vertices 1, i+1, and i+2 define triangle i. 'numOfVertices/-2' triangles are rendered
554 + *AM_TRIANGLES* renders each triplet of vertices as an independent triangle.
555 Vertices 3i-2, 3i-1, and 3i define triangle i. 'numOfVertices/3' triangles are rendered
556 + *AM_POINT_LIST* renders each vertex as a single point. Vertex i defines point i. 'numOfVertices' points are rendered
557 + *AM_LINE_LIST* renders each pair of vertices as an independent line segment.
558 Vertices 2i-1 and 2i define line i. 'numOfVertices/2' lines are rendered
559 + *AM_LINE_STRIP* renders a connected group of line segments from the first vertex to the last. Vertices i and i+1 define line i. 'numOfVertices - 1' lines are rendered
562 <renderTriangle>, <vertex> struct */
563 void renderVertexArray(vertex *array, unsigned int numOfVertices, int type);
569 Creates a new light numbered 'numLight' with the properties defined in 'lt'
572 numLight - Specifies a light number. The number of lights depends on the underlying implementation,
573 but at least eight lights are supported. They are identified by integers 0 .. maximum lights
575 lt - a struct <light> variable which defines the properties of the 'numLight' light
578 struct <light>, <showLight>*/
579 void setLight( int numLight, const light& lt );
582 Enables/disables light 'numLight'. Light 'numLight' must first have been created with the <setLight> method.
585 numLight - the number of the light to enable/disable
587 state - *true* to enable the light, *false* otherwise
590 struct <light>, <setLight>*/
591 void showLight( int numLight, bool state );
593 /*method: renderParticle
594 Renders a particle in the display
597 x - the x coordinate of the particle position
599 y - the y coordinate of the particle position
601 z - the z coordinate of the particle position
603 size - size of the particle
605 col - colour of the particle
607 type - can be *AM_SOFTWARE_PARTICLE* or *AM_HARDWARE_PARTICLE*
610 <renderParticleArray>*/
611 void renderParticle(float x, float y, float z, float size, colour col, int type);
613 /*method: renderParticleArray
614 Useful for rendering lots of particles
617 array - the array of particles
619 sizeOfArray - guess what...
621 type - can be *AM_SOFTWARE_PARTICLE* or *AM_HARDWARE_PARTICLE*
625 void renderParticleArray(particle *array, unsigned int sizeOfArray, int type);
626 void setPerspective(float fov, float ratio, float zNear, float zFar);
629 void project( float objx, float objy, float objz,
630 float *winx, float *winy, float *winz );
632 /*method: unproject*/
633 void unproject( float winx, float winy, float winz,
634 float *objx, float *objy, float *objz );
636 /*method: planeIntersect*/
637 void planeIntersect( float a, float b, float c, float d,
638 float p1x, float p1y, float p1z, float p2x, float p2y, float p2z,
639 float *poutx, float *pouty, float *poutz );
641 /*method: enter2dMode*/
643 /*method: leave2dMode*/
647 static bool oneGraphics; //gia na dhmiourgeitai mono ena antikeimeno Graphics
659 Texture *currentTexture;
661 bool sceneBegin; //flag gia to an egine sceneBegin
665 float maxSize; //point size gia particles me point pixel
666 void drawBillboardParticle(float x, float y, float z, float size, colour col);
668 //SDL_Surface *screen;
677 A class for representing 2d textures
687 int filtering, filteringDefinition;
688 bool colourKeyEnabled;
690 unsigned long height;
693 //void swap( unsigned char &a, unsigned char &b );
694 // void CreateTexture( unsigned int textureArray[], char *strFileName, int textureID );
695 // int ImageLoad( const char *filename, Image *image );
696 void LoadGLTextures( unsigned int *gl_Tex, const char * filename );
698 friend void Graphics::setTexture( Texture *tex );
704 /* group: Constructors*/
707 /* constructor: Texture
708 Creates a texture from an image file
711 file - the filename of the image to use as a texture. Accepted formats are PNG, TGA, BMP, JPG, DDS.
712 g - a pointer to a Graphics object*/
713 Texture( char *file, Graphics *g);
714 /* constructor: Texture
715 Creates a texture from an image file
718 file - the filename of the image to use as a texture. Accepted formats are PNG, TGA, BMP, JPG.
719 key - the colour key to use
720 g - a pointer to a Graphics object*/
721 Texture( char *file, colour key, Graphics *g);
722 /* constructor: Texture
723 Creates a texture from memory
726 data - a pointer to the textures data
727 w - the width of the texture
728 h - the height of the texture
729 format - the format of the pixels in _data_. Accepted values are AM_RGBA, AM_ALPHA
730 type - currently the one supported type is AM_BYTE
731 g - a pointer to a Graphics object*/
732 Texture(void *data, unsigned int w, unsigned int h, int format, int type, Graphics *g);
736 void texSubImage2D(int xoff, int yoff, unsigned int w, unsigned int h, int format, int type, const void *pixels);
737 void setFiltering(int f, float anisotropyLevel = 1.0);
742 unsigned long getWidth();
746 unsigned long getHeight();
747 //unsigned int gl_getGLTex();