![]() |
|
display screen manipulation |
user1061
Member #15,774
October 2014
|
1#include <allegro5\allegro.h>
2#include <allegro5\monitor.h>
3#include <allegro5\allegro_primitives.h>
4#include <allegro5\allegro_font.h>
5#include <allegro5\allegro_ttf.h>
6#include<allegro5/allegro_image.h>
7
8
9
10int main(void)
11{
12 //detecting monitor or monitor fullsize and resolution
13 ALLEGRO_MONITOR_INFO Monitor_info; // not without monitor.h
14 int Dwidth; // screenwidth absolute
15 int Dheight; // screenheight absolute
16
17
18 ALLEGRO_DISPLAY *display = NULL;
19 ALLEGRO_TIMER *timer = NULL;
20
21
22 if(!al_init()) //initialize Allegro
23 return -1;
24
25 al_get_monitor_info(0, & Monitor_info);
26
27 Dwidth=(int) Monitor_info.x2;
28 Dheight=(int) Monitor_info.y2;
29 int width = Dwidth - 40, w = width;
30 int height = Dheight - 40, h = height;
31 //w = 800, h = 600;
32
33
34 int count = 0;
35 int FPS = 60;
36
37 bool done = false;
38
39 al_set_new_display_flags(ALLEGRO_RESIZABLE);
40 al_set_window_title(display, "Console Machine");
41
42 timer = al_create_timer(1.0 / FPS);
43
44
45
46 display = al_create_display(w, h); //create our display object
47
48 if(!display) //test display object
49 return -1;
50
51 al_init_image_addon();
52 al_init_primitives_addon();
53 al_init_font_addon();
54 al_init_ttf_addon();
55 al_install_keyboard();
56 al_install_mouse();
57
58 // setting keyboard variable
59 ALLEGRO_KEYBOARD_STATE KeyState;
60
61 // setting font variables
62 ALLEGRO_FONT *font18 = al_load_font("arial.ttf", 18, 0);
63
64
65 // registering events to event queue
66
67 ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
68 al_register_event_source(event_queue, al_get_keyboard_event_source());
69 al_register_event_source(event_queue, al_get_mouse_event_source());
70 al_register_event_source(event_queue, al_get_timer_event_source(timer));
71 al_register_event_source(event_queue, al_get_display_event_source(display));
72
73
74 al_start_timer(timer);
75
76
77
78
79 while(!done)
80 {
81 ALLEGRO_EVENT events;
82 al_wait_for_event(event_queue, &events);
83 al_get_keyboard_state(&KeyState);
84
85 if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE || al_key_down(&KeyState, 59))
86 {
87 done = true;
88 }
89 if(!done)
90 {
91 count++;// added if for when changing to states, then !done can be replaced.
92 }
93 int dw = al_get_display_width(display);
94 int dh = al_get_display_height(display);
95
96 //bool al_acknowledge_resize(ALLEGRO_DISPLAY *display)
97
98 if(dw != w || dh != h)
99 {
100 count = 0;
101
102 }
103
104
105 //creating the screen output
106
107
108 al_draw_textf(font18, al_map_rgb(255, 0, 255), 20, 20, ALLEGRO_ALIGN_LEFT, "Cycles: %i", count);
109 al_draw_textf(font18, al_map_rgb(255, 0, 255), 20, 40, ALLEGRO_ALIGN_LEFT, "dw: %i", dw);
110 al_draw_textf(font18, al_map_rgb(255, 0, 255), 20, 60, ALLEGRO_ALIGN_LEFT, "dh: %i", dh);
111
112 //for (int i = 0; i < 800; i )
113
114
115
116
117 // clear for next cycle through
118 al_flip_display();
119 al_clear_to_color(al_map_rgb(0,0,0));
120
121 }
122
123
124 //destroy the pointers
125 al_destroy_timer(timer);
126 al_destroy_display(display);
127 al_destroy_font(font18);
128 al_destroy_event_queue(event_queue);
129
130 return 0;
131}
I was trying to make a workable resizable display for a program I have in mind. I am obviously very new to allegro (5) and not yet that good in c++ either, that for prelimanary. so you may take that into account while answering if any!;D Problem: Above code works, wich ever display size I give in the top of the file, but when resizing the whole display just gets bigger with the window! And when resized, when reading out the display size: int dw = al_get_display_width(display); returns the initial value wich I specified at first making the display1 What I want to get though is a display that where I have a map the size of whatever, say 20 times the size of the screen, that my resized window passes over the map and show a bigger portion of the map instead of what it does here, simply getting bigger or smaller letters. In addition the way to continue should be when going with the mousepointer to NSWE(ast) on the map, that the remainder of whats on the map gets on the whatever size display. To conclude, any tip on where to get better info on how to get up to speed with the various ways of reading out the functions, or learning to use them other then the manual, codingmadeeasy or Mike Geigs tutorial on the subject could be helpfull! |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I believe you need to handle the resize events, and call al_acknowledge_resize in order for the display backbuffer to be properly resized. Also, please surround posted code with <code></code> tags. -- |
user1061
Member #15,774
October 2014
|
I did the tags (), thanks for answering, as in the code I remarked the al_acknowledge_resize already, wanted to implement it, but I stumbled on the fact that I cannot find anywhere a good example from wich to obtain the knowledge how to handle this. I have a hard time figuring out how to implement things from the manual only. Many objects can just be pasted in and will eventualy come together in the program and are not dependant on if the screen question is solved as asked above, but it is part of the feature the end program will have to have or get stuck on a 800 by 600 screen! |
Thomas Fjellstrom
Member #476
June 2000
![]() |
There is a folder in the allegro source archive called 'examples'. In there you can find plenty of examples on how to use various allegro features In this case, there is a display resize event you handle, and call al_acknowledge_resize in it, or as a result of it "at some point in time". -- |
user1061
Member #15,774
October 2014
|
Okey, got it. Thank you for asking, search on.... So I hope there is someone that can help me, instead of telling me to tag my code and stating the obvious. And to ad to my own 2nd post the question is more urgent then I lead to believe, not for that I cannot go try code other parts of the program, but that the existance of the lack of an answer holds me from freely coding that. So thanks ahead if someone can help me out! |
LennyLen
Member #5,313
December 2004
![]() |
user1061 said: So I hope there is someone that can help me, instead of telling me to tag my code and stating the obvious. With that kind of attitude, you're lucky if you get any help at all. Luckily Thomas has already given you everything you need to know. If you read that page it even tells you exactly which of the Allegro examples use that function.
|
pkrcel
Member #14,001
February 2012
|
Well, you TRIED to use al_acknoloedge display resize but you aren't responding to the correspondent event. To be honest, you aren't even chekcing the events apart for the exit button Keypress. Is this too obvious? Lenny told you rightly to go check usage examples, allegro example programs are a wealth of code, there's a HUNDRED of them and are toroughly documenting most library features. It is unlikely that Google shares your distaste for capitalism. - Derezo |
user1061
Member #15,774
October 2014
|
Well I tried to be as thourough as possible in the question, and comming to the code I pasted in, true I stripped it to the minimum and didnt bother handling stuf that were not needed for the question. And I read all forum. This is by far mentioned to be the place to get information about allegro, but I am send on to do what I already did by the one that appears to be the moderator here since he is in all the posts I read. So thanks for nothing then. Didnt ask the question to get in a discussion that seams needed after the 2nd answer of Thomas, btw appears to be his standard answer in all the posts to. I editted the what you call attitude part in because after reading all forum I got that he was leading me on with his answer and that there are some that help and some that just make comments in the various posts. But I gather you all now have to defend your friend, who gave me a brush of after my first question, and honestly nobody even cared to read or address the questions there. |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Wait until you're not mad anymore and come back and read this entire thread again. They all watch too much MSNBC... they get ideas. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
user1061 said: This is by far mentioned to be the place to get information about allegro, but I am send on to do what I already did by the one that appears to be the moderator here since he is in all the posts I read. I'm just a guy who likes to try to help. Quote: Didnt ask the question to get in a discussion that seams needed after the 2nd answer of Thomas, btw appears to be his standard answer in all the posts to. Heh. Well, when you need more information than the docs provide, going to the examples is a good next step. As for the resize display info, that is the only valid answer for the question you were asking. Quote: I editted the what you call attitude part in because after reading all forum I got that he was leading me on with his answer and that there are some that help and some that just make comments in the various posts. But I gather you all now have to defend your friend, who gave me a brush of after my first question, and honestly nobody even cared to read or address the questions there. I'm not sure how you came to that conclusion. I honestly tried to help you. -- |
user1061
Member #15,774
October 2014
|
So hope we can get of that playing the man, and yep! thomas told me pkrcel to go use al_acknowledge_display, with wich I got stuck and prompted me to ask the question in the first place! So the answer is useless to me and not adressing the question. I gather it is from the onset 3 bits of code I dont grasp, but being honest in a lack of knowledge seams to lead here to being trolled. Talking about attitude. If he doesnt want to answer the question why bother making more then the first post, I put the code tags in, I am new to this forum so didnt know right away how to handle that either. So thanks to Thomas thats remedied. But if sending people on that are looking for an answer, a step up, and then telling them because he forgot the code tags, to go look elsewhere isnt the way this forum is advertised realy. Come to think of it, if making truely a clone of minecraft, he must have addressed the very same issue about the the screen as where my question was about part 1. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
user1061 said: thomas told me pkrcel to go use al_acknowledge_display, with wich I got stuck and prompted me to ask the question in the first place! So the answer is useless to me and not adressing the question. But it isn't useless. I said to call it when handling the DISPLAY RESIZE event. If you can't figure that out yourself immediately, there is more than one example that handles display resizes. Quote: I gather it is from the onset 3 bits of code I dont grasp, but being honest in a lack of knowledge seams to lead here to being trolled. People with an honest lack of knowledge don't often get trolled. but a whiff of attitude gets you some unwanted attention pretty quickly. Quote: But if sending people on that are looking for an answer, a step up, and then telling them because he forgot the code tags, to go look elsewhere isnt the way this forum is advertised realy So telling you to look at ALLEGRO's own examples is telling you to "look elsewhere"? I honestly don't think it is. What you are looking for it seems is a hand out. Someone to give you the exact code you are looking for, without you having to do it yourself. That is something most of us here try not to do (it happens occasionally when we're feeling extra charitable), because it doesn't actually help the person we're trying to help to learn. I do actually know how to get allegro to allow a window to be resized. I pointed you to the examples so you could see how it was done. I also know how to get a large world rendered in a window smaller than the world[1]. But that is a more advanced topic that should come after figuring out how to get your window resizeable. References
-- |
user1061
Member #15,774
October 2014
|
I tried follow codemadeeasy tutorial, jumped back and forth the last month between mike geig and the first mentioned tutorial, is in the first question to btw. And you may have noticed that having followed codemade easy tutorial that is quite a bit of effort, nothing ever is easy there these days since he retracted the code examples. Mike Geigs tutorial was a refreshing restart but without that, there is very little documentation about allegro 5, wich sparked me to ask about any place to find good tutorials! I understand solving individuals problems with grasping how to implement this or that function is not mandatory, but looking at code is all I do these days. At least php, javascript and c++ are good documented, but I stil think that allegro can do much more easier what I want to accomplish on short term, and so I just need a step up from Mike Geig, since he handles lots of things, and maybe if codemadeeasy its website is up again can solve some issues. Having followed Mike Geig I now can handle what he exampled, figured out the monitor part on my own, but yeah got stuck and learned that Mike and codemade easy always step over the realy interesting knowledge parts. So yeah I know I lack knowledge, and yeah I am almost fluent in javascript, wich helps in understanding concepts in programming, but I just stumble in every new routine in allegro now. Basicly you can say that if it was not in the Mike Geig tutorial I cannot use it, because Mike never explains the concept of handling it in reality, but just gives a good starting point. So moving to close this thread to whomever is moderator. Its of topic! |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I still suggest taking a look at the example code in the allegro source Showing a little initiative goes a long way. -- |
user1061
Member #15,774
October 2014
|
Well now we are getting somewhere, a link would be nice! |
Thomas Fjellstrom
Member #476
June 2000
![]() |
examples/ex_display_events.c is a good option -- |
user1061
Member #15,774
October 2014
|
yeah thanks, looked at it loaded it, but thats why I asked here, since I already found not working examples by the dozen, one of the reasons I put in the top of my question: This file works. Will try reverse engineer it even so,... |
Thomas Fjellstrom
Member #476
June 2000
![]() |
That's the thing, these are THE allegro examples. If they don't work its probably a bug and should be reported. -- |
user1061
Member #15,774
October 2014
|
no bug, just common.c not included, so cant see a working examp.. One of the reasons I started writing snippets that work, if my collection is of a mature size it no doubt will be on my website someday. Going slow though gathering all examples, no one in my vicinity using allegro, and not much help elsewhere, yeah broken files... |
pkrcel
Member #14,001
February 2012
|
Sorry user1061 but I have a really hard time getting your point How come they do not work? Which files are "broken"? It is unlikely that Google shares your distaste for capitalism. - Derezo |
Thomas Fjellstrom
Member #476
June 2000
![]() |
The build system should let you compile the examples just fine. -- |
user1061
Member #15,774
October 2014
|
I must have done something wrong then, when i try it it says missing common.c and it doesnt compile. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
You tried using allegro's cmake based build system? -- |
user1061
Member #15,774
October 2014
|
Yeah have cmade somewhere downloaded sometime, wasnt for allegro btw! Answer was as simple as it could be and I was just overthinking the whole problem! And what the point??! Well so many broken links and so many tutorials without a feedback after some time, and so many people asking newbie questions everywhere on different forums and most questions get trolled over by the shortsighted hardcore gamers wanting to use and abuse and giving misdirections simple for the fun of it. While those that do that simply forget that when, like here on an allegro forum, the language is for creating games, the forum is not meant for trolling like gamers do in all those games they play. But hey what to expect, gamers are so used to troll newbies they simply dont know better. So yeah solution was very simple, I just waited patiently read the rest of forum, allegro is only a sidestep for me since I wanted to use the graphical interface a technical program, so lots to calculate there, and for the graphics, well as in games, you do want it to look nice!:P Whomever realy helped thanks.;) |
|