39 struct viewport_params
47 glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
49 unsigned char* pixelbuffer = (
unsigned char*) malloc( viewport.x * viewport.y * 4 );
54 glPixelStorei( GL_PACK_ALIGNMENT, 1 );
55 glReadBuffer( GL_BACK_LEFT );
57 glReadPixels( viewport.originX, viewport.originY, viewport.x, viewport.y, GL_RGBA,
58 GL_UNSIGNED_BYTE, pixelbuffer );
60 unsigned char* rgbBuffer = (
unsigned char*) malloc( viewport.x * viewport.y * 3 );
61 unsigned char* alphaBuffer = (
unsigned char*) malloc( viewport.x * viewport.y );
63 unsigned char* rgbaPtr = pixelbuffer;
64 unsigned char* rgbPtr = rgbBuffer;
65 unsigned char* alphaPtr = alphaBuffer;
67 for(
int y = 0; y < viewport.y; y++ )
69 for(
int x = 0; x < viewport.x; x++ )
71 rgbPtr[0] = rgbaPtr[0];
72 rgbPtr[1] = rgbaPtr[1];
73 rgbPtr[2] = rgbaPtr[2];
74 alphaPtr[0] = rgbaPtr[3];
87 aDstImage.SetData( rgbBuffer, viewport.x, viewport.y,
false );
88 aDstImage.SetAlpha( alphaBuffer,
false );
92 aDstImage = aDstImage.Mirror(
false );
98 unsigned char* rgbaBuffer = (
unsigned char*) malloc( aImage.
GetWidth() *
101 unsigned char* dst = rgbaBuffer;
102 const unsigned char* ori = aImage.
GetBuffer();
106 unsigned char v = *ori;
118 glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
119 glPixelStorei( GL_PACK_ALIGNMENT, 4 );
121 glGenTextures( 1, &texture );
122 glBindTexture( GL_TEXTURE_2D, texture );
124 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aImage.
GetWidth(), aImage.
GetHeight(), 0, GL_RGBA,
125 GL_UNSIGNED_BYTE, rgbaBuffer );
127 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
128 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
129 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
130 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
132 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
134 glBindTexture( GL_TEXTURE_2D, 0 );
157 const float shininess =
160 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
161 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
162 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
163 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
164 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shininess );
169 bool aUseSelectedMaterial,
SFVEC3F aSelectionColor )
172 const SFVEC4F diffuse =
SFVEC4F( aUseSelectedMaterial ? aSelectionColor : aMaterialDiffuse,
177 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
178 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
179 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
180 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
181 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 0.0f );
187 glMatrixMode( GL_PROJECTION );
190 glMatrixMode( GL_MODELVIEW );
193 glDisable( GL_LIGHTING );
194 glDisable( GL_COLOR_MATERIAL );
195 glDisable( GL_DEPTH_TEST );
196 glDisable( GL_TEXTURE_2D );
197 glDisable( GL_BLEND );
198 glDisable( GL_ALPHA_TEST );
201 glColor4f( aTopColor.r, aTopColor.g, aTopColor.b, aTopColor.a );
202 glVertex2f( -1.0, 1.0 );
204 glColor4f( aBotColor.r, aBotColor.g, aBotColor.b, aBotColor.a );
205 glVertex2f( -1.0,-1.0 );
206 glVertex2f( 1.0,-1.0 );
208 glColor4f( aTopColor.r, aTopColor.g, aTopColor.b, aTopColor.a);
209 glVertex2f( 1.0, 1.0 );
216 if( !glActiveTexture || !glClientActiveTexture )
217 throw std::runtime_error(
"The OpenGL context no longer exists: unable to Reset Textures" );
219 glActiveTexture( GL_TEXTURE0 );
220 glBindTexture( GL_TEXTURE_2D, 0 );
221 glClientActiveTexture( GL_TEXTURE0 );
222 glDisable( GL_TEXTURE_2D );
223 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
227 glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
static_cast<const float*
>( &zero.x ) );
Manage an 8-bit channel image.
unsigned char * GetBuffer() const
Get the image buffer pointer.
unsigned int GetHeight() const
unsigned int GetWidth() const
void OglGetScreenshot(wxImage &aDstImage)
Get the pixel data of current OpenGL image.
void OglResetTextureState()
Reset to default state the texture settings.
void OglSetDiffuseMaterial(const SFVEC3F &aMaterialDiffuse, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor)
Sets only the diffuse color and keep other parameters with default values.
void OglSetMaterial(const SMATERIAL &aMaterial, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor)
Set OpenGL materials.
GLuint OglLoadTexture(const IMAGE &aImage)
Generate a new OpenGL texture.
void OglDrawBackground(const SFVEC4F &aTopColor, const SFVEC4F &aBotColor)
Define generic OpenGL functions that are common to any OpenGL target.
includes in a proper way the openGL related includes
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.