|
Mixing Allegro 5 with OPENGL |
Kev Callahan
Member #6,022
July 2005
|
Hi, I have used Allegro 5 to setup things for OPENGL and am now quite happily bouncing a sphere, cylinder and flat surface around the screen.. What I now want to do (and not sure if this will kill framerate) is to write to the flat surface texture - for now just drawing a rectangle with Allegro 5 functions (guess I'd need to al_get_opengl_texture() again?)... I can't seem to get this to work - guess I'm screwing up the matrix stack in some way. So.. I tried saving the (GL_MODELVIEW_MATRIX) stack and restoring it - but again no luck. 1{
2 double matrix1[16]; //, matrix2[16];
3
4 ALLEGRO_BITMAP *save = al_get_target_bitmap();
5
6 glGetDoublev(GL_MODELVIEW_MATRIX, matrix1);
7 //glGetDoublev(GL_PROJECTION_MATRIX, matrix2);
8
9 al_set_target_bitmap(bmp[4]);
10 al_draw_rectangle(0, 0, count*6, count*6, al_map_rgb(255,255,255), 2);
11 al_set_target_bitmap(save);
12
13 glLoadMatrixd(matrix1);
14 //glLoadMatrixd(matrix2);
15}
16
17draw_opengl_objects();
Can anyone give me a few pointers please? Kev |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You should be able to draw normally to your surface. Each bitmap stores its own transformations. al_set_target_bitmap should take care of restoring its own transformations. Show more code. Like your draw_opengl_objects function. EDIT Kev Callahan said: The call to LoadMatrix may be overwriting a matrix set by al_set_target_bitmap. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Here's a simplified version.. In effect as soon as I mess around using al_set_target_bitmap() to the bitmap I want updated, the display gets corrupted in some way. 1 if ((draw == true) && (al_event_queue_is_empty(eventq)))
2 {
3 // backup / restore matrix
4 if (0)
5 {
6 //double matrix1[16], matrix2[16];
7 //ALLEGRO_BITMAP *save = al_get_target_bitmap();
8 //glGetDoublev(GL_MODELVIEW_MATRIX, matrix1);
9 //glGetDoublev(GL_PROJECTION_MATRIX, matrix2);
10 al_set_target_bitmap(bmp[4]);
11 al_draw_rectangle(0, 0, pos*6, pos*6, al_map_rgb(255,255,255), 2);
12 //al_set_target_bitmap(save);
13 //glLoadMatrixd(matrix1);
14 //glLoadMatrixd(matrix2);
15 }
16
17 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the depth buffer
18 //al_clear_to_color(al_map_rgb(0,0,0)); // clear screen
19
20 // **
21 glEnable(GL_DEPTH_TEST);
22 glEnable(GL_TEXTURE_2D);
23
24 glMatrixMode(GL_MODELVIEW); // set current matrix stack = GL_MODELVIEW
25 glLoadIdentity(); // replace current matrix with the identity matrix
26
27 // ** camera position
28 {
29 gluLookAt(0.0f, 0.0f, 1650.0f, // set camera at this xyz position
30 0.0f, 0.0f, 0.0f, // towrds this xyz position
31 0.2, 1.0f, 0.0f); // define Y is 'up' (note can use fractions to rotate camera)
32
33 pos += 1.0; pos = fmod(pos, 360.0);
34
35 glRotatef(pos/3.14, 2.0f, 0.0f, 0.0f); /* 'pos' deg orbit the X axis */
36 glRotatef(pos, 0.0f, 2.0f, 0.0f); /* 'pos' deg orbit the Y axis */
37 }
38
39 // ** flat image
40 {
41 if (0)
42 {
43 //this just draws to rectangle to screen
44 al_draw_rectangle(0, 0, pos*6, pos*6, al_map_rgb(255,255,255), 2);
45 }
46
47 draw_flat_texture(3, -400, -300, 256, 192);
48 }
49
50 glDisable(GL_TEXTURE_2D);
51 glDisable(GL_DEPTH_TEST);
52
53 glFlush();
54
55 draw = false;
56 al_flip_display();
and for completeness - 1void draw_flat_texture(GLuint id, float x, float y, float w, float h)
2{
3 glBindTexture (GL_TEXTURE_2D, id);
4 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
5 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
6
7 glPushMatrix(); // push on stack
8
9 glBegin(GL_QUADS);
10 glTexCoord2f(0, 0); glVertex3f(x, y, 0);
11 glTexCoord2f(0, 1); glVertex3f(x, h, 0);
12 glTexCoord2f(1, 1); glVertex3f(w, h, 0);
13 glTexCoord2f(1, 0); glVertex3f(w, y, 0);
14 glEnd();
15
16 glPopMatrix(); // pop off stack
17}
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Like I said, your call to LoadMatrix may be overwriting the projection view matrix that opengl uses. You're not setting it at all, so it's being changed by allegro, but not set back to normal by you. Also, you can use allegro's transforms to accomplish the same thing. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Sorry I'm confused a bit I'd like to see if I can continue using opengl (as I wanted to understand it a bit better), but may well decide to stick with Allegro. Edit: I have setup my projection matrix earlier; but I need to reset it again if I use allegro functions?? Hadn't imagined that stack would have been touched. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Yes, I believe allegro uses an orthographic projection matrix to draw to the back buffer. Each bitmap has two matrices associated with it. Edit - can you post a zip of your code? I'd like to play around with it a bit. Edit - at the very least you need to reset your model view and projection matrices after using allegro. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
No problem, I won't be able to till Monday unfortunately. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Resetting both matrices should fix your problem. They work in tandem. The MODELVIEW matrix takes care of moving the 'camera' and the PROJECTION matrix takes care of defining the view volume. So something like : /// Setup your camera with gluLookAt glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /// gluLookAt /// Setup an orthographic or perspective projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); /// glFrustum /// glOrtho See https://www.opengl.org/archives/resources/faq/technical/viewing.htm for some details. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Still no luck - source attached As soon as I call al_set_target_bitmap() [line 146] everything goes awry - re-setting up the cameras has no benefit. May have to delve again into library code to see/understand what's happening - suspect my knowledge of how the opengl pipeline works isn't helping. 1#include <stdio.h>
2
3#include "allegro5/allegro.h"
4#include "allegro5/allegro_image.h"
5#include "allegro5/allegro_opengl.h"
6#include "allegro5/allegro_primitives.h"
7
8#include "GL/glu.h"
9#include "math.h"
10#include "signal.h"
11
12#define MAXNUMBITMAPS 8
13
14#ifdef IMX6
15#define al_create_display(x,y) al_setup_display_imx6(x, y)
16#define al_init() al_init_imx6()
17#endif
18
19#ifndef WHERE
20#define WHERE() { printf("line %d\n", __LINE__); }
21#endif
22
23extern int al_init_imx6();
24extern ALLEGRO_DISPLAY *al_setup_display_imx6(int w, int h);
25
26float ss=1.0;
27float pos=0.0f;
28bool loop=true;
29
30int SCREEN_W = 1024;
31int SCREEN_H = 768;
32
33void draw_flat_texture(GLuint id, float x, float y, float w, float h);
34
35void sig_int(int s) { WHERE(); loop=false; }
36
37// ** camera_3D_setup *****************************************************************
38void camera_3D_setup()
39{
40 glMatrixMode(GL_PROJECTION); // current matrix stack (for subsequent matrix operations) = GL_PROJECTION
41 glLoadIdentity(); // replace the current matrix with the identity matrix
42 gluPerspective(35.0, (GLdouble)SCREEN_W / (GLdouble)SCREEN_H, 1.0, 2000.0);
43}
44
45// ** camera_2D_setup *****************************************************************
46void camera_2D_setup()
47{
48 glMatrixMode(GL_PROJECTION); // current matrix stack (for subsequent matrix operations) = GL_PROJECTION
49 glLoadIdentity(); // replace the current matrix with the identity matrix
50 glOrtho(0.0, (GLdouble)SCREEN_W, (GLdouble)SCREEN_H, 0.0, 0.0, 1.0);
51}
52
53ALLEGRO_BITMAP *bmp;
54GLuint oti;
55GLuint ogl_tex;
56
57
58// ** main *****************************************************************
59int main(int argc, char *argv[])
60{
61 ALLEGRO_DISPLAY *display = NULL;
62 ALLEGRO_EVENT_QUEUE *eventq = NULL;
63 ALLEGRO_TIMER *timer = NULL;
64
65 float fps = 60.0f;
66 bool draw = false;
67
68 signal(SIGINT, sig_int);
69 signal(SIGTERM, sig_int);
70 signal(SIGKILL, sig_int);
71
72 GLUquadricObj *quad_1 = gluNewQuadric();
73
74 // ** initialise graphics, extensions, etc
75 {
76 al_init();
77 al_init_image_addon();
78 al_init_primitives_addon();
79 al_install_keyboard();
80 }
81
82 // ** setup display
83 {
84 al_set_new_display_flags (ALLEGRO_OPENGL);
85 al_set_new_display_option (ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
86 display = al_create_display(SCREEN_W, SCREEN_H);
87 }
88
89 eventq = al_create_event_queue();
90 timer = al_create_timer(1.0f/fps);
91
92 // load bitmaps
93 al_set_new_bitmap_flags(ALLEGRO_MIPMAP | ALLEGRO_MIN_LINEAR);
94
95 bmp = al_load_bitmap("img_2.jpg");
96
97 ogl_tex = al_get_opengl_texture(bmp); // store OPENGL texture id
98
99 // ** register event sources
100 {
101 al_register_event_source(eventq, al_get_display_event_source (display));
102 al_register_event_source(eventq, al_get_timer_event_source (timer));
103 al_register_event_source(eventq, al_get_keyboard_event_source());
104 }
105
106 al_start_timer(timer);
107
108
109 // ** camera setup
110 {
111 // 2D camera
112 camera_2D_setup();
113
114 // default flat background
115 al_draw_bitmap(bmp, 0.0f, 0.0f, 0);
116
117 // 3D camera
118 camera_3D_setup();
119 }
120
121
122 // ** main loop
123 while (loop)
124 {
125 ALLEGRO_EVENT event;
126 al_wait_for_event(eventq, &event);
127
128 switch(event.type)
129 {
130 case ALLEGRO_EVENT_KEY_DOWN: case ALLEGRO_EVENT_DISPLAY_CLOSE: loop = false; break;
131 case ALLEGRO_EVENT_TIMER: draw = true; break;
132 default: break;
133 }
134
135 if ((draw == true) && (al_event_queue_is_empty(eventq)))
136 {
137
138
139 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the depth buffer
140
141
142 // draw something onto texture - *** this is very detrimental to everything(!) ***
143 //if (0)
144 {
145 // draw onto texture
146 al_set_target_bitmap(bmp);
147 //al_draw_rectangle(0, 0, pos*2, pos*2, al_map_rgb(255,255,255), 5);
148
149 // try setting up cameras again
150 //camera_2D_setup();
151 //camera_3D_setup();
152 }
153
154
155
156 // **
157 glEnable(GL_DEPTH_TEST);
158 glEnable(GL_TEXTURE_2D);
159
160 glMatrixMode(GL_MODELVIEW); // set current matrix stack = GL_MODELVIEW
161 glLoadIdentity(); // replace current matrix with the identity matrix
162
163 // ** rotate camera position around 0,0,0
164 {
165 pos += 1.0; pos = fmod(pos, 360.0);
166
167 gluLookAt(0.0f, 0.0f, 1650.0f, 0.0f, 0.0f, 0.0f, 0.2, 1.0f, 0.0f);
168 glRotatef(pos/3.14, 2.0f, 0.0f, 0.0f);
169 glRotatef(pos, 0.0f, 2.0f, 0.0f);
170 }
171
172 // ** draw (hopefully modified) flat image
173 {
174 draw_flat_texture(1, -400, -300, 256, 192);
175 }
176
177 // ** draw sphere
178 {
179 glBindTexture (GL_TEXTURE_2D, ogl_tex);
180 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
181 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
182
183 glPushMatrix(); // push on stack
184 glTranslatef( 1.0f*ss, 0.0f, 0.0f); // translation
185 glRotatef (-80.0f, 1.0f, 0.0f, 0.0f); // rotate X - fixed
186 glRotatef (-15.0f, 0.0f, 1.0f, 0.0f); // rotate Y - fixed
187 glRotatef (-20.0f, 0.0f, 0.0f, 1.0f); // rotate Z - fixed
188
189 gluQuadricTexture(quad_1, GL_TRUE); // start texture coordinate generation
190 gluSphere (quad_1, 70.0f, 28, 28); // radius, slices, stacks
191
192 gluQuadricTexture(quad_1, GL_FALSE); // halt texture coordinate generation
193 glPopMatrix(); // pop off stack
194 }
195
196 glDisable(GL_TEXTURE_2D);
197 glDisable(GL_DEPTH_TEST);
198 glFlush();
199
200 draw = false;
201 al_flip_display();
202 }
203 }
204
205 al_destroy_bitmap(bmp);
206
207 glDeleteTextures (1, &oti);
208 gluDeleteQuadric (quad_1);
209
210 al_flush_event_queue (eventq);
211 al_destroy_event_queue(eventq);
212 al_stop_timer (timer);
213 al_destroy_timer (timer);
214 al_destroy_display (display);
215
216 return 0;
217}
218
219// ** draw_flat_texture *****************************************************************
220void draw_flat_texture(GLuint id, float x, float y, float w, float h)
221{
222 glBindTexture (GL_TEXTURE_2D, id);
223 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
224 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
225
226 glPushMatrix(); // push on stack
227
228 glBegin(GL_QUADS);
229 glTexCoord2f(0, 0); glVertex3f(x, y, 0);
230 glTexCoord2f(0, 1); glVertex3f(x, h, 0);
231 glTexCoord2f(1, 1); glVertex3f(w, h, 0);
232 glTexCoord2f(1, 0); glVertex3f(w, y, 0);
233 glEnd();
234
235 glPopMatrix(); // pop off stack
236}
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I figured out the problem. In addition to resetting the model view and projection matrices, you need to set the bitmap drawing target to the backbuffer again. You're just drawing to the bitmap. That's why the results never show up. EDIT My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Well that makes (pretty obvious) sense, will mess around a bit with it tomorrow. Thanks. Thought I'd tried this, but probably without the resetting of the projection, etc.. Update - Well that's an improvement I think - I'm drawing rectangle(s) on the target and it's displaying it correctly when the camera is face-on.. [Update 2 - Actually not too sure how many rectangles are being drawn.. maybe only the first one - all very weird.] 2 very strange things though - . When the camera gets at an acute angle, the bitmap gets a sheen whereby you can see the original bitmap underneath with the rectangles fading on top. Maybe I'm seeing some default OPENGL lighting?? . Calling al_clear_to_color() after setting the target bitmap to the texture, fills the whole screen with colour rather than just the target. I'm thinking at the moment that A5 and OpenGL don't work together as easily as I'd hoped 1 if ((draw == true) && (al_event_queue_is_empty(eventq)))
2 {
3 //camera_2D_setup(); // makes no difference to output
4 // set up perspective projection
5 camera_3D_setup();
6
7 // do the 3D stuff
8 glMatrixMode(GL_MODELVIEW);
9 glLoadIdentity();
10
11 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the depth buffer
12
13 // **
14 glEnable(GL_DEPTH_TEST);
15 glEnable(GL_TEXTURE_2D);
16
17 glMatrixMode(GL_MODELVIEW); // set current matrix stack = GL_MODELVIEW
18 glLoadIdentity(); // replace current matrix with the identity matrix
19
20 // ** rotate camera position around 0,0,0
21 {
22 pos += 0.5; pos = fmod(pos, 1000.0);
23
24 gluLookAt(0.0f, 0.0f, 1650.0f, 0.0f, 0.0f, 0.0f, 0.2, 1.0f, 0.0f);
25 glRotatef(pos/3.14, 2.0f, 0.0f, 0.0f);
26 glRotatef(pos, 0.0f, 2.0f, 0.0f);
27 }
28
29 // ** draw (hopefully modified) flat image
30 {
31 draw_flat_texture(1, -400, -300, 256, 192);
32 }
33
34 glDisable(GL_TEXTURE_2D);
35 glDisable(GL_DEPTH_TEST);
36 glFlush();
37
38 //glMatrixMode(GL_PROJECTION);// makes no difference to output
39 //glPopMatrix(); // makes no difference to output
40 //glMatrixMode(GL_MODELVIEW); // makes no difference to output
41 //glLoadIdentity(); // makes no difference to output
42
43 //Do some 2D stuff
44 {
45 al_set_target_bitmap(bmp);
46
47 //al_clear_to_color(al_map_rgb(0,0,64)); // ** fills whole screen with colour :(
48 al_draw_rectangle(0, 0, pos, pos, al_map_rgb(255,255,0), 4);
49
50 al_set_target_backbuffer(display);
51 }
52
53 draw = false;
54 al_flip_display();
55 }
EDIT: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Don't forget to use 'send to top' when you make big edits like that. Something I see is that you're setting and loading the model view identity matrix twice. It's just extra code that doesn't do anything. As for clearing to color on the bitmap affecting the screen, I think there's something funny going on with the allegro part of things. I don't think it's drawing to the right texture target. It seems to draw fine to it's own bitmap, but not to the associated texture in my test cases. I'll keep investigating this when I have time. I made a post to [AD] about this, but no reply yet. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Thanks for the help Edgar. Will try to post my updated source tomorrow, I virtually started from scratch after what I'd learnt from your input. I now have a 'draw' loop that does some A5 2d, then some opengl and then more 2d before I flipscreen() .. I'm not in any way saying I'm doing it the correct way but it's looking hopeful..! UPDATE - Latest Code - Draws 10 cubes, all of same size, moves the camera to a new viewing position and displays some text on-screen. Seems way better mixing allegro and opengl now. Problem I now have (and I'm sure I've set something up incorrectly) is that near objects are smaller than distant objects.. Any idea on why this would happen? I'm guessing it's something to do with the way I've setup the depth buffer or something along those lines. UPDATE - SOLVED 1//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2void render_scene(void)
3{
4 static float ss=0;
5
6 // ** A5 2D bits
7
8 glDisable(GL_CULL_FACE);
9
10 ms = al_current_time();
11 ss = (ss+0.05); if (ss > 7) ss=0;
12
13 // ** modify bitmaps
14 {
15 al_set_target_bitmap(texture);
16 al_draw_bitmap(copybmp, 0, 0, 0);
17 al_draw_text(font, al_map_rgb(32,32,255), ss*100, 250, ALLEGRO_ALIGN_LEFT, "TEXTURE FONT");
18 al_draw_text(font, al_map_rgb(255,32,32), 1024-ss*100, 300, ALLEGRO_ALIGN_RIGHT, "TEXTURE FONT");
19 }
20
21
22 // reset destination target to display
23 al_set_target_backbuffer(display);
24
25 al_clear_to_color(al_map_rgb(8, 16, 32)); // set background color
26
27 al_draw_text(font, al_map_rgb(255,255,128), SCREEN_W/2, SCREEN_H -50, ALLEGRO_ALIGN_CENTER, "BACKGROUND TEXT");
28
29 // ** 3D
30
31 // setup perspepective projection
32 glMatrixMode(GL_PROJECTION);
33 glPushMatrix();
34 glLoadIdentity();
35 gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f);
36
37 //glViewport(0, 0, SCREEN_W/2, SCREEN_H/2); // restrict (stretch/shrink) output to an area of screen
38
39 // ** set camera position & orientation
40 {
41 cam.dest.x = 0.0f;
42 cam.dest.y = -5.0f;
43 cam.dest.z = 9.0f;
44
45 camera_move();
46
47 gluLookAt(cam.posn.x, cam.posn.y, cam.posn.z, cam.view.x, cam.view.y, cam.view.z, cam.orient.x, cam.orient.y, cam.orient.z);
48 }
49
50 // ** setup
51 glMatrixMode (GL_MODELVIEW); // to operate on model-view matrix
52 glEnable (GL_DEPTH_TEST); // enable depth testing for z-culling
53 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
54 glDepthFunc (GL_LESS); // set the type of depth-test
55 glShadeModel (GL_SMOOTH); // enable smooth shading
56 glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // nice perspective corrections
57 glEnable (GL_CULL_FACE);
58 glClearDepth (1.0f); // set background depth to farthest
59
60 // ** draw cubes
61 for (int i=0; i<10; i++)
62 {
63 glEnable (GL_TEXTURE_2D);
64 glBindTexture (GL_TEXTURE_2D, 5);
65
66 glLoadIdentity(); // reset the model-view matrix
67 glTranslatef(0.0f, 0.0f, -2.0f*i); // move right and into the screen
68 glRotatef (-ms*64*(i+1), 1, 1, 1);
69
70 draw_cube(2.0); //*i);
71 }
72
73 // ** return to 2D
74 glMatrixMode(GL_PROJECTION);
75 glPopMatrix();
76 glMatrixMode(GL_MODELVIEW);
77 glLoadIdentity();
78
79 glDisable(GL_CULL_FACE); // disable culling to allow 2D to show
80
81 // ** A5 2D bit
82 al_draw_textf(font, al_map_rgb(128,128,255), SCREEN_W/2, 40, ALLEGRO_ALIGN_CENTER, "FOREGROUND TEXT OUTPUT");
83}
84
85
86//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87void draw_cube(float size)
88{
89 glBegin(GL_QUADS);
90
91 glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, size); // bottom left - FRONT
92 glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, size); // bottom right
93 glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, size); // top right
94 glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, size); // top left
95 glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, -size); // bottom right - BACK
96 glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, -size); // top right
97 glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, -size); // top left
98 glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, -size); // bottom left
99 glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // top left - TOP
100 glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, size, size); // bottom left
101 glTexCoord2f(1.0f, 0.0f); glVertex3f( size, size, size); // bottom right
102 glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // top right
103 glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, -size, -size); // top right - BOT
104 glTexCoord2f(0.0f, 1.0f); glVertex3f( size, -size, -size); // top left
105 glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // bottom left
106 glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // bottom right
107 glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, -size); // bottom right - RIGHT
108 glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // top right
109 glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, size); // top left
110 glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // bottom left
111 glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, -size); // bottom left - LEFT
112 glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // bottom right
113 glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, size); // top right
114 glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // top left
115
116 glEnd();
117}
118
119//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120void camera_move()
121{
122 static float qq;
123
124 if (cam.accel < 0.5) cam.accel += 0.0001;
125 cam.posn.x += (cam.accel * (cam.posn.x < cam.dest.x));
126 cam.posn.x -= (cam.accel * (cam.posn.x > cam.dest.x));
127 cam.posn.y += (cam.accel * (cam.posn.y < cam.dest.y));
128 cam.posn.y -= (cam.accel * (cam.posn.y > cam.dest.y));
129 cam.posn.z += (cam.accel * (cam.posn.z < cam.dest.z));
130 cam.posn.z -= (cam.accel * (cam.posn.z > cam.dest.z));
131}
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Did you get your program to correctly draw to a texture and display the updated texture? Please post the entire code in a zip so I can play around with it again. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Yes I did still more tidying up to do as I get to understand a little more what the issues are and what doesn't have to be reset each frame... Unfortunately I don't have access to my PC, so here's a link to the zip I just created on my mobile. https://drive.google.com/file/d/0B1W53uB-s4sDRHpSSnlwcVZVUEE/view?usp=drivesdk Hopefully that will work. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
DOH. It doesn't work because your images aren't included with the zip. Or the font. I just replaced your resources with made up stuff and it works now. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Ah yeah sorry, thought you had those already Seems to be way better, don't know why I cant place text 'behind' 3d objects using allegro's functions, but could obviously work around that. Also i guess a fair bit of optimisation is possible as I'm calling a lot every frame, would imagine some of its not required apart from at initialisation. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Kev Callahan said: don't know why I cant place text 'behind' 3d objects using allegro's functions You can, you just have to draw it at the proper depth, either using z values, or a z translation matrix. Of course it will shrink into the background, so you have to draw it at 'real size'. You can also fake it by drawing your scene onto a buffer and then drawing your text on screen and your buffer on top of it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kev Callahan
Member #6,022
July 2005
|
Yeah know I can use an interim texture to do it.. (seems wasteful though) . |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Sure, you can draw it farther away at a larger scale, with OpenGL (the MODELVIEW matrix) or Allegro (a scale transform). Alternatively, you can draw your scene with an orthographic transform, but then everything the same size will be the same size regardless of distance. Perhaps you could combine drawing your scene in perspective projection and your text with orthographic projection and thereby 'cheat'. Worth a try anyway. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|