• Content count

  • Joined

  • Last visited

Community Reputation

268 Neutral

About songho

  • Rank
  1. building view matrix

    Normalize the side and up vectors, after performing cross product.
  2. I believe PGM is 8-bit grayscale image format, therefore the data type in glDrawPixels() would be GL_UNSIGNED_BYTE instead of GL_INT. You may have other mistakes on loading the pixmap and OpenGL codes. Please refer to the following codes. It includes a C++ PGM (P2 and P5) loader/writer class and OpenGL (GLUT) codes to draw the PGM image to the screen;
  3. OpenGL OpenGl Matrix Problem

    Quote:Original post by enotirab Basically I'm just confused as to why the Red Book has a translation matrix like this; 1 0 0 dx 0 1 0 dy (which is how mine is meant to be set up. 0 0 1 dz 0 0 0 1 It is the correct notation in OpenGL. However, keep in mind how OpenGL stores these 16 elements of the matrix into an 1-dimensional array. That is, the vertical elements (columns) are stored first, then move on the next column. The problem may be that your matrix class stores 16 elements in row-major order; storing the first row elements, then moving to the next line, which is common for math and C++. I do not know the original intention for OpenGL's way in first place, however, as a result, you can find very interesting fact; 3 consecutive elements in an array represent a meaningful set. For example, the first column, (m0, m1, m2) is the left(X) axis, the second column, (m4, m5, m6) is the up(Y) axis, the third column, (m8, m9, 10) is the forward(Z) axis, and the right most column, (m12, m13, m14) is for the translation. Here is an image for better understanding; For more info, check this link; OpenGL Matrix You can keep the own structure in your class, but you need to transpose the matrix data when you pass them to OpenGL. OpenGL also provides functions for this; glLoadTransposeMatrix{fd}() and glMultTransposeMatrix{fd}().
  4. current fbo

    I think you are looking for glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT). If it returns 0, then it refers to the window-system-provided (default) framebuffer. If non-zero value is returned, then it refers to the currently bound FBO. Other tokens added for FBO extension are; GL_RENDERBUFFER_BINDING_EXT GL_MAX_COLOR_ATTACHMENTS_EXT GL_MAX_RENDERBUFFER_SIZE_EXT Also, please check FBO specific interfaces to get info of the bound FBO; glGetFramebufferAttachmentParameterivEXT() glGetRenderbufferParameterivEXT()
  5. Well, please try C standard clock() first. I believe GLUT also uses clock() function internally to measure time, so the result should be same as glutGet(GLUT_ELAPSED_TIME). Also, QueryPerformanceCounter() is very high resolution timer as sgi1981 mentioned. But, it is a Windows specific API. Please check the following link . It explains how to use QueryPerformanceCounter() and an example of source code. High Resolution Timer
  6. luckyyyyyy, Here is a screenshot of the GLUT_ELAPSED_TIME output from my display callback function. Notice the time resolution of GLUT_ELPASED_TIME. As you can see, the resolution of GLUT timer is around 15 ms. That's why same numbers are duplicated many times and it suddenly jump to the next number. For applications with fast frame rates, you need a high resolution timer to measure more accurate elapsed time (at least 1ms difference).
  7. OpenGL Using extensions

    Here is how to set up extension functions without 3rd party extension helpers; // in order to get function prototypes from glext.h, define GL_GLEXT_PROTOTYPES before including glext.h #define GL_GLEXT_PROTOTYPES #include "glext.h" // function pointers for GL_EXT_blend_minmax extension // Windows needs to get function pointers from ICD OpenGL drivers, // because opengl32.dll does not support extensions higher than v1.1. #ifdef _WIN32 PFNGLBLENDEQUATIONEXTPROC pglBlendEquationEXT = 0; #define glBlendEquationEXT pglBlendEquationEXT #endif int main() { ... // get function pointer if "GL_EXT_blend_minmax" is supported glBlendEquationEXT = (PFNGLBLENDEQUATIONEXTPROC)wglGetProcAddress("glBlendEquationEXT"); ... } [Edited by - songho on December 12, 2008 2:06:38 PM]
  8. I quickly tested glutGet(GLUT_ELAPSED_TIME) on my system, and it works fine. But, I notice that your outputs are decreasing. Does GLUT initialized properly? Or, your GLUT lib may be broken.
  9. glutGet() actually returns an integer value. Please change the variable from double to int.
  10. OpenGL Glaux.h problems

    If you still want to compile the demo tutorial with glaux, then here it is; glaux.h glaux.lib
  11. Quote:Original post by Weedfin What's the best way to render to the existing DC, preferably without having to change any of the code in the existing app? I prefer to use a separate thread for OpenGL rendering. But, the simplest way is to put the rendering calls into the main message loop. Please check this.
  12. This is what I do; Create a RC in WM_CREATE handler: 1. Get the DC of the OpenGL window with GetDC() and the window handle. 2. Set the desired pixel format with SetPixelFormat() and the DC. 3. Create new RC with wglCreateContext() and the DC. 4. Release the DC with ReleaseDC(). Delete the RC in WM_CLOSE handler: 1. Release the current RC with wglMakeCurrent() and NULL parameter. 2. Delete the RC with wglDeleteContext(). HWND handle; HDC hdc; HGLRC hglrc; ... // retrieve a handle to a display device context hdc = ::GetDC(handle); // set members of PIXELFORMATDESCRIPTOR with given mode ID PIXELFORMATDESCRIPTOR pfd; int pixelFormat = findPixelFormat(hdc, colorBits, depthBits, stencilBits); ::DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd); // set pixel format ::SetPixelFormat(hdc, pixelFormat, &pfd); // create a new OpenGL rendering context hglrc = ::wglCreateContext(hdc); ::wglMakeCurrent(hdc, hglrc); ::ReleaseDC(handle, hdc); ... /////////////////////////////////////////////////////////////////////////////// // find the best pixel format with given parameters /////////////////////////////////////////////////////////////////////////////// int findPixelFormat(HDC hdc, int colorBits, int depthBits, int stencilBits) { int currMode; // pixel format mode ID int bestMode; // return value, best pixel format int currScore; // points of current mode int bestScore; // points of best candidate PIXELFORMATDESCRIPTOR pfd; // search the available formats for the best mode bestMode = 0; bestScore = 0; for(currMode = 1; ::DescribePixelFormat(hdc, currMode, sizeof(pfd), &pfd) > 0; ++currMode) { // ignore if cannot support opengl if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue; // ignore if cannot render into a window if(!(pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue; // ignore if cannot support rgba mode if((pfd.iPixelType != PFD_TYPE_RGBA) || (pfd.dwFlags & PFD_NEED_PALETTE)) continue; // ignore if not double buffer if(!(pfd.dwFlags & PFD_DOUBLEBUFFER)) continue; // try to find best candidate currScore = 0; // colour bits if(pfd.cColorBits >= colorBits) ++currScore; if(pfd.cColorBits == colorBits) ++currScore; // depth bits if(pfd.cDepthBits >= depthBits) ++currScore; if(pfd.cDepthBits == depthBits) ++currScore; // stencil bits if(pfd.cStencilBits >= stencilBits) ++currScore; if(pfd.cStencilBits == stencilBits) ++currScore; // alpha bits if(pfd.cAlphaBits > 0) ++currScore; // check if it is best mode so far if(currScore > bestScore) { bestScore = currScore; bestMode = currMode; } } return bestMode; }
  13. OpenGL [opengl]shared vertexes

    Quote:Original post by giugio How i create these instances in opengl? Using vbo? Yes, You can use VBOs. Just clarification, I didn't mean instantiating objects such as C++ or object-oriented programming. OpenGL only provides base APIs for drawing and transformation. You have to implement classes yourself if you want to wrap it nicely into classes in your programs. Other ways to draw meshes are; 1. Immediate mode with glBegin()/glEnd() block. 2. Vertex Array 3. Display List
  14. OpenGL [opengl]shared vertexes

    You can create multiple instances from a single reference mesh. You need simply apply different transformation matrices for each instance.
  15. OpenGL window coordinates

    You are calling both glOrth() and gluPerspective() in your Resize(). glOrtho() is to create a orthographic(parallel) viewing frustum, and gluPerspective() is to create a perspective viewing frustum. Please comment out gluPerspective() call.