# SelethD

Member

573

456 Neutral

• Rank
1. ## How do I get a 3D position from a Camera Vector

Not sure if it will be needed by anyone, but after experimenting I did find a solution.   --first i set up some vectors local g_up = Vector3.new(0,1,0)  --global up local v_forward = target.lookVector local v_right = -g_up:Cross(v_forward) local v_up = -v_forward:Cross(v_right) local p = target.position   --get a new position, based off of moving down the vectors (also the 'loc' variable is what was returned by the function in the above post) p = (v_forward*(-loc.Z))+p p = (v_right*loc.X)+p p = (v_up*loc.Y)+p   local cam = Camera cam.position = p cam.lookAt = p+(target.lookVector * -2))    I dont know if its the best way to do this, but it works, so... unless it gives me issues, ill use this   Thanks
2. ## How do I get a 3D position from a Camera Vector

Ok... I am quite the novice when it comes to game related math, especially in the 3D realm.  So I shall try to convey my problem as clearly as possible, since I do not know much of the terminology.   I have a Camera in 3D space, this camera can be located at any x,y,z and it can face any direction valid for a FPS view. I have a target, the target can be at any location in 3D space along the x,y,z however the target will be STATIC and non movable.   I would like to be able to have my camera position itself in front of the target so that the target will appear a certain size and location on the 2D render screen.   I found online a function, when when supplied with variables of x,y (location of target to be displayed on 2D screen) and height (the height the target should display on the 2D screen) the function will return a Vector3 stating where the target should be placed in 3D space, so that it will render at the x,y at desired height on the 2D render screen.   The problem I am having is converting that Vector3 into something that I can use to position my Camera (since my target is stable) in the correct position to get the same result.   This is what I am doing so far... the code is in Lua   -- This line is calling the function I found online, I am requesting a Vector3 position so the target will be shown on the 2D render at position screenW/2, screenH/2 (so that should be in center of screen) and I want the object to appear to be .5 the size of my screen's height so thats the second screenH/2.  The last argument is the unit size of the object (2 units high)   local pos = ScreenSpace.ScreenToWorldByHeight(screenW/2,screenH/2,screenH/2, 2)   Now the result is ... pos = (0,0,-2)   -- Meaning i need to have the target positioned -2 away from my camera on the Z axis to display as needed.   This is the same result no matter which way my camera is facing, so I know the result is based off of my camera's .. facing vector?   So I tried this to get my new camera position...   newCamPos = TargetPosition - pos   This however, causes my camera to be positioned at the targets location offset by +2 on the Z axis, when in reality, I need it to be +2 on the Z axis in relation to how the Target is facing, the targets facing vector.   So I am lost... is there an easier way to do this?  What terms should I search for?  Or if you have any tips or tricks to share that would be great.   Thanks

4. ## OpenGL Trouble loading and displaying with transparency, 8bit indexed bitmaps

Its too bad there is no apparent 'native support' for 8bit images in opengl anymore.  However, I did not know it was getting a copy of the entire palette on each call, I tried to suggestion of making one copy to an array, and using the array, and the results were 100% faster.   I cant even tell how long its taking to load, as it zips through the files.   Thanks so much.
5. ## OpenGL Trouble loading and displaying with transparency, 8bit indexed bitmaps

It is definately the 'looping' through the indexes that is causing the slow operation.   I have been searching and searching online for a solution, and came across something interesting...   I've seen  GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, PixelFormat.ColorIndex, PixelType.UnsignedByte, data); now, the PixelFormat is ColorIndex.... this is what I need... however, when I use this, I get pure black images, no transparency... So, I think I must be missing the 'color palette' somewhere... I'm trying to discover, how to let opengl know the data of the colorpalette tha the ColorIndex will look at.   I also read this... "Similarly, to offset the color indices of a bitmap to the palette entries you have defined for it, use glPixelTransferi(GL_INDEX_OFFSET, bitmap_entry);"   it says 'the palette entries you have defined', and im assuming this is 'bitmap_entry', but nothing shows 'HOW' to define the palette entries     So... I'm feeling more lost than ever, surely surely someone has used indexed graphics, and knows how to do this, but the lack of information on the web is troubling, i'm thinking, is it even possible anymore?     Thanks for any help
6. ## OpenGL Trouble loading and displaying with transparency, 8bit indexed bitmaps

Thanks so much for your input.   Well, the case with Palette.Entries[0], is that it's alpha value is non 0, and I really don't care what color the pixels are for index 0, as long as it is transparent.  I cant edit the original images, unless there is some magical opengl, trick to mass convert data or something, I'm afraid I'll have to check and set to alpha 0 each time I hit an index 0 byte.   I see what you mean, as far as writing 1x4 bytes, not sure if this would be a speed increase, but its something I will try, just to see if I get different results.   It is a time critical piece of code, and I do have it in a 'title/loading' screen, its just.... slow loading.   Now you mention, am I sure its 'super slow'... yeah, it kinda is... and actually that is a bit surprising, even for an 800x800 image... I would think it would be faster on a modern computer.  So, I'm wondering if the part that is taking up so much time, might be the part of the code where I am reading in the Bitmap, with LockBits, and copying its data.   I plan to keep trying and experimenting   If anyone has any other input or have used 8bit indexed bitmaps.... please share some secrets, thanks.
7. ## OpenGL Trouble loading and displaying with transparency, 8bit indexed bitmaps

I am working on a project, that uses some legacy graphics, that are in an 8bit indexed bitmaps.  These are the ones with a 1 byte pixel, pointing to an array of 256 colors.   So far, this is how I have been doing things.... (note, I'm using C#, with OpenTK, although a solution in C++ can be easily converted) Bitmap bitmap = new Bitmap(path); System.Drawing.Imaging.BitmapData textureData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); int srcmax = textureData.Height * textureData.Stride; byte[] origBytes = new Byte[srcmax]; Marshal.Copy(textureData.Scan0, origBytes, 0, srcmax); bitmap.UnlockBits(textureData); this gives me the bitmap pixel data (the 1 byte index numbers) in textureData. So now, I very slowly and very painfully, go through the data, as such.... //loop through all the pixels byte[] data = new byte[(bitmap.Width * bitmap.Height) * 4]; int srcloc = 0; int dstloc = 0; byte index; Color color; for (int y = 0; y < textureData.Height; y++) { srcloc = y * textureData.Stride; for (int x = 0; x < textureData.Width; x++) { index = origBytes[srcloc]; if (index == 0) { data[dstloc] = 0; data[dstloc + 1] = 0; data[dstloc + 2] = 0; data[dstloc + 3] = 0; } else { color = bitmap.Palette.Entries[index]; data[dstloc] = color.R; data[dstloc + 1] = color.G; data[dstloc + 2] = color.B; data[dstloc + 3] = color.A; } dstloc += 4; srcloc++; } } as you can see, I am looking at the color, pointed to, by each pixel index... and manually reversing the red, and blue values, and also, setting alpha to 0, when the index number is 0.  This converted data is then used to create an opengl texture, as follows... GL.Enable(EnableCap.Texture2D); uint textureID = 0; GL.GenTextures(1, out textureID); GL.BindTexture(TextureTarget.Texture2D, ret.ID); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelData); GL.Disable(EnableCap.Texture2D); Now... this totally works, I end up with a rgba opengl texture2d, with transparency that can be used to texture a quad  and it looks perfect.... only problem is the super slow speed of going through each pixel, as some of these images are > 800x800   So... If anyone knows of a better solution, something faster, or if you know of anything I seem to be doing wrong (opengl wise, as I am an opengl noob) please let me know.   Thanks
8. ## OpenGL How 'in terms of structure' do I use my shader?

Thanks for the replies, I wouldn't even begin to know how to batch my sprites, as each of the 100 sprites would contain different textures.  No duplicating textures.   I see what you mean now about not needing to call 'end' on the shader.     I think I understand about the 'setvariable' once, ,then just bind different textures.  I will give this a try XD    Thanks again.

10. ## How we solved the infamous sliding bug

Just my 2 cents, but I would think, unless it really affects gameplay, I wouldnt worry about each screen being a little different than the other. Not sure exactly what type of game you are making, but I have seen many games where the screens do not match up, but was not necessary for accurate gameplay.
11. ## Post-christmas GD games giveaway

Whenever I see a topic that you have replied to, or initiated, it always gets my interest.  Great job.
12. ## You Don't Need to Hide Your Source Code

I have to agree with wicked357, I think the most logical reason to be careful with sharing your source would be to help prevent cheating... Granted, I have done my fair share of that, in my day, and I know from experience, that not having the source made hacks, and bots extreamly difficult to create.   Also, if your source is server code, it could have database information that could compromise the security of user accounts or other important things on your system.   But for small games, single players, or just a stripped down framework, there is no reason to worry about sharing.
13. ## Rush 2 - Looking for Feedback

I tried it out, using IE (I know most people use other browsers, but you should always try to be a cross browser compatible as possible)   There are only a few little things that I noticed   1) When loading the resources, after pressing the 'Play' button, it sort of just 'hangs' , at first I thought my window locked up, but then the game started, so, maybe  a 'loading' screen or progress bar would help to show that it didnt just lock   2) The screen will scroll smooth most of the time with the player, but on occasion the screen will shake, almost like there is an earthquake happening.  Not sure if you are doing that on purpose?!?!  If you are... cool, but if not, might want to check out your screen movement (camera movement) code.   I really think you have a cool idea, and I see lots of potential here.  Good job XD
14. ## What Language or Languages for Web and Mobile Apps

Wow, you guys have given a LOT of useful information.  I cant express how grateful I am.  This will give me enough options to research and experiment with to last me a while.    Thanks again.
15. ## What Language or Languages for Web and Mobile Apps

If this is not the correct forum, my apologies.  I thought, since I am a beginner to web or mobile games, this would be the best place to ask the quesiton.     I have been programming 'forever' in C++ and recently in C# with a sprinkle of Java thrown in for flavor.  However, all my games or apps are the standard .exe, run this in windows, variety.     Recently though, I have been trying to learn what language or languages I need to know to make games on a mobile device or that can be played from a web site.     I know the Apple market is fairly proprietary, and thus not owning a Mac, I dont think I have any possibility for developing anything for the IOS market.     The Android market, has so many different devices I'm confused of which one I should target (or if I even need to target anything specific) and definately what is the best Game Creation language to program it in.     I would love for my little games to not only be played on a mobile device, but also be playable from a web browser.  So I'm not sure if I could use the same language, or if the mobile device, and the web based, would need different languages for the program to be in.     My apologies if this is an 'over asked' question.  I promise you I have googled myself silly over the last few weeks trying to find answers.  I seriously just have lousy luck searching for answers.   BTW, I am only able to code from a windows platform.   Thanks in advance for any advice, or links you can provide to help me make the transition into the web / mobile device gaming arena.