Sign in to follow this  

Couple o' Qs.

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this