Skip to content

Commit

Permalink
allegro
Browse files Browse the repository at this point in the history
  • Loading branch information
sechshelme committed Apr 2, 2023
1 parent 313dfca commit cf1aaf3
Show file tree
Hide file tree
Showing 19 changed files with 969 additions and 18 deletions.
Binary file added Allegro_5/C/a.out
Binary file not shown.
Binary file added Allegro_5/C/a.out.xxx
Binary file not shown.
106 changes: 106 additions & 0 deletions Allegro_5/C/allegro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* This program uses the Allegro game library to display a blank window.
*
* It initializes the display and starts up the main game loop. The
* game loop only checks for two events: timer (determined by the FPS)
* and display close (when the user tries to close the window).
*
* http://www.damienradtke.org/building-a-mario-clone-with-allegro
*/

// https://gist.github.com/dradtke/2494024

#include <stdio.h>
#include <allegro5/allegro.h>
//#include <allegro/allegro.h>

const float FPS = 60;

int main(int argc, char *argv[])
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;

bool running = true;
bool redraw = true;

// Initialize allegro
if (!al_init()) {
fprintf(stderr, "Failed to initialize allegro.\n");
return 1;
}

// Initialize the timer
timer = al_create_timer(1.0 / FPS);
if (!timer) {
fprintf(stderr, "Failed to create timer.\n");
return 1;
}

// Create the display
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "Failed to create display.\n");
return 1;
}

// Create the event queue
event_queue = al_create_event_queue();
if (!event_queue) {
fprintf(stderr, "Failed to create event queue.");
return 1;
}

// Register event sources
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_timer_event_source(timer));

// Display a black screen
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();

// Start the timer
al_start_timer(timer);

// Game loop
while (running) {
ALLEGRO_EVENT event;
ALLEGRO_TIMEOUT timeout;

// Initialize timeout
al_init_timeout(&timeout, 0.06);

// Fetch the event (if one exists)
bool get_event = al_wait_for_event_until(event_queue, &event, &timeout);

// Handle the event
if (get_event) {
switch (event.type) {
case ALLEGRO_EVENT_TIMER:
redraw = true;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
running = false;
break;
default:
fprintf(stderr, "Unsupported event received: %d\n", event.type);
break;
}
}

// Check if we need to redraw
if (redraw && al_is_event_queue_empty(event_queue)) {
// Redraw
al_clear_to_color(al_map_rgb(0, 255, 0));
al_flip_display();
redraw = false;
}
}

// Clean up
al_destroy_display(display);
al_destroy_event_queue(event_queue);

return 0;
}
39 changes: 39 additions & 0 deletions Allegro_5/C/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
https://liballeg.org/

#Allegro 5
Download:
[https://github.com/liballeg/allegro5]

```bash
cmake -S . -B build && cmake --build build
su
cmake --install build --prefix=/usr
```
oder
```bash
mkdir build
cd build
cmake ..
```
## Kompilieren

```bash
gcc allegro.c -lallegro
gcc allegro.c `pkg-config allegro-5 --libs --cflags`
`
```

#Allegro 4.x
```bash
apt install liballegro4-dev
```

## Kompilieren
```bash
gcc allegro.c -I/usr/local/include -L/usr/local/lib -lallegro
```




Binary file added Allegro_5/allegro.pas-5.2.b.1-1-src-pas.7z
Binary file not shown.
43 changes: 43 additions & 0 deletions Allegro_5/codeblocks/Allegro/Allegro.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Allegro" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Allegro" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Allegro" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="`pkg-config allegro-5 --cflags`" />
</Compiler>
<Linker>
<Add option="`pkg-config allegro-5 --libs`" />
</Linker>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions />
</Project>
</CodeBlocks_project_file>
108 changes: 108 additions & 0 deletions Allegro_5/codeblocks/Allegro/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* This program uses the Allegro game library to display a blank window.
*
* It initializes the display and starts up the main game loop. The
* game loop only checks for two events: timer (determined by the FPS)
* and display close (when the user tries to close the window).
*
* http://www.damienradtke.org/building-a-mario-clone-with-allegro
*/

// https://gist.github.com/dradtke/2494024

#include <stdio.h>
#include <allegro5/allegro.h>
//#include <allegro/allegro.h>

const float FPS = 60;
char col=0;

int main(int argc, char *argv[])
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;

bool running = true;
bool redraw = true;

// Initialize allegro
if (!al_init()) {
fprintf(stderr, "Failed to initialize allegro.\n");
return 1;
}

// Initialize the timer
timer = al_create_timer(1.0 / FPS);
if (!timer) {
fprintf(stderr, "Failed to create timer.\n");
return 1;
}

// Create the display
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "Failed to create display.\n");
return 1;
}

// Create the event queue
event_queue = al_create_event_queue();
if (!event_queue) {
fprintf(stderr, "Failed to create event queue.");
return 1;
}

// Register event sources
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_timer_event_source(timer));

// Display a black screen
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();

// Start the timer
al_start_timer(timer);

// Game loop
while (running) {
ALLEGRO_EVENT event;
ALLEGRO_TIMEOUT timeout;

// Initialize timeout
al_init_timeout(&timeout, 0.06);

// Fetch the event (if one exists)
bool get_event = al_wait_for_event_until(event_queue, &event, &timeout);

// Handle the event
if (get_event) {
switch (event.type) {
case ALLEGRO_EVENT_TIMER:
redraw = true;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
running = false;
break;
default:
fprintf(stderr, "Unsupported event received: %d\n", event.type);
break;
}
}

// Check if we need to redraw
if (redraw && al_is_event_queue_empty(event_queue)) {
// Redraw
al_clear_to_color(al_map_rgb(0, col, 0));
col++;
al_flip_display();
redraw = false;
}
}

// Clean up
al_destroy_display(display);
al_destroy_event_queue(event_queue);

return 0;
}
1 change: 1 addition & 0 deletions Allegro_5/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://allegro-pas.sourceforge.net/
4 changes: 2 additions & 2 deletions Altes_SDL-1.2/40_-_Multithreading_Mandelbrot/Project1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const
Screen_Width: integer = 1280;
Screen_Heigth: integer = 960;
Screen_Heigth: integer = 800;
Screen_BPP: integer = 32;

ThreadCount: integer = 0;
Expand Down Expand Up @@ -41,7 +41,7 @@ TThread = record

function my_thread(Data: Pointer): integer; cdecl;
const
interation = 10000;
interation = 20000;
var
Para: TThread;
Farbe, x, y: word;
Expand Down
Loading

0 comments on commit cf1aaf3

Please sign in to comment.