49 0.0f,0.0f,0.0f,0.0f) );
54 0.0f,0.0f,0.0f,1.0f));
80 (*this) = moMatrix4f::IDENTITY;
86 (*this) = moMatrix4f::ZERO;
102 moGLMatrixf::MakeLookAt(
float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ ) {
104 moVector3f center3D( centerX, centerY, centerZ );
111 direction3D.
X() = center3D.
X() - eyePosition3D.
X();
112 direction3D.
Y()= center3D.
Y() - eyePosition3D.
Y();
113 direction3D.
Z() = center3D.
Z() - eyePosition3D.
Z();
123 side3D = direction3D.
UnitCross( upVector3D );
131 up = side3D.
Cross( direction3D );
154 matrix2[0][0] = side3D.
X();
155 matrix2[1][0] = side3D.
Y();
156 matrix2[2][0] = side3D.
Z();
159 matrix2[0][1] = up.
X();
160 matrix2[1][1] = up.
Y();
161 matrix2[2][1] = up.
Z();
164 matrix2[0][2] = -direction3D.
X();
165 matrix2[1][2] = -direction3D.
Y();
166 matrix2[2][2] = -direction3D.
Z();
169 matrix2[0][3] = matrix2[1][3] = matrix2[2][3] = 0.0f;
179 me.
Translate( -eyePosition3D.
X(), -eyePosition3D.
Y(), -eyePosition3D.
Z() );
187 float r_l = right - left;
188 float t_b = top - bottom;
189 float f_n = zfar - znear;
190 float A = (right + left)/r_l;
191 float B = (top + bottom)/t_b;
192 float C = -(zfar + znear)/f_n;
193 float D = -2*(zfar*znear)/f_n;
198 Result.SetRow( 0,
moVector4f( 2.0 * znear / r_l, 0.0, A, 0.0 ) );
199 Result.SetRow( 1,
moVector4f( 0.0, 2.0 * znear / t_b, B, 0.0 ) );
200 Result.SetRow( 2,
moVector4f( 0.0, 0.0, C, D ) );
201 Result.SetRow( 3,
moVector4f( 0.0, 0.0, -1.0, 0.0 ) );
203 Me = Me * (Result.Transpose());
213 float r_l = right - left;
214 float t_b = top - bottom;
215 float f_n = zfar - znear;
216 float tx = -(right + left)/r_l;
217 float ty = -(top + bottom)/t_b;
218 float tz = -(zfar + znear)/f_n;
222 Result.SetRow( 0,
moVector4f( 2.0 / r_l, 0.0, 0.0, tx ) );
223 Result.SetRow( 1,
moVector4f( 0.0, 2.0 / t_b, 0.0, ty ) );
224 Result.SetRow( 2,
moVector4f( 0.0, 0.0, -2.0 / f_n, tz ) );
226 Me = Me * (Result.Transpose());
243 Me = Me*Result.Transpose();
263 if (rz!=0.0 && rx==0.0 && ry==0.0) {
269 Me = Me*Result.Transpose();
272 Result[0][0] = rx*rx*(1-c) + c;
273 Result[0][1] = rx*ry*(1-c) - rz*s;
274 Result[0][2] = rx*rz*(1-c) + ry*s;
277 Result[1][0] = rx*ry*(1-c) + rz*s;
278 Result[1][1] = ry*ry*(1-c) + c;
279 Result[1][2] = ry*rz*(1-c) - rx*s;
282 Result[2][0] = rx*rz*(1-c) - ry*s;
283 Result[2][1] = ry*rz*(1-c) + rx*s;
284 Result[2][2] = rz*rz*(1-c) + c;
291 Me = Me*Result.Transpose();
305 Me = Me*Result.Transpose();
314 for(
int j=0;j<4; j++) {
316 for(
int i=0;i<4; i++) {
339 m_DisplayServer = NULL;
340 m_DisplayScreen = NULL;
341 m_DisplayWindow = NULL;
343 m_gpu_vendor_code = 0;
344 m_gpu_vendor_string =
"undefined";
345 m_gpu_renderer_string =
"undefined";
347 m_current_fbo = m_previous_fbo = 0;
349 m_current_read_buffer = m_current_draw_buffer = 0;
350 m_previous_read_buffer = m_previous_draw_buffer = 0;
351 m_bFrameBufferObjectActive =
false;
361 QueryGPUVendorString();
363 m_bFrameBufferObjectActive =
false;
366 m_DisplayServer = NULL;
367 m_DisplayScreen = NULL;
368 m_DisplayWindow = NULL;
369 m_gl_version =
"none";
370 m_gl_major_version = 0;
371 m_gl_minor_version = 0;
374 glGetIntegerv(GL_DRAW_BUFFER, &m_current_draw_buffer);
375 glGetIntegerv(GL_READ_BUFFER, &m_current_read_buffer);
378 m_gl_version = (
char*) glGetString(GL_VERSION);
379 glGetIntegerv(GL_MAJOR_VERSION, &m_gl_major_version);
380 glGetIntegerv(GL_MINOR_VERSION, &m_gl_minor_version);
382 if (m_gl_major_version==0) {
383 std::string major = (
char*)m_gl_version;
384 major.substr( 0, major.find(
".") );
385 m_gl_major_version = (int) atoi(major.c_str() );
388 if (m_gl_minor_version==0) {
389 std::string minor = (
char*)m_gl_version;
390 minor.substr( minor.find(
".")+1, 1 );
391 m_gl_minor_version = (int) atoi(minor.c_str() );
397 MODebug2->
Message(
"moGLManager::Init > GPU VENDOR STRING is "+m_gpu_vendor_string );
398 MODebug2->
Message(
"moGLManager::Init > GPU RENDERER STRING is "+m_gpu_renderer_string );
411 m_bFrameBufferObjectActive = active;
423 while ((errnum = glGetError()))
431 errstr+= (
char *)gluErrorString(errnum);
439 void moGLManager::QueryGPUVendorString()
442 char *glvendor = NULL;
443 glvendor = (
char*)glGetString(GL_VENDOR);
444 if (glvendor!=NULL) {
445 strcpy(vendor, glvendor);
446 m_gpu_vendor_string = vendor;
448 if (strstr(vendor,
"NVIDIA") != NULL) m_gpu_vendor_code =
MO_GPU_NV;
449 else if (strstr(vendor,
"ATI") != NULL) m_gpu_vendor_code =
MO_GPU_ATI;
450 else if (strstr(vendor,
"INTEL") != NULL) m_gpu_vendor_code =
MO_GPU_INTEL;
454 glvendor = (
char*)glGetString(GL_RENDERER);
455 if (glvendor!=NULL) {
456 strcpy(vendor, glvendor);
457 m_gpu_renderer_string = vendor;
464 glViewport(0, 0, p_width, p_height);
484 glMatrixMode(GL_PROJECTION);
486 glLoadMatrixf( m_ProjectionMatrix.GetPointer() );
504 moDisplay( p_width, p_height ).HeightToProportion(-0.5),
505 moDisplay( p_width, p_height ).HeightToProportion(0.5)
512 glMatrixMode(GL_PROJECTION);
516 m_ProjectionMatrix.
MakeOrthographic( left, right, bottom, top, znear, zfar );
518 if (p_width!=0 || p_height!=0) {
519 glViewport(0, 0, p_width, p_height);
524 glMatrixMode(GL_PROJECTION);
525 glLoadMatrixf( m_ProjectionMatrix.GetPointer() );
533 if ( p_width == 0 || p_height == 0 ) { p_width = 1; p_height = 1; prop = 1.0; }
535 prop = (float) p_height / (
float) p_width;
537 glViewport( 0, 0, p_width, p_height );
541 glMatrixMode(GL_PROJECTION);
542 glLoadMatrixf( m_ProjectionMatrix.GetPointer() );
547 glMatrixMode(GL_MODELVIEW);
554 void moGLManager::LookAt(
float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ ) {
558 Lat.
MakeLookAt( eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ );
563 m_ProjectionMatrix = Lat*m_ProjectionMatrix;
569 glMatrixMode(GL_PROJECTION);
571 glLoadMatrixf( m_ProjectionMatrix.GetPointer() );
581 MOint render_mode = 0;
583 glGetIntegerv(GL_RENDER_MODE, &render_mode);
592 glRenderMode(p_mode);
599 glEnable(GL_DEPTH_TEST);
600 glDepthFunc(GL_LEQUAL);
602 glEnable(GL_TEXTURE_2D);
605 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
612 glDisable(GL_DEPTH_TEST);
614 glDisable(GL_TEXTURE_2D);
620 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
621 glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE);
622 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
623 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
624 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
626 glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
627 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
628 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
629 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
630 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
633 glPixelStorei(GL_PACK_ALIGNMENT, 4);
634 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
644 glPushAttrib(GL_ALL_ATTRIB_BITS);
652 glMatrixMode(GL_MODELVIEW);
654 glMatrixMode(GL_PROJECTION);
656 glMatrixMode(GL_TEXTURE);
664 glPushAttrib(GL_VIEWPORT_BIT);
671 m_saved_fbo = m_current_fbo;
672 m_saved_read_buffer = m_current_read_buffer;
673 m_saved_draw_buffer = m_current_draw_buffer;
688 glMatrixMode(GL_PROJECTION);
690 glMatrixMode(GL_MODELVIEW);
692 glMatrixMode(GL_TEXTURE);
707 m_current_fbo = m_saved_fbo;
708 if (m_bFrameBufferObjectActive) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_current_fbo);
710 m_current_read_buffer = m_saved_read_buffer;
712 if (m_bFrameBufferObjectActive) glReadBuffer(m_current_read_buffer);
714 m_current_draw_buffer = m_saved_draw_buffer;
716 if (m_bFrameBufferObjectActive) glDrawBuffer(m_current_draw_buffer);
726 result.
target = GL_TEXTURE_RECTANGLE_NV;
728 if (p_num_components == 4) result.
internal_format = GL_FLOAT_RGBA16_NV;
731 if (p_num_components == 4) result.
internal_format = GL_FLOAT_RGBA32_NV;
736 result.
target = GL_TEXTURE_RECTANGLE_ARB;
738 if (p_num_components == 4) result.
internal_format = GL_RGBA_FLOAT16_ATI;
741 if (p_num_components == 4) result.
internal_format = GL_RGBA_FLOAT32_ATI;
747 result.
target = GL_TEXTURE_RECTANGLE_ARB;
759 result.
wrap_s = GL_CLAMP_TO_EDGE;
760 result.
wrap_t = GL_CLAMP_TO_EDGE;
769 (p_target == GL_TEXTURE_RECTANGLE_NV) ||
771 (p_target == GL_TEXTURE_RECTANGLE_ARB);
778 (p_internal_format == GL_FLOAT_RGBA16_NV) ||
779 (p_internal_format == GL_FLOAT_RGBA32_NV) ||
780 (p_internal_format == GL_FLOAT_R16_NV) ||
781 (p_internal_format == GL_FLOAT_R32_NV) ||
782 (p_internal_format == GL_RGBA_FLOAT16_ATI) ||
783 (p_internal_format == GL_RGBA_FLOAT32_ATI) ||
784 (p_internal_format == GL_LUMINANCE_FLOAT16_ATI) ||
785 (p_internal_format == GL_LUMINANCE_FLOAT32_ATI) ||
787 (p_internal_format == GL_RGBA16F_ARB) ||
788 (p_internal_format == GL_RGBA32F_ARB) ||
789 (p_internal_format == GL_LUMINANCE16F_ARB) ||
790 (p_internal_format == GL_LUMINANCE32F_ARB);
795 return (p_min_filter == GL_NEAREST_MIPMAP_NEAREST) ||
796 (p_min_filter == GL_LINEAR_MIPMAP_NEAREST) ||
797 (p_min_filter == GL_NEAREST_MIPMAP_LINEAR) ||
798 (p_min_filter == GL_LINEAR_MIPMAP_LINEAR);
803 m_current_fbo = m_fbo;
804 if (m_bFrameBufferObjectActive) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_current_fbo);
809 m_current_read_buffer = p_buffer;
811 if (m_bFrameBufferObjectActive) glReadBuffer(m_current_read_buffer);
817 m_current_draw_buffer = p_buffer;
819 if (m_bFrameBufferObjectActive) glDrawBuffer(m_current_draw_buffer);
825 m_previous_fbo = m_current_fbo;
826 m_previous_read_buffer = m_current_read_buffer;
827 m_previous_draw_buffer = m_current_draw_buffer;
846 PIXELFORMATDESCRIPTOR pfd;
850 memset(&pfd, 0,
sizeof(PIXELFORMATDESCRIPTOR));
852 pfd.nSize =
sizeof(pfd);
854 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
855 pfd.iPixelType = PFD_TYPE_RGBA;
858 pfd.cStencilBits = 8;
859 pfd.iLayerType = PFD_MAIN_PLANE;
861 PixelFormat = ChoosePixelFormat(hDC, &pfd);
862 SetPixelFormat(hDC, PixelFormat, &pfd);
865 this->m_Context = (
moGLContext) wglCreateContext(hDC);
866 wglMakeCurrent(hDC, (HGLRC) this->m_Context );
884 int m_glxVersion = 0;
885 int glxMajorVer, glxMinorVer;
886 Display *XServerDisplay=NULL;
887 GdkDisplay *XGdkDisplay=NULL;
888 GLXFBConfig *fbc = NULL;
889 GLXPbuffer OffScreenBuffer = 0;
894 MODebug2->
Message(
"moGLManager::CreateContext > getting X server display" );
896 if (m_DisplayServer==NULL) {
897 XServerDisplay = XOpenDisplay(NULL);
898 m_DisplayServer = (
void*)XServerDisplay;
900 XServerDisplay = (Display *)m_DisplayServer;
901 MODebug2->
Message(
"moGLManager::CreateContext > display server connection already opened.");
907 if (XServerDisplay) {
909 MODebug2->
Message(
"moGLManager::CreateContext > X server display OK." );
911 XGdkDisplay = gdk_x11_lookup_xdisplay( XServerDisplay );
912 if (!XGdkDisplay) XGdkDisplay = gdk_display_get_default ();
916 nscreens = gdk_display_get_n_screens(XGdkDisplay);
926 bool ok = glXQueryVersion( XServerDisplay, &glxMajorVer, &glxMinorVer);
931 m_glxVersion = glxMajorVer*10 + glxMinorVer;
933 MODebug2->
Message(
"moGLManager::CreateContext > GLX Version (10=1.0,13=1.3,...): " +
IntToStr(m_glxVersion) +
"=" +
FloatToStr( (
double)(m_glxVersion)/(
double) 10.0) );
935 if ( m_glxVersion >= 13)
943 GLX_RENDER_TYPE, GLX_RGBA_BIT,
955 fbc = glXChooseFBConfig( XServerDisplay,
956 DefaultScreen(XServerDisplay),
964 MODebug2->
Error(
"moGLManager::CreateContext > No FBConfig");
968 this->m_Context = (
moGLContext) glXCreateNewContext( XServerDisplay ,
977 int attrib_list_vi[] =
990 XVisualInfo *vi = glXChooseVisual( XServerDisplay,
991 DefaultScreen(XServerDisplay),
994 this->m_Context = (
moGLContext) glXCreateContext( XServerDisplay,
1000 if (this->m_Context) {
1002 MODebug2->
Message(
"moGLManager::CreateContext > creating offscreen buffer.");
1004 if ( m_glxVersion >= 13 ) {
1006 int pbuffer_attrib[] = {
1007 GLX_PBUFFER_WIDTH, p_width,
1008 GLX_PBUFFER_HEIGHT, p_height,
1009 GLX_LARGEST_PBUFFER, 0,
1010 GLX_PRESERVED_CONTENTS, 0,
1012 OffScreenBuffer = glXCreatePbuffer( XServerDisplay, fbc[0], pbuffer_attrib );
1014 this->m_DisplayScreen = (
void*) OffScreenBuffer;
1016 if (OffScreenBuffer) {
1022 if ( glXMakeContextCurrent( XServerDisplay, OffScreenBuffer, OffScreenBuffer, (GLXContext) this->m_Context ) ) {
1023 MODebug2->
Message(
"moGLManager::CreateContext > Making Context current OK!");
1049 return (this->m_Context == NULL);
1060 return this->m_Context;
1066 return this->m_DisplayServer;
1071 return this->m_DisplayScreen;
1076 return this->m_DisplayWindow;
1082 m_Context = p_Context;
1087 return m_ModelMatrix;
1093 m_ModelMatrix = p_mat4;
1094 return m_ModelMatrix;
1099 return m_ProjectionMatrix;
1105 m_ProjectionMatrix = p_mat4;
1106 return m_ProjectionMatrix;
void SetDefaultPixelStorageModes()
moGLMatrixf & MakeLookAt(float eyeX=0.0, float eyeY=0.0, float eyeZ=-10.0, float centerX=0.0, float centerY=0.0, float centerZ=0.0, float upX=0.0, float upY=0.0, float upZ=1.0)
moDisplayScreen GetDisplayScreen()
moGLMatrixf & Scale(float sx, float sy, float sz)
void SetPerspectiveView(MOint p_width, MOint p_height, double fovy=60.0, double aspect=1.0, double znear=0.1, double zfar=4000.0)
moGLMatrixf & MakePerspective(float fovy, float aspect, float zNear, float zFar)
Parámetros internos de una textura.
The Blue component of a color.
void SetDefaultOrthographicView(MOint p_width=0, MOint p_height=0)
moGLMatrixf & GetModelMatrix()
void LookAt(float eyeX=0.0, float eyeY=0.0, float eyeZ=-10.0, float centerX=0.0, float centerY=0.0, float centerZ=0.0, float upX=0.0, float upY=0.0, float upZ=1.0)
void Error(moText p_text)
Anuncia y registra un error.
void SetName(const moText &p_name)
moGLMatrixf & SetModelMatrix(const moGLMatrixf &p_mat4)
moVector4< MOfloat > moVector4f
LIBMOLDEO_API moText0 FloatToStr(double a)
moRenderManager * GetRenderMan()
Matrices para transformaciones en Open GL.
static void Error(moText p_text)
Anuncia un error.
moDisplayWindow GetDisplayWindow()
static const moGLMatrixf ZERO
void SetResourceType(moResourceType p_restype)
static Real Sin(Real fValue)
MOboolean RectTexture(GLenum p_target) const
moGLMatrixf & operator=(const moGLMatrixf &rkM)
moGLMatrixf(bool bZero=true)
moGLMatrixf & Rotate(float angle, float vx, float vy, float vz)
MOboolean MipMapTexture(GLint p_min_filter)
MOboolean CheckErrors(moText p_location)
void SetRow(int iRow, const moVector3< Real > &rkV)
clase de para manejar textos
moResourceManager * m_pResourceManager
Puntero al administrador de recursos.
MOint RenderHeight() const
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
moGLMatrixf & SetProjectionMatrix(const moGLMatrixf &p_mat4)
moGLMatrixf & MakeIdentity()
moGLMatrixf & MakeFrustrum(float left=-1.0, float right=1.0, float bottom=-1.0, float top=1.0, float near=0.0001, float far=1000.0f)
void SetCurrentDrawBuffer(MOint p_buffer)
moGLMatrixf & Translate(float x, float y, float z)
void SetCurrentReadBuffer(MOint p_buffer)
MOboolean FPTexture(GLint p_internal_format)
void SetCurrentFBO(MOuint m_fbo)
void SetDefaultPerspectiveView(MOint p_width, MOint p_height)
void SetContext(moGLContext p_Context)
static const moGLMatrixf IDENTITY
The Alpha (or transparency) of a color.
void SetFrameBufferObjectActive(bool active=true)
moGLMatrixf & GetProjectionMatrix()
void SetLabelName(const moText &p_labelname)
moTexParam BuildFPTexParam(MOboolean p_16bits=true, MOushort p_num_components=4)
virtual MOboolean Finish()
MOint RenderWidth() const
static moDebug * MODebug2
Clase de impresión de errores para depuración
void SetRenderMode(MOint p_mode)
moGLMatrixf & MakeOrthographic(float left=-1.0, float right=1.0, float bottom=-1.0, float top=1.0, float near=0.0001, float far=1000.0f)
moMatrix4< MOfloat > moMatrix4f
static Real Cos(Real fValue)
moDisplayServer GetDisplayServer()
moVector3 Cross(const moVector3 &rkV) const
LIBMOLDEO_API moText0 IntToStr(int a)
void RestoreFramebuffer()
int CreateContext(int p_width, int p_height)
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
void SetOrthographicView(MOint p_width=0, MOint p_height=0, float left=0.0, float right=1.0, float bottom=0.0, float top=1.0, float znear=-1.0, float zfar=1.0)
void SetType(moMoldeoObjectType p_type)
moVector3 UnitCross(const moVector3 &rkV) const