39 struct viewport_params
47 glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
49 unsigned char* pixelbuffer = (
unsigned char*) malloc( viewport.x * viewport.y * 3 );
54 glPixelStorei( GL_PACK_ALIGNMENT, 1 );
55 glReadBuffer( GL_BACK_LEFT );
57 glReadPixels( viewport.originX, viewport.originY, viewport.x, viewport.y, GL_RGB,
58 GL_UNSIGNED_BYTE, pixelbuffer );
65 aDstImage.SetData( pixelbuffer, viewport.x, viewport.y,
false );
67 aDstImage = aDstImage.Mirror(
false );
73 unsigned char* rgbaBuffer = (
unsigned char*) malloc( aImage.
GetWidth() *
76 unsigned char* dst = rgbaBuffer;
77 const unsigned char* ori = aImage.
GetBuffer();
81 unsigned char v = *ori;
93 glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
94 glPixelStorei( GL_PACK_ALIGNMENT, 4 );
96 glGenTextures( 1, &texture );
97 glBindTexture( GL_TEXTURE_2D, texture );
99 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aImage.
GetWidth(), aImage.
GetHeight(), 0, GL_RGBA,
100 GL_UNSIGNED_BYTE, rgbaBuffer );
102 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
103 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
104 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
105 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
107 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
109 glBindTexture( GL_TEXTURE_2D, 0 );
132 const float shininess =
135 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
136 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
137 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
138 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
139 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shininess );
144 bool aUseSelectedMaterial,
SFVEC3F aSelectionColor )
147 const SFVEC4F diffuse =
SFVEC4F( aUseSelectedMaterial ? aSelectionColor : aMaterialDiffuse,
152 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
153 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
154 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
155 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
156 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 0.0f );
162 glMatrixMode( GL_PROJECTION );
165 glMatrixMode( GL_MODELVIEW );
168 glDisable( GL_LIGHTING );
169 glDisable( GL_COLOR_MATERIAL );
170 glDisable( GL_DEPTH_TEST );
171 glDisable( GL_TEXTURE_2D );
172 glDisable( GL_BLEND );
173 glDisable( GL_ALPHA_TEST );
176 glColor4f( aTopColor.x, aTopColor.y, aTopColor.z, 1.0f );
177 glVertex2f( -1.0, 1.0 );
179 glColor4f( aBotColor.x, aBotColor.y, aBotColor.z, 1.0f );
180 glVertex2f( -1.0,-1.0 );
181 glVertex2f( 1.0,-1.0 );
183 glColor4f( aTopColor.x, aTopColor.y, aTopColor.z, 1.0f );
184 glVertex2f( 1.0, 1.0 );
191 if( !glActiveTexture || !glClientActiveTexture )
192 throw std::runtime_error(
"The OpenGL context no longer exists: unable to Reset Textures" );
194 glActiveTexture( GL_TEXTURE0 );
195 glBindTexture( GL_TEXTURE_2D, 0 );
196 glClientActiveTexture( GL_TEXTURE0 );
197 glDisable( GL_TEXTURE_2D );
198 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
202 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 OglDrawBackground(const SFVEC3F &aTopColor, const SFVEC3F &aBotColor)
void OglSetMaterial(const SMATERIAL &aMaterial, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor)
Set OpenGL materials.
GLuint OglLoadTexture(const IMAGE &aImage)
Generate a new OpenGL texture.
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.