glDrawPixels, glPixelTransferf, glPixelMap
I am writing a program where a bunch of symbols have to always be the same size and always face the camera. The easiest way is to load up a bitmap and glDrawPixels() to the screen. The catch is that the symbols have to change color. I need there to be just 1 image to load and then be able to change its color on the fly.
glPixelTransferf() can change the color but I have not been able to make this happen. glPixelMap() might be able to change the color but I am unable to get this to work either. The "Red Book" provides no examples and the explanation is not very good. Any help on this topic would be greatly appreciated.
.
.
.
loadGLTexture()
glRasterPos3f( 0.0f, 0.0f, 0.0f );
glPixelTransferf(); // There are so many variations that do
// not give me the desired result. I do
// not know what to put here anymore.
glDrawPixels( textureImage.getWidth(), textureImage.getHeight(),
GL_RGBA, GL_UNSIGNED_BYTE, textureImage.getByteArrayOfImage() );
.
.
.
quote:
Original post by David20321
Couldn''t you just use sprites?
Sprites would need to be recalculated for size and rotation every time the camera is moved. It would then be easier to use display lists instead of loading up files. But thanks for the suggestion I had to learn what a sprite was before I could respond and now I have a new technique I may be able to use later.
after youve done your 3d stuff do a 2d matrix projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,winWidth,0,winHeight,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
and draw all your gl_quads here (quicker than drawpixels)
also for the clolur thing enable blending + go glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
glColor4f(1,0,0,1); draw the object + it should be red?
btw im not to sure about this being the correct blending function (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR) just experiment
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,winWidth,0,winHeight,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
and draw all your gl_quads here (quicker than drawpixels)
also for the clolur thing enable blending + go glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
glColor4f(1,0,0,1); draw the object + it should be red?
btw im not to sure about this being the correct blending function (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR) just experiment
glDrawPixels() is TOO slow. Everyone have experienced this problem.
The solution is to use a simple quad and apply a texture. It''s simple, fast (if you have a 3D card), easy and you can do a lot of things that glDrawPixels() cannot do.
You can use color sum functions to blend primary color with texels (see glTexEnv() ) and achieve your effect.
If you want that your symbols will have the same size and face the camera...simply use an orthographic view ( see glOrtho() ) so you can work in 2D.
Of course you need to learn how to load and setup a texture but there are a lot of tutorials and I''m sure you will have no difficult. And you can use your knowledge for future applications.
This is the common way to draw ''sprites'' in OpenGL.
The solution is to use a simple quad and apply a texture. It''s simple, fast (if you have a 3D card), easy and you can do a lot of things that glDrawPixels() cannot do.
You can use color sum functions to blend primary color with texels (see glTexEnv() ) and achieve your effect.
If you want that your symbols will have the same size and face the camera...simply use an orthographic view ( see glOrtho() ) so you can work in 2D.
Of course you need to learn how to load and setup a texture but there are a lot of tutorials and I''m sure you will have no difficult. And you can use your knowledge for future applications.
This is the common way to draw ''sprites'' in OpenGL.
IpSeDiXiT
Thanks everyone for all your suggestions.
I still have not been able to get the pixeltransfer thing to work and I am convinced they put it in to frustrate me.
I did not mention that the work I am doing is required to be in 3D. The symbols are 2D. You can think of the symbols as letters of an alphabet never seen on the planet earth before. They float out in 3D space but must always face the camera and regardless of the Z value must always appear to be the same size.
I tried creating the HEX byte arrays for the symbols but some of the symbols are circles and they come out less than favorably.
Since there can be hundreds of symbols floating within the camera view and moving in various directions. I thought that using glBitmap would give me the speed I was looking for plus save me the hassle of having to come up with formulas to resize the symbols and rotate them towards the viewer. However making up all the hex values to define the byte arrays to pass to glBitmap was/is a hassle. glDrawPixels gave me the ability to draw the symbols in an editor and save them to a file. Load the files at run time and just change the colors of the symbols as needed at run time became the next problem.
Now that I have given even more information, if anyone has any more suggestions that will give me the desired results plus the maximum performance I would love to here from you.
Thanks for your time and patience.
X
I still have not been able to get the pixeltransfer thing to work and I am convinced they put it in to frustrate me.

I did not mention that the work I am doing is required to be in 3D. The symbols are 2D. You can think of the symbols as letters of an alphabet never seen on the planet earth before. They float out in 3D space but must always face the camera and regardless of the Z value must always appear to be the same size.
I tried creating the HEX byte arrays for the symbols but some of the symbols are circles and they come out less than favorably.
Since there can be hundreds of symbols floating within the camera view and moving in various directions. I thought that using glBitmap would give me the speed I was looking for plus save me the hassle of having to come up with formulas to resize the symbols and rotate them towards the viewer. However making up all the hex values to define the byte arrays to pass to glBitmap was/is a hassle. glDrawPixels gave me the ability to draw the symbols in an editor and save them to a file. Load the files at run time and just change the colors of the symbols as needed at run time became the next problem.
Now that I have given even more information, if anyone has any more suggestions that will give me the desired results plus the maximum performance I would love to here from you.
Thanks for your time and patience.
X
I suggest you to use ''GL_QUADS'' again...they are FASTER than glDrawPixels() and similar because a lot of video cards seem to have a very bad support for these functions.
You have to resize nothing.
Simply set your GL_PROJECTION matrix to an orthogonal view using glOrtho() or gluOrtho2D() and draw your quads.
Another advantage is that OpenGL will clip your offscreen images for you!
I have understood that you have some symbol (a kind of images) and you want change their color on the fly, is it right?
Simply draw every symbol in black and white in a large bitmap. For simplicity I save these bitmaps as 8 bit.
Black pixels should have index 0, white pixels index 255.
If your image editor does not allow this (ie: PaintShop Pro) you have to do by yourself
( byte=(byte==0?0:255) for every i ).<br> <br>Set up an image as a GL_ALPHA texture. For every symbol you have to draw a quad using corner coordinates and texture coordinates.<br>You can draw a quad with the same size of your symbol.<br><br>Then use glTexEnv() to specify the effect you want but I dont recall exactly (maybe GL_MODULATE ). <br>glEnable(GL_ALPHA_TEST).<br>You can specify a glColor()…if a pixel in your bitmap is white you will see the color else if the pixel is black you draw nothing (or viceversa).<br><br>But if you want there are other effects…for example you can use GL_BLEND and create semi transparent pixels to smooth their edges or use other glTexEnv() color sum functions…<br><br>Of course these are only ideas…you should check the functions in your guide.<br><br>http://www.opengl.org/Documentation/Version1.2/OpenGL_spec_1.2.1.pdf<br><br>You can also see some tutorials on bitmap font.<br><br>But be sure : it works ! </i>
You have to resize nothing.
Simply set your GL_PROJECTION matrix to an orthogonal view using glOrtho() or gluOrtho2D() and draw your quads.
Another advantage is that OpenGL will clip your offscreen images for you!
I have understood that you have some symbol (a kind of images) and you want change their color on the fly, is it right?
Simply draw every symbol in black and white in a large bitmap. For simplicity I save these bitmaps as 8 bit.
Black pixels should have index 0, white pixels index 255.
If your image editor does not allow this (ie: PaintShop Pro) you have to do by yourself
( byte=(byte==0?0:255) for every i ).<br> <br>Set up an image as a GL_ALPHA texture. For every symbol you have to draw a quad using corner coordinates and texture coordinates.<br>You can draw a quad with the same size of your symbol.<br><br>Then use glTexEnv() to specify the effect you want but I dont recall exactly (maybe GL_MODULATE ). <br>glEnable(GL_ALPHA_TEST).<br>You can specify a glColor()…if a pixel in your bitmap is white you will see the color else if the pixel is black you draw nothing (or viceversa).<br><br>But if you want there are other effects…for example you can use GL_BLEND and create semi transparent pixels to smooth their edges or use other glTexEnv() color sum functions…<br><br>Of course these are only ideas…you should check the functions in your guide.<br><br>http://www.opengl.org/Documentation/Version1.2/OpenGL_spec_1.2.1.pdf<br><br>You can also see some tutorials on bitmap font.<br><br>But be sure : it works ! </i>
IpSeDiXiT
I have the same problem as xdriver had.
I believe that the main problem is to display QUADS in 3D space using the glRasterPos3xx functions in order the quads to be placed correctly in 3D space. thus, the quads should not be scaled or rotated but must be positioned in the correct 3D position.
I am using orthographic projection for the 3D view.
Does anyone know the solution for this problem?
Thx
I believe that the main problem is to display QUADS in 3D space using the glRasterPos3xx functions in order the quads to be placed correctly in 3D space. thus, the quads should not be scaled or rotated but must be positioned in the correct 3D position.
I am using orthographic projection for the 3D view.
Does anyone know the solution for this problem?
Thx
Check out the NV_point_sprite and ARB_point_sprite extensions. They may be very useful, though they''re supported on limited hardware (GeForce3+ and Radeon8500+).
Have you looked at NeHe''s masking tutorial? Since you mentioned it floating in 2D that might be something to look at. I think it''s tutorial #20 but don''t quote me
.
To change the color of the texture, it''s always worked for me just to change the color of the quad I''m about to apply it to - I''ve never used blending.
Lastly, it is possible to combine 2D and 3D mode - you can render the 3D stuff in 3D mode and then change to 2D mode to add things to the screen. zedzeek alluded to this in his answer. I couldn''t ever get it to work without calling glDisable(GL_DEPTH_TEST) (though I didn''t try very hard
). I have a sample that does that on my site - the city. If you want to have a look, search for Render and DoOrthoModeRendering in main.cpp
Love means nothing to a tennis player

To change the color of the texture, it''s always worked for me just to change the color of the quad I''m about to apply it to - I''ve never used blending.
Lastly, it is possible to combine 2D and 3D mode - you can render the 3D stuff in 3D mode and then change to 2D mode to add things to the screen. zedzeek alluded to this in his answer. I couldn''t ever get it to work without calling glDisable(GL_DEPTH_TEST) (though I didn''t try very hard

Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement