I ) Introduction:
I'm working on some functions to handle alpha channel and blit an animation of them.
I was using Allegro functions before and it was working fine.
Now i wanna use allegroGL to improve speed, but i'm sure i'm mistaking with "how to use allegroGL & mix it with (opengl & allegro)" .
II ) What is my problem:
I got a SPRITE structure where i keep information for my anims.
Before trying to switch to AGL, i was saving each one pixel per pixel in a file , and reading them from this file.
It was keeping Alpha channel and working fine when set_alpha_blender & draw_trans_sprite.
Since i try to use AllegroGL instead of directX, i got the following problems:
1: never see the right color, always got various red colors.
2: a very bad FPS ( 6-9 )
3: not sure the result is using alpha
<b>III ) What i want to do :</b>
1: Make an initialize function to handle allegroGL for 2d iso using
2: Make a 'blit' function who use allegroGL instead of directX
3: Make a 'close' function to shutdown allegroGL
<b>IV ) so, WTF ?</b>
I'm for sure don't understanding how do GL work. I'm ok to draw lines, point , shapes. But with alpha i got a real problem.
Are function for direct use of BITMAP struct with allegroGL available ?
I was thinking to a allegro_gl_draw_trans_sprite(...) or something else.
If some can post code , i'll be very happy.
<b>V ) Function & structs used</b>
struct SPRITE:
sprite saver:
sprite loader:
sprite blitter:
allegroGL initialiser:
/* * TO DO : add initialize function */
allegroGL exit:
/* * TO DO : add allegroGL exit function */
<b>Conclusion:</b>
OpenGl make me crazy, i have not sleeped the last 3 night, i'm tired to search and obtain the same result . I need help. Thanks
OpenGl make me crazy, i have not sleeped the last 3 night, i'm tired to search and obtain the same result . I need help. Thanks
What about OpenLayer? It's made for this kind of a thing - to render bitmaps with an alpha channel using OpenGL.
Perhaps because i wanna know how to do this using only allegro & allegrogl
EDIT: But i'm also looking at openlayer. I'm not sure it has all the requirement i need , but i'll see. And if you know how to solve the topic with only allegro&allegrogl, don't wait and post your answer !
EDIT2: i'm looking at lots of code using allegroGL. The problem is that in fact , no one use the same organisation as the other. Some are calling allegro_gl_begin() ...end() where some others don't, to do the same thing.
Perhaps because i wanna know how to do this using only allegro & allegrogl
Why? OpenLayer isn't a wrapper for AllegroGL. It maps the functions to direct OpenGL calls, not to AllegroGL code. Thus it enables a lot of effects and blending modes which aren't possible with AllegroGL's interface.
Sorry, but I don't really know how to solve your problem. But in many cases if you wish to use pure OpenGL you could take a peek at OpenLayer's code.
Also you wouldn't need any wrapper sprite class because OpenLayer automates all the code you posted.
is openlayer compatible with C code ? and ansi ? and finally does it run under linux ?
OpenLayer is in ansi C++ and platform independant. But in most cases you should be able to write C code but compile it in C++.
1: never see the right color, always got various red colors.
2: a very bad FPS ( 6-9 )
This leads me to believe you got software rendering. After you set the mode, try printing out these strings:
printf("Graphics Driver: OpenGL %s (%s)\n" " %s detected\n" " Set %dx%d %dbpp %s mode\n", glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER), SCREEN_W, SCREEN_H, bitmap_color_depth(screen), (gfx_driver->windowed ? "windowed" : "fullscreen"));
If you are getting software rendering make sure you set and request GL_RENDERMETHOD 1.
Graphics Driver: OpenGL 2.0.0 (NVIDIA Corporation)
GeForce FX Go5700/AGP/SSE2/3DNOW! detected
Set 800x600 32bpp fullscreen mode.
GL_RENDERMETHOD is already requested.
About the wrong colors - i did the same thing, loading PCX, saving them back into my file format and then in my game - load my format back to bitmaps (and then converting into AllegoGL textures).
But my textures were not RED, they were BLUE. I found that there are problem using RGB, BRG, ... formats. So check if you use the same colors when saving, or change it as you load it back..
BTW: how do you draw the textures ? I thing, if you do it the OpenGl way, you should have a lot of more FPS..
(wrote this in private message)
Try AllegroGL examples, what fps you'll get. (or your video card is capable off)
This is my basic drawing function (I'm really a beginner in openGl, but this will do all you need - rotation, alpha, rgb changes).
1 | void mydraw_sp(GLuint mytexture, int x,int y,int r,int g,int b,int alpha,int angle,int w,int h) |
2 | { |
3 | //Enable texturing on all models for now on. |
4 | glLoadIdentity();//reset matrix |
5 | glBindTexture(GL_TEXTURE_2D, mytexture); |
6 | //Define how alpha blending will work and enable alpha blending. |
7 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
8 | glEnable(GL_BLEND); |
9 | glTranslatef(x, y, 0.0); |
10 | glRotatef(angle, 0, 0, 1.0); |
11 | glBegin(GL_QUADS); |
12 | //If we set the color to white here, then the textured quad won't be |
13 | //tinted red or half-see-through or something when we draw it based on |
14 | //the last call to glColor*(). |
15 | glColor4ub(r, g, b, alpha); |
16 | |
17 | //Draw our four points, clockwise. |
18 | glTexCoord2f(0, 0); glVertex3f(0,0, 0); |
19 | glTexCoord2f(1, 0); glVertex3f(w, 0, 0); |
20 | glTexCoord2f(1, 1); glVertex3f(w, h, 0); |
21 | glTexCoord2f(0, 1); glVertex3f(0, h , 0); |
22 | glEnd(); |
23 | glLoadIdentity(); |
24 | } |
I test with your drawing function.
I already got thosesilly colors.
What i do for saving and loading colors is:
WTF with this ? i can't see where it swap rgb to rbg or other.
When i use set_trans_blender & draw_trans_sprite, it works fine.
EDIT: i found this in the doc of allegroGL.
Important note: on 32 bit bitmap in RGBA mode, the alpha channel created by Allegro is set to all 0 by default. This will cause the texture to not show up in 32bpp modes if alpha is set. You will need to fill in the alpha channel manually if you need an alpha channel.
Help !
Ohé ! Bob Bombadil, Bob Bombadillon !
By the pixel, the bitmap, the screen and the layer,
By the great spirit of OpenGL , listen now and hear me
COme on, Bob Bombadil, my need is near me..
what bpp you're using when saving ? and when using OGL ? is it the same ?
bpp is the same at loading & saving. it's 32 bpp.
If someone have time to help, i have attached some tga that i can be able to quickly blit using allegro&agl.
Would be nice if you posted some code, on occasion.
Here i made an example, who works very slow.
you can download it
HERE (with source code & tga for test only 900 ko)
the source code is posted here too
agl.c:
1 | #include <stdlib.h> |
2 | #include <alleggl.h> |
3 | |
4 | |
5 | int it, |
6 | nbimg, |
7 | w,h; |
8 | |
9 | |
10 | char name[64]; |
11 | |
12 | |
13 | int main(int argc , char *argv[]) |
14 | { |
15 | |
16 | |
17 | BITMAP **tmp; /* for read the tga's */ |
18 | GLuint *tex; /* for store the index returned by allegr_gl_make_texture */ |
19 | |
20 | |
21 | allegro_init(); |
22 | install_mouse(); |
23 | |
24 | |
25 | set_color_depth(32); |
26 | |
27 | install_allegro_gl(); |
28 | |
29 | allegro_gl_clear_settings(); |
30 | allegro_gl_set (AGL_COLOR_DEPTH , 32); |
31 | allegro_gl_set (AGL_DOUBLEBUFFER , 1 ); |
32 | allegro_gl_set (AGL_RENDERMETHOD , 1 ); |
33 | allegro_gl_set (AGL_FULLSCREEN , 1 ); |
34 | allegro_gl_set (AGL_REQUIRE, AGL_RENDERMETHOD |AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_FULLSCREEN); |
35 | |
36 | |
37 | if (set_gfx_mode(GFX_OPENGL_FULLSCREEN, 800, 600, 0, 0) < 0) |
38 | { |
39 | allegro_message("DUCK AND COVER!\n"); |
40 | exit(EXIT_FAILURE); |
41 | } |
42 | |
43 | |
44 | allegro_gl_use_alpha_channel(TRUE); |
45 | |
46 | |
47 | nbimg = atoi( argv[1] ); |
48 | tmp = malloc( nbimg * sizeof( BITMAP *)); |
49 | tex = malloc( nbimg * sizeof( GLuint )); |
50 | |
51 | |
52 | for( it = 0 ; it < nbimg ; it ++) { |
53 | |
54 | sprintf( name , "DATA/a+%04d.tga" , it + 1 ); |
55 | |
56 | printf("name: %s\n",name); |
57 | |
58 | tmp[it] = load_bitmap(name, NULL); |
59 | |
60 | w=tmp[it]->w; |
61 | h=tmp[it]->h; |
62 | |
63 | if (tmp[it] == NULL) |
64 | { |
65 | allegro_message("Error: couldn't find %s",name); |
66 | exit(EXIT_FAILURE); |
67 | } |
68 | |
69 | tex[it] = allegro_gl_make_texture(tmp[it]); |
70 | |
71 | destroy_bitmap(tmp[it]); |
72 | |
73 | } |
74 | |
75 | install_keyboard(); |
76 | |
77 | glClearColor(0, 0, 0, 0); |
78 | |
79 | glDisable(GL_DEPTH_TEST); |
80 | glDisable(GL_LIGHTING); |
81 | |
82 | glMatrixMode(GL_PROJECTION); |
83 | glLoadIdentity(); |
84 | |
85 | glOrtho( 0, SCREEN_W, SCREEN_H, 0, -1, 1 ); |
86 | |
87 | glMatrixMode(GL_MODELVIEW); |
88 | glLoadIdentity(); |
89 | |
90 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
91 | |
92 | it=-1; |
93 | |
94 | glEnable(GL_TEXTURE_2D); |
95 | |
96 | |
97 | w = w /2; |
98 | h = h /2; |
99 | |
100 | printf("Graphics Driver: OpenGL %s (%s)\n" |
101 | " %s detected\n" |
102 | " Set %dx%d %dbpp %s mode\n", |
103 | glGetString(GL_VERSION), glGetString(GL_VENDOR), |
104 | glGetString(GL_RENDERER), |
105 | SCREEN_W, SCREEN_H, bitmap_color_depth(screen), |
106 | (gfx_driver->windowed ? "windowed" : "fullscreen")); |
107 | |
108 | do{ |
109 | |
110 | it++; |
111 | if(it>=nbimg)it=0; |
112 | |
113 | glBindTexture(GL_TEXTURE_2D, tex[it]); |
114 | |
115 | glClear(GL_COLOR_BUFFER_BIT); |
116 | |
117 | glEnable(GL_BLEND); |
118 | |
119 | glBegin(GL_QUADS); |
120 | glColor3f(1.0f, 1.0f, 1.0f); |
121 | glTexCoord2f(0.0f, 0.0f); |
122 | glVertex3f(mouse_x - w , mouse_y - h , 0.0f); |
123 | glTexCoord2f(1.0f, 0.0f); |
124 | glVertex3f(mouse_x + w , mouse_y - h , 0.0f); |
125 | glTexCoord2f(1.0f, 1.0f); |
126 | glVertex3f(mouse_x + w , mouse_y + h , 0.0f); |
127 | glTexCoord2f(0.0f, 1.0f); |
128 | glVertex3f(mouse_x - w , mouse_y + h , 0.0f); |
129 | glEnd(); |
130 | |
131 | glDisable(GL_BLEND); |
132 | |
133 | allegro_gl_flip(); |
134 | |
135 | }while(!key[KEY_ESC]); |
136 | |
137 | for(it = 0 ; it < nbimg ; it ++ ) |
138 | glDeleteTextures(1, &tex[it]); |
139 | |
140 | remove_allegro_gl(); |
141 | |
142 | allegro_exit(); |
143 | |
144 | return 0; |
145 | } |
146 | END_OF_MAIN() |
It's working, good colors, but it is sloooow and the drivers is good.
EDIT: i'm allowed myself to cut&paste your 5 lines of code, kittycat, and the return is always :
Graphics Driver: OpenGL 2.0.0 (NVIDIA Corporation)
GeForce FX Go5700/AGP/SSE2/3DNOW! detected
Set 800x600 32bpp fullscreen mode
EDIT2: to test it, launch a command, and go to the atb directory, launch atb 35 (there are 35 tga in /DATA)
EDIT3: can't be able to speed this up... can it be a size issue? lemme check.
EDIT4: I test all examples in AllegroGL examples directory. Results are: exmasked is as slow as the pasted code. WTF !!²²!!
EDIT5: What can be the raison for exmasked to be so slow ? it is right for colors, but it is already so slow...
!!! IT WAS A DRIVER ISSUE !!! Nvidia's Update for GeforceFX Go 5700 are bad ... everything is better now i loose more than a week for a driver issue...
Sorry to have make you loose times ... can someone post for me to give cookies ?
Bump
And no thanks to all for helping out (BAF is coockied because i bore him a lot on msn all along the day and he bumps :p )