OSDN Git Service

first
[psychlops/cpp.git] / psychlops / extension / prototype / graphic / psychlops_g_canvas3d_prototype.cpp
1 /*
2  *  psychlops_g_canvas3d_prototype.cpp
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/10/05 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 //#include <gl/gl.h>
10 #include "../../../psychlops_core.h"
11 #include "../../../platform/gl/psychlops_g_GL_h.h"
12
13 #include "psychlops_g_canvas3d_prototype.h"
14
15
16 namespace Psychlops {
17
18 /*
19         Canvas3D::Canvas3D(void) : has_instance_(false), APIsetColor(0) {
20         }
21         Canvas3D::Canvas3D(CanvasMode mode) : has_instance_(false), APIsetColor(0) {
22                 set(mode);
23         }
24         Canvas3D::Canvas3D(int d_width, int d_height, int d_colordepth, double d_refreshrate, CanvasMode mode) : has_instance_(false), APIsetColor(0) {
25                 set(d_width, d_height, d_colordepth, d_refreshrate, mode);
26         }*/
27         Canvas3D::~Canvas3D(void) {
28                 release();
29         }
30
31                 static void setColor4Through(const Color &color) {
32                         double r,g,b,a;
33                         color.get(r,g,b,a);
34                         glColor4d(r,g,b,a);
35                 }
36                 static void setColorClaer4Through(const Color &color) {
37                         double r,g,b,a;
38                         color.get(r,g,b,a);
39                         glClearColor(r,g,b,a);
40                 }
41
42         void Canvas3D::popMatrixes() {
43                 glMatrixMode(GL_MODELVIEW);
44                 glPopMatrix();
45                 glMatrixMode(GL_PROJECTION);
46                 glPopMatrix();
47         }
48         void Canvas3D::loadOrthoProjection() {
49                 glMatrixMode(GL_PROJECTION);
50                 glPushMatrix();
51                 glOrtho(-0.375, Width-0.375, Height-0.375, -0.375, -1000, 1000);
52                 glMatrixMode(GL_MODELVIEW);
53                 glPushMatrix();
54 //              glDisable(GL_LIGHTING);
55 //              glDisable(GL_DEPTH_TEST);
56         }
57
58         void Canvas3D::initAPIprop() {
59                 switch(colordepth) {
60 /*              case 24:
61                 case 32:
62                         APIsetColor = &(DirectGetColor::setColor4ub);
63                         APIsetColorClear = &(DirectGetColor::setColorClear4ub);
64                         break;*/
65                 default:
66                         APIsetColor = &(setColor4Through);
67                         APIsetColorClear = &(setColorClaer4Through);
68                         break;
69                 }
70
71                 glMatrixMode(GL_PROJECTION);
72                 glLoadIdentity();
73                 glMatrixMode(GL_MODELVIEW);
74                 glLoadIdentity();
75                 loadOrthoProjection();
76
77                 initAPIattributes();
78                 glDrawBuffer(GL_BACK);
79                 glReadBuffer(GL_BACK);
80
81                 GLclampf red=0.0, green=0.0, blue=0.0, alpha=1.0;
82 //              default_drawing_mode_ = GL_POINTS;
83                 glClearColor(red,green,blue,alpha);
84                 clear();
85                 this->Canvas::flip();
86                 clear();
87                 this->Canvas::flip();
88         }
89
90         void Canvas3D::initAPIattributes() {
91                 glPushAttrib(GL_ALL_ATTRIB_BITS);
92
93                 ////    default settings        ////
94                 glShadeModel(GL_FLAT);
95                 glEnable(GL_ALPHA_TEST);
96                 glEnable(GL_BLEND);
97                 glEnable(GL_LINE_STIPPLE);
98                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
99 /*              glDisable(GL_POINT_SMOOTH);
100                 glDisable(GL_LINE_SMOOTH);
101                 glDisable(GL_POLYGON_SMOOTH);
102                 glDisable(GL_DEPTH_TEST);
103                 glDisable(GL_DITHER);
104                 glDisable(GL_FOG);
105                 glDisable(GL_LIGHTING);
106                 glDisable(GL_LOGIC_OP);
107                 glDisable(GL_STENCIL_TEST);
108                 glDisable(GL_TEXTURE_1D);
109                 glDisable(GL_TEXTURE_2D);
110 */              glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
111                 glPixelTransferi(GL_MAP_STENCIL, GL_FALSE);
112                 glPixelTransferi(GL_RED_SCALE, 1);
113                 glPixelTransferi(GL_RED_BIAS, 0);
114                 glPixelTransferi(GL_GREEN_SCALE, 1);
115                 glPixelTransferi(GL_GREEN_BIAS, 0);
116                 glPixelTransferi(GL_BLUE_SCALE, 1);
117                 glPixelTransferi(GL_BLUE_BIAS, 0);
118                 glPixelTransferi(GL_ALPHA_SCALE, 1);
119                 glPixelTransferi(GL_ALPHA_BIAS, 0);
120                 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
121                 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
122                 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
123                 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
124                 glPixelStoref(GL_UNPACK_ALIGNMENT, 4);
125                 glPixelStorei(GL_PACK_ALIGNMENT, 4);
126                 glPixelStoref(GL_PACK_ALIGNMENT, 4);
127                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
128         }
129
130         void Canvas3D::flip(int nextframe) {
131                 popMatrixes();
132                 loadOrthoProjection();
133
134                 glPushAttrib(GL_ALL_ATTRIB_BITS);
135                 glDisable(GL_LIGHTING);
136                 this->Canvas::flip(nextframe);
137                 glPopAttrib();
138
139                 popMatrixes();
140                 loadOrthoProjection();
141         }
142 \r
143 \r
144 \r
145
146 }       /*      <- namespace Psycholops         */