songuke

Members
  • Content count

    10
  • Joined

  • Last visited

Community Reputation

122 Neutral

About songuke

  • Rank
    Member
  1. SDL_image aligned or unaligned?

    I see, so pitch = bytes per pixel (e.g. 3 for RGB) * width + a number of padded bytes, isn't it? :) I did recalculate the padded width. Dunno it was supported in the SDL_surface structure. :)
  2. Hi guys, SDL_image library provided IMG_load function that help load images. I loaded a bitmap 256x256 and compare with another load of 257x257. I saw the 257x257 bitmap does not render correctly (the image was distorted and unable to see). I thought the SDL_image resulted with SDL_surface with the array of internal pixels (SDL_surface->pixels) is an aligned image (with additional bytes padded at each row if the width % 4 != 0). Am I right?
  3. /* transform matrix */ Vector3f n = view - eye; //look Vector3f u = n.Cross(up); //right //Vector3f v = n.Cross(u); //left-handed - ??? Vector3f v = u.Cross(n); //right-handed - currently I used this u = u.Normalize(); v = v.Normalize(); n = n.Normalize(); /* make n as -z (negative z) in OpenGL (we look to the negative OpenGL) */ n = -n; //now become left-handed //translation Vector3f t = Vector3f(-eye.Dot(u), -eye.Dot(v), -eye.Dot(n)); /* interpreting as column-major like this in OpenGL * ( u.x, u.y, u.z, t.x, * v.x, v.y, v.z, t.y, * n.x, n.y, n.z, t.z, * 0 , 0, 0, 1 ) */ GLfloat m[] = { //so the matrix must be like this: u.x, v.x, n.x, 0, u.y, v.y, n.y, 0, u.z, v.z, n.z, 0, t.x, t.y, t.z, 1 }; I tested this transformation and gained the same result as gluLookAt method. But now I'm having a problem deriving this for the billboard. The billboard code is like this: Vector3f n = vecView; //vector from object of billboard to camera Vector3f u = vecUp.Cross(n); /* !!! Point to the left??? */ Vector3f v = n.Cross(u); u = u.Normalize(); v = v.Normalize(); n = n.Normalize(); //no translation yet //Vector3f t = Vector3f(-posObj.Dot(u), -posObj.Dot(v), -posObj.Dot(n)); /* interpreting as column-major like this * ( u.x, u.y, u.z, t.x, * v.x, v.y, v.z, t.y, * n.x, n.y, n.z, t.z, * 0 , 0, 0, 1 ) */ /* THIS ONE NOT WORK!!! GLfloat m[] = { u.x, v.x, n.x, 0, u.y, v.y, n.y, 0, u.z, v.z, n.z, 0, t.x, t.y, t.z, 1 };*/ /*BUT THIS ONE WORKS!!! -> This matrix's rotation part (u, v, n) is wrong of its position.*/ GLfloat billboardMat[] = { u.x, u.y, u.z, 0, v.x, v.y, v.z, 0, n.x, n.y, n.z, 0, t.x, t.y, t.z, 1 }; The billboard matrix is like this. I thought the billboardMat's elements is wrong but it does produce the right result of billboard. In the opposite, if I used the camera transformation matrix without the line n = -n, I still get the billboard effect but the rotation of Y axis is wrong (the image is upside down). It looks confusing. Anyone could give me some hints? :) Thanks in advance.
  4. Hi, I'm confused about the following: Could you please point out the difference between the view transformation derived from UVN (eye point, look-at point, up vector) matrix and the one derived by rotating the world coordinate? If I'm right, in Direct3D the coordinate system is left-handed. Our camera is right-handed though. So is that the problem? I have not try this in OpenGL, of which the coordinate system is right-handed. Thanks in advance.
  5. Phew, finally know what the reason is. Actually I did allocate some elements in the array like T* elements = new T[size] and then only use "delete elements" in the destructor. This will leave some trash elements remaining in the heap so some further operations (which?, who knows!) will throw errors. I changed to "delete[] elements" to ensure every objects in the array is deleted properly and the error is gone. Just wonder why those error is so terrible to figure out? (glibc throws exception although I didn't touch it) And many thanks to the Valgrind tool since I would not have know the bug without it. :)
  6. Hi guys, I have this error, too. My situation is much more strange. I created a window with some widgets using gtkmm. I also rewrite MFC's CArray for use in Linux. I found that the constructor of CArray is automatically called several times although I didn't declare any CArray in the main function. I even empty the main() function and remove all includes, like this: int main() { return 0; } and then run the program. It still throws out the munchunk() glibc error after calling several times the CArray constructor. Really strange, as the body of the main is empty!!! I guess there's a problem with those linking libraries of gtkmm? I'm using Eclipse on Ubuntu in joint with gtkmm library for my project. Any hints? Thanks in advance.
  7. glDrawPixels and GL_DEPTH_TEST

    I see, so in this case we need to use glRasterPos3f(0.0f, 0.0f, -1.0f) then glDrawPixels to draw the background at z = -1 first, then draw the ball at z = 0. Is that the idea?
  8. glDrawPixels and GL_DEPTH_TEST

    Hi, I do not quite understand. For instance, I draw a ball on a field (in ortho projection mode). I draw the field by glDrawPixels and then draw the ball (a quad with texture) on it. When I enable GL_DEPTH_TEST I cannot see the ball (the Z of the ball is 0 actually). No matter how I change the Z element towards the near plane or the far plane, the ball can't not be seen. If I disable GL_DEPTH_TEST then everything is ok. Therefore, I think the glDrawPixels may have some issues with the GL_DEPTH_TEST. The obvious solution is use a quad as the background and discard the glDrawPixels. Any other solutions?
  9. Hi guys, just wonder what is the mechanism of this glDrawPixels? As I know, glDrawPixels rendered directly to the framebuffer. Currently I used it to draw a 2D background in ortho projection. And how can I enable depth test? When I enable GL_DEPTH_TEST, every object is gone. When I disabled it, the objects are rendered normally on the background. Hope you guys can help. :) Thanks a lot.
  10. Hi all, I've got this issue when trying to transform from world to view coordinate in 3D environment: When I use the UVN transformation (1) which calculates U, V, N from eye point, look-at point and up vector, the transform matrix is different from the one I derived from rotating the world coordinate XYZ (2) in order to become the view point. The details of the later process is as follow: Let N be the vector from eye to look-at point. Assume that the eye is at the origin of XYZ. 1. Calculate theta and phi of N in XYZ. 2. Rotate XYZ coordinate system a theta angle about Z so the new X axis fit into the projection of N on the XY-plane. 3. Rotate X'Y'Z around Y' so as Z fit N. 4. ??? I think these steps are quite similar to rotating objects about an arbitrary axis. However, in view transformation case, after the first 3 steps, we just fit the Z axis into N. I think in order to make the transformation of UVN similar to the transformation of rotation coordinate system XYZ, we must somehow rotate XY about Z in the 4th step. At this point, I was really confused. Anyone can help me plz? Just want to figure out why these two transformation goes wrong in my case. In fact, everyone use the first UVN transformation, right? Thank you! :)