Couple o' Qs.

Started by
7 comments, last by Harryu 16 years, 11 months ago
I didn't know where to put this so i put it here, where everyone looks. I have a problem with the key repeat thingie. I want something to happen constantly while a key is pressed (like a sprite going left), but it only goes left one unit and then it pauses and then starts repeating, like it is supposed to. How can make it so that it doesn't pause? I'm using OpenGL with GLUT if it matters. My second question is OpenGL related but anyways... How can i make a part of a texture transparent? If i make a texture with black background and a red circle in the middle, how do i make the black transparent? I'm using Targa format for my textures at the moment. I only have code for .raw and .tga which is tedious when i want to make a simple texture (have to mess with photoshop). Are there any good code for .bmp or jpg maybe? I saw some .bmp stuff on NeHe's guide but it is with AUX window system so... any good for GLUT (I can't write my own... yet.)? Thanks.
Advertisement
The best way to make a texture transparent is to load an image with an alpha channel (ie. RGBA rather than just RGB colour data). jpg and bmp only support RGB, but I think tga can contain an alpha channel, as can png. You should look though photoshop and see how you can create an alpha layer and then export the final image as tga or png. You can use devIL to load images, it supports tga and png formats (and a whole load of others).
Alternatively, you could loop through each pixel of the bitmap and check which ones match your specified colour key value. Then give all matching pixels an alpha value of 0. Do this before you create a texture out of the bitmap.
Quote:Original post by cresty
I have a problem with the key repeat thingie. I want something to happen constantly while a key is pressed (like a sprite going left), but it only goes left one unit and then it pauses and then starts repeating, like it is supposed to. How can make it so that it doesn't pause? I'm using OpenGL with GLUT if it matters.


Basically, you don't want to use the key repeat feature. You need to poll the key directly to find out if it is up or down. There are various ways to do this, but I don't believe GLUT supports it. In Window's, you can use GetAsyncKeyState() or DirectInput, orlook for WM_KEYUP and WM_KEYDOWN messages.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:Original post by JohnBolton
Quote:Original post by cresty
I have a problem with the key repeat thingie. I want something to happen constantly while a key is pressed (like a sprite going left), but it only goes left one unit and then it pauses and then starts repeating, like it is supposed to. How can make it so that it doesn't pause? I'm using OpenGL with GLUT if it matters.


Basically, you don't want to use the key repeat feature. You need to poll the key directly to find out if it is up or down. There are various ways to do this, but I don't believe GLUT supports it. In Window's, you can use GetAsyncKeyState() or DirectInput, orlook for WM_KEYUP and WM_KEYDOWN messages.


And you can use SDL (www.libsdl.org), if you're not using windows (or you just want to be more cross-platform-compatible).

Good luck. :)
Loading a bmp file manually
Another bmp loader
Thanks for the replies.

Is there really no way to fix the keyboard problem with GLUT? If not... are there any good tutorials for OpenGL with Win32 windowing system?

Thanks.
There definitely should be a way to fix this in GLUT; there's some command for key repeat rate, IIRC.
For the key repeat problem, you could try the method I used for my Java game engine. Basically, I maintain an array (ArrayList, as it were) of all the keys that have been pressed, but not yet released. So every time there is a key press, I check to see if that key is in the list, and if it's not then I add it. If a key is released, I remove the key from my list. When you want to check a key state, you can just check the array.

Hope that helps,
Harry

This topic is closed to new replies.

Advertisement