Jump to content
  • Advertisement

Quasius

Member
  • Content Count

    68
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Quasius

  • Rank
    Member
  1. I want to be able to take in arbitrary rectangular images and stick them together in the same texture. So I need an algorithm that can find the "best" place to add the image to the texture given a map of used/unused space (a bit like Tetris). I could definitely write something on my own, but this feels like one of those problems that's been solved thousands of times- probably more efficiently than what I'd write. I just don't know what to google since I don't know the "official" name of the problem/algorithm. Is this a solved problem? If so, where can I find it? Thanks for any info.
  2. I am trying to render a 2D sprite with an image overlay that gets applied according to an alpha mask. Here is an image of it working correctly: The base texture is on the bottom, the overlay texture is on top and the alpha mask is on the left. The new image in is the center. The problem is the only way I've been able to do it is with 2 rendering passes. By rendering the base texture first and then rendering the water overlay with: /*Render base texture on its own*/ glActiveTextureARB(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pMaskImage->GetTextureID()); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); glActiveTextureARB(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pOverlayImage->GetTextureID()); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE1); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); /*calculate texture coords and render quad*/ It seems like this should be possible with one pass and 3 texture units. I tried this (along with many other things): glActiveTextureARB(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pMaskImage->GetTextureID()); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); glActiveTextureARB(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pOverlayImage->GetTextureID()); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE1); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pBaseImage->GetTextureID()); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE2); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA); /*calculate texture coords and render quad*/ but that results in this: What am I doing wrong? I know I'm not fully understanding what's going on here. For example, my understanding is that the image will be drawn starting with texture unit 0 up to texture unit n. Wouldn't that mean the GL_TEXTURE_ENV_MODE I set for texture0 (the alpha mask) wouldn't matter since it's getting overwritten by subsequent texture units? But it does seem to matter since setting it to GL_DECAL or something produces different results. Thanks for any help.
  3. I'm a beginner-intermediate OpenGL programmer, and I'm trying to find an article on writing fast OpenGL. I'm looking for info like what calls are expensive, optimization techniques, etc. Is there anything like this out there? Thanks.
  4. I've been working on a project in MSVS 2005 C++ for a while now. Recently, the intellisense for one of the classes got messed up. It recognizes things incorrectly, thinks functions are at wrong line numbers, etc. It's almost like it's "frozen" at some previous intellisense state and is not updating anymore. How can I force VS to redo its intellisense file? I tried removing and readding the files to the solution, but it didn't work.
  5. Well, the good news is it works now. The bad news is I have no idea why and that makes me nervous. What worked was "If you don't want the rotations to be dependent on one another, you'll need to store the orientation between frames/updates and update it incrementally as you go" suggested by jyk. I was actually shocked when it worked since I don't see how Matrix33 IncrementalRot = GenerateRotationMatrixX(fAngle); Matrix33Multiply(m_mat33Rotation, IncrementalRot, m_mat33Rotation); ...frame... Matrix33 IncrementalRot = GenerateRotationMatrixZ(fAngle); Matrix33Multiply(m_mat33Rotation, IncrementalRot, m_mat33Rotation); ...frame... Matrix33 IncrementalRot = GenerateRotationMatrixX(fAngle); Matrix33Multiply(m_mat33Rotation, IncrementalRot, m_mat33Rotation); for (int i = 0; i < nNumVerts; ++i) { RotatePoint(m_vVertices, m_mat33Rotation, m_vVertices); } is different from Matrix33 mat33X, mat33Z, mat33Rotation; //rotation about x mat33X.f22 = cos(2 * fAngle); mat33X.f23 = sin(2 * fAngle); mat33X.f32 = -mat33X.f23; mat33X.f33 = mat33X.f22; //rotation about z mat33Z.f11 = cos(fAngle); mat33Z.f12 = sin(fAngle); mat33Z.f21 = -mat33Z.f12; mat33Z.f22 = mat33Z.f11; //combine into final rotation matrix Matrix33Multiply(mat33Rotation, mat33X, mat33Rotation); Matrix33Multiply(mat33Rotation, mat33Z, mat33Rotation); for (int i = 0; i < nNumVerts; ++i) { RotatePoint(m_vVertices, mat33Rotation, m_vVertices); } Also, I looked at your post Sneftel. Isn't what you're doing just switching around which axis is dependent on another? When I was shuffling around rotation orders all I achieved was changing which axis was global, not making them all global. Or am I misunderstanding you? (I probably am.) Thanks for your help, guys. I think I'm getting closer to wrapping my head around this...
  6. Alright, I'll try to be more specific. I'm trying to make an editor that allows the user to place and orient a simple 3D primitive (box in this case). Since the game is actually isometric 2D, this is just for some internal 3D collision volumes. So I'm doing these 3D calculations "by hand" instead of using OpenGL. (Positioning/orienting the verts in internal 3D, then projecting to 2D screen coords.) Everything is working fine, except that it's nearly impossible to correctly orient the object when 2 of the axes are dependent on the others and appear to be changing/arbitrary axes instead of global x, y , and z. I'm tracking a variable between frames, m_v3fRotation, that contains rotations between 0 and 2*PI for x, y, and z. So I need to take those 3 values and calculate an orientation matrix/quat/whatever that treats each of those values as rotations about a global axis. (I actually want to rotate around the y axis and then an axis straight into/out of the screen and a third perpendicular to that instead of using the isometric x and z that don't correlate intuitively to mouse movements. But that should just be some manipulations of the x and z axis at the same time if I can figure out how to rotate x, y, and z independently. So I don't think this is relevant to my question.) Hopefully that was clearer for what I'm trying to do. Thanks.
  7. I'm still missing something here. Switching around the arguments for the second matrix multiply only changed the order of dependence. Even if I do it explicitly like this: Math3D::Matrix33Multiply(mat33Rotation, mat33X, mat33Rotation); Math3D::Matrix33Multiply(mat33Rotation, mat33Y, mat33Rotation); Math3D::Matrix33Multiply(mat33Rotation, mat33Z, mat33Rotation); I still get the same problem. That is the y rotation is relative to the z rotation and the x rotation is relative to the y and z rotation. Only z is on a "global" axis. If it's unclear, the arguments for the Matrix33Multiply function are (Matrix33& matrix1, Matrix33& matrix2, Matrix33& result). Also, I tried this with quats and got the exact same behavior. Maybe just tell me the general method for rotating about multiple global axes and I'll adjust my code to it?
  8. I know that matrix multiplication is not commutative. So if I make a rotation matrix for x, y, and z and multiply them together, the order I multiply them will make some of the rotations dependent on others. It ends up looking like only the last rotation is around the "global" axis. So how do I rotate some amount around the global x, then some amount around the global z instead of some amount around the global x, then some amount around the new local z? I doubt there's anything particularly interesting about it, but here's the code I'm currently using: //rotate the verts Vector3f v3fRotatedVert; Math3D::Matrix33 mat33X, mat33Y, mat33Z, mat33Rotation; //First, build the rotation matrix: //rotation about x mat33X.f22 = cos(m_v3fRotation.x); mat33X.f23 = sin(m_v3fRotation.x); mat33X.f32 = -mat33X.f23; mat33X.f33 = mat33X.f22; //rotation about y mat33Y.f11 = cos(m_v3fRotation.y); mat33Y.f31 = sin(m_v3fRotation.y); mat33Y.f13 = -mat33Y.f31; mat33Y.f33 = mat33Y.f11; //rotation about z mat33Z.f11 = cos(m_v3fRotation.z); mat33Z.f12 = sin(m_v3fRotation.z); mat33Z.f21 = -mat33Z.f12; mat33Z.f22 = mat33Z.f11; //combine into final rotation matrix Math3D::Matrix33Multiply(mat33X, mat33Y, mat33Rotation); Math3D::Matrix33Multiply(mat33Rotation, mat33Z, mat33Rotation); sf::Vector3f v3fVertCopy; for (int i = 0; i < m_nNumVerts; ++i) { Math3D::RotatePoint(m_vVertices, mat33Rotation); }
  9. Thanks. I'll look at that. I had no idea what terms to search under.
  10. Here is the problem: I have a group of 2D points and I need to find which points form the largest-possible (outer) convex polygon. The identified points should be in-order to form the poly. For example, it should find the red points in order in the following image: (Obviously where the loop starts is arbitrary.) I was working with a method of starting with any line segment and then trying to find which other connecting line segment formed the largest angle with it. This would eventually lead outward and around, forming the loop. The problem was that this involved lots of expensive inverse trig for finding the angles and ended up involving a lot of special cases to check for (coincident points, collinear points, etc.) Obviously the special cases can be worked out (although they are being stubborn), but this method will always involve all the inverse trig. So I was wondering if there was a known simpler solution. Thanks.
  11. Quote:Original post by SnotBob Why would you want to do that? Are you intending to use OpenGL to compute stuff you need in your game logic? If that's the case, it probably is better to write your own routines. Yes, that's what I wanted to do. I just wrote my own routines based on these replies. Thanks.
  12. Is it possible in the OpenGL API to transform (rotate) a point and then save the result? I don't just want to apply rotations for rendering with glRotatef. I want to rotate a point and then save the result. Or do I just need to build my own rotation functions for this?
  13. I have a class which needs some data which will always be the same for every instance of that class, so storing it separately for each instance is a waste of memory and I wanted it to be static. So it looks something like this: Foo.h: class Foo { void DoSomething(); static int m_Bar; }; --------------------------------------------------------- Foo.cpp: #include "Foo.h" void Foo::DoSomething() { m_Bar = 5; } This produces "error LNK2001: unresolved external symbol." I am using MSVC++ 2005 express. I tried messing around with extern, but didn't get anywhere. What is the correct syntax for what I'm trying to do? Thanks.
  14. A wav file is not just amplitudes as bytes. Look up the wav file format. Here is one: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ Also, I think DirectSound has WaveFormat functions for getting some of the header information. Other sound libraries might have similar functions.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!