Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
7746e6f
Working on NXDK port of calculator2.c
kosmas12 Apr 4, 2020
fd5bc77
Started working on a port of my calculator for the 2001 Xbox
kosmas12 Apr 4, 2020
24cc562
Started a port of my calculator in C for the 2001 Xbox using the NXDK…
kosmas12 Apr 4, 2020
f14ab3c
Added a mappings database and fixed XCalculator boot
kosmas12 Apr 4, 2020
f3ad1e0
XCalculator is starting to take form!
kosmas12 Apr 4, 2020
3e13fb0
Improved switch readability
kosmas12 Apr 4, 2020
7330d93
XCalculator now has all the base code in. Will fix.
kosmas12 Apr 4, 2020
ac5d445
fixed an error in the axis checks. Still doesn't work
kosmas12 Apr 5, 2020
715bc8d
Refactored some of XCalculator. Still doesn't do everything and doesn…
kosmas12 Apr 6, 2020
875a447
Refactor somewhat complete, doesn't work yet
kosmas12 Apr 6, 2020
5449cde
Refactor complete, supposed to work
kosmas12 Apr 6, 2020
6afe4fd
XCalculator kinda works now
kosmas12 Apr 6, 2020
92ad04f
rafactor complete. Kind of works
kosmas12 Apr 6, 2020
c05c6ef
Almost working, gotta fix infinite printing
kosmas12 Apr 6, 2020
258613a
changes
kosmas12 Apr 6, 2020
2298598
Made some changes to test functions individually
kosmas12 Apr 6, 2020
202e249
changes
kosmas12 Apr 6, 2020
957731b
changes
kosmas12 Apr 6, 2020
e415e87
Added a function for pressing A, still not tested
kosmas12 Apr 7, 2020
18aeb32
XCalculator is one step closer to working
kosmas12 Apr 7, 2020
95a019e
One step closer to working
kosmas12 Apr 7, 2020
c8731fd
fixing some stuff
kosmas12 Apr 7, 2020
10d46b1
getCommand() prints the right amount of times now
kosmas12 Apr 7, 2020
65640d7
description prints properly now
kosmas12 Apr 7, 2020
eaece9e
getInput() prints properly, input still doesn't work
kosmas12 Apr 7, 2020
c41a1c9
One step closer to working
kosmas12 Apr 7, 2020
2622676
fixes
kosmas12 Apr 7, 2020
ec8f585
stufff
kosmas12 Apr 7, 2020
9efa028
stuff
kosmas12 Apr 7, 2020
5fcae10
Kind of making progress with getCommand()
kosmas12 Apr 7, 2020
d97a67a
Trying a new fix
kosmas12 Apr 7, 2020
cce6b88
trying a fix
kosmas12 Apr 7, 2020
6dfa076
almost fixed getCommand()
kosmas12 Apr 7, 2020
50bb17e
changes
kosmas12 Apr 7, 2020
7769ce3
changes
kosmas12 Apr 7, 2020
048122b
getCommand() now works
kosmas12 Apr 7, 2020
59779d8
made getCommand() return user_command
kosmas12 Apr 7, 2020
cec9766
changes
kosmas12 Apr 7, 2020
a81e353
Most parts of the calculator work, have to fix user_input
kosmas12 Apr 7, 2020
3b5dbde
changes
kosmas12 Apr 7, 2020
15153c6
changes
kosmas12 Apr 7, 2020
4d75082
Honestly I don't know why I write these messages anymore
kosmas12 Apr 7, 2020
a1ee792
printfloat() now works properly
kosmas12 Apr 8, 2020
dc67d01
Working on a getInput() fix
kosmas12 Apr 8, 2020
fa634b0
getInput() fix in progress
kosmas12 Apr 8, 2020
b941640
getInput() fix in progress
kosmas12 Apr 8, 2020
003d33f
made some changes to printfloat()
kosmas12 Apr 8, 2020
2fdf334
WIP making isThingUsed()
kosmas12 Apr 8, 2020
c9924df
change
kosmas12 Apr 8, 2020
cd6621d
just stop with these messages already
kosmas12 Apr 8, 2020
40765f0
changes
kosmas12 Apr 8, 2020
de526e4
.
kosmas12 Apr 8, 2020
8617e68
F these messages
kosmas12 Apr 8, 2020
e58db15
.
kosmas12 Apr 8, 2020
401f7b6
removed mappings fil
kosmas12 Apr 8, 2020
2be0d0e
The user option can now never go out of bounds
kosmas12 Apr 8, 2020
bba31e6
tweaked some values in getInput() to work with the inverted Y axis in…
kosmas12 Apr 11, 2020
d7b8445
adjusted getInput() to work with inverted Y axis
kosmas12 Apr 11, 2020
3142aa7
help() works properly now
kosmas12 Apr 12, 2020
7ed9dad
implemented remap() for correct getInput() work
kosmas12 Apr 13, 2020
7009986
XCalculator now works
kosmas12 Apr 13, 2020
9a6edd0
Fully documented XCalculator
kosmas12 Apr 13, 2020
a2ca87f
git config --global user.email johndoe@example.com
kosmas12 Apr 14, 2020
b787d6a
resets user_input after operations and imrpoved readability
kosmas12 Apr 14, 2020
7500a69
Started working on a subcalculator for XCalculator
kosmas12 Apr 14, 2020
c3ded53
Started work on minicalc()
kosmas12 Apr 19, 2020
caa9de9
Improved control over the input number in getInput()
kosmas12 Apr 19, 2020
6ab619f
Creating 1 codebase for both PC and Xbox
kosmas12 Apr 20, 2020
7c4bc76
.
kosmas12 Apr 20, 2020
a4ac0a8
Abandoned same codebase for all platforms
kosmas12 Apr 20, 2020
b52415e
abandoned minicalc()
kosmas12 Apr 20, 2020
55927f2
fixed a small bug in getInput()
kosmas12 Apr 20, 2020
39f69a9
Started work on NXDK port for Mandelbrot set
kosmas12 Apr 22, 2020
bd15c9b
Started work on NXDK port for Mandelbrot Set
kosmas12 Apr 22, 2020
548e4f9
Started work on Mandelbrot set with NXDK
kosmas12 Apr 22, 2020
d21a4e8
Started work on NXDK Mandelbrot Set
kosmas12 Apr 22, 2020
accb5fb
Started work on NXDK port for Mandelbrot Set drawer
kosmas12 Apr 22, 2020
e5a0e29
Started working on NXDK port for Mandelbrot set drawer
kosmas12 Apr 22, 2020
d81fd53
Changed a few variables on XCalculator
kosmas12 Apr 23, 2020
e65ffaf
Changed MandelbrotSetX to use controller input
kosmas12 Apr 23, 2020
88ebe98
Changed window dimensions
kosmas12 Apr 23, 2020
21dc58b
Update README.md
kosmas12 Apr 23, 2020
f889e44
Update README.md
kosmas12 Apr 23, 2020
a335813
Update README.md
kosmas12 Apr 23, 2020
3287a60
Update README
kosmas12 Apr 23, 2020
ee134f7
Xbox and PC now share the same codebase
kosmas12 Apr 25, 2020
637c1b3
Merge branch 'nxdk' of github.com:kosmas12/My-code-stuff into nxdk
kosmas12 Apr 25, 2020
15daf9e
NXDK and PC share the same codebase
kosmas12 Apr 25, 2020
bafb535
NXDK and PC share one codebase
kosmas12 Apr 25, 2020
fe8b1ea
Update README.md
kosmas12 Apr 25, 2020
e109eab
Update README.md
kosmas12 Apr 25, 2020
f1f2182
Made MandelbrotSetX work with a controller
kosmas12 Apr 25, 2020
554c733
Merge branch 'nxdk' of github.com:kosmas12/My-code-stuff into nxdk
kosmas12 Apr 25, 2020
05b743a
Changed input for zoom functions (in and out)
kosmas12 Apr 25, 2020
de9f703
.
kosmas12 Apr 26, 2020
4130f50
kosmas12 Apr 27, 2020
a89d193
Attempt to improve performance. Program broken.
kosmas12 May 2, 2020
133c95e
kosmas12 May 2, 2020
6116d97
kosmas12 May 2, 2020
cf252f6
Trying to fix code with better performance
kosmas12 May 2, 2020
19984a9
Edited README.md
kosmas12 May 3, 2020
c88278f
Edited READMEs
kosmas12 May 3, 2020
4074da3
Update README
kosmas12 May 3, 2020
bac6a3e
Mandelbrot also works
kosmas12 May 3, 2020
de598d9
Mandelbrot almost works
kosmas12 May 3, 2020
6421e45
Mandelbrot almost works
kosmas12 May 3, 2020
5a7d543
Made Makefiles more modular
kosmas12 May 3, 2020
e5521d2
Removed unnecessary README
kosmas12 May 3, 2020
d57ade6
Made the controller detection part of the code print the found contro…
kosmas12 May 3, 2020
cab2990
Added error printing for joystick opening
kosmas12 May 3, 2020
6e9a396
Fixed joystick error checking
kosmas12 May 4, 2020
15117e7
made assert run in both Xbox and PC
kosmas12 May 4, 2020
036a5cd
fixed a double semicolon in mandelbrot
kosmas12 May 4, 2020
1bffd52
Fixed a double semicolon in Mandelbrot
kosmas12 May 4, 2020
61856b8
Mandelbrot now works with the performance fix
kosmas12 May 4, 2020
bfba334
Fixed assert undefined on nxdk (Changed #include order)
kosmas12 May 4, 2020
bb7ddbd
changed #includes
kosmas12 May 4, 2020
bfdc4b4
Mandelbrot can now exit by pressing the X button on its window
kosmas12 May 4, 2020
e33fa39
Mandelbrot works on nxdk with the new code, but performance is bad
kosmas12 May 4, 2020
1559624
updated controls
kosmas12 May 4, 2020
f669e7f
XCalculator now chooses a command with the DPad
kosmas12 May 7, 2020
4ef2109
Some small refactors
kosmas12 May 7, 2020
da46282
Started work on a simple SDL music player. Supports hardcoded .wav on…
kosmas12 May 13, 2020
412af08
Added Makefile for nxdk
kosmas12 May 13, 2020
65e33cc
Added code to unload SDL for a 100% clear exit
kosmas12 May 13, 2020
6f16f64
Makefile now bundles audio file with XISO
kosmas12 May 13, 2020
2c70252
kosmas12 May 13, 2020
c0e3c3e
Music PlayerX is now fully NXDK compatible, don't try yet as there is…
kosmas12 May 13, 2020
fd27126
kosmas12 May 13, 2020
cec1f9a
Now a sample audio file is bundled, still doesn't work
kosmas12 May 14, 2020
0f128a8
The player can now play an audio file that doesn't exceed Xbox RAM li…
kosmas12 May 14, 2020
365a650
Pause functionality added, file to play is a variable
kosmas12 May 14, 2020
c9f116e
Added a README for the music player, also added pause function and a …
kosmas12 May 14, 2020
7fe5dbe
Updated README
kosmas12 May 14, 2020
786e761
Changed where variables are located
kosmas12 May 14, 2020
9819aa2
Renamed to XMusic. Also now there are 2 bundled wav files to test dif…
kosmas12 May 14, 2020
67224c7
Removed 2nd bundled song
kosmas12 May 15, 2020
f4cd366
Replaced 2nd bundled song
kosmas12 May 15, 2020
b92a98f
nxdk pause now works
kosmas12 May 15, 2020
d52a9d4
The program now runs for as long as there is audio, and streams data …
kosmas12 May 15, 2020
5a1eec3
Removed queuing audio. Not advised to use this on actual hw yet
kosmas12 May 15, 2020
240a952
Fixed bundled songs
kosmas12 May 16, 2020
8bd0d33
XMusic now always quits, not just with SIGINT
kosmas12 May 16, 2020
4c17283
Changed bundled pause test filename to test spaces on filename
kosmas12 May 16, 2020
d17e17f
There is a function to handle playing a file now, prepared to start w…
kosmas12 May 17, 2020
55ec108
Started making an actual file selector for the Xbox version of XMusic
kosmas12 May 22, 2020
f77bed1
kosmas12 May 22, 2020
cfb7578
XMusic's file selector now lists the correct number of files and also…
kosmas12 May 24, 2020
e50b509
kosmas12 May 24, 2020
957a869
Fixed a side effect where XMusic read from disk every frame
kosmas12 May 25, 2020
a20b1d0
XMusic now has a working file selector
kosmas12 May 26, 2020
b2441ed
XMusic supports spaces on PC, also fixed a problem where XReboot was …
kosmas12 May 26, 2020
2c037bd
Updated Makefile to be more efficient
kosmas12 May 26, 2020
f460734
kosmas12 May 26, 2020
4b24a03
Now hosting personal website code
kosmas12 May 26, 2020
d3ddc06
Code for public personal website is uploaded
kosmas12 May 26, 2020
9756f92
Removed personal website code to make different project
kosmas12 May 26, 2020
f6b857d
Pausing with SDL_mixer now works on PC, Xbox fix incoming
kosmas12 May 30, 2020
6bd790c
Changed README
kosmas12 May 31, 2020
44fe24e
Using Mix_Quit() function
kosmas12 Jun 1, 2020
257ef0b
Trying to fix Xbox no audio issue, file doesn't even open
kosmas12 Jun 4, 2020
af829e8
kosmas12 Jun 4, 2020
521feb2
Trying to add the Xbox version to use paths instead of file namse
kosmas12 Jun 6, 2020
d7cbc2a
Added Makefile for PC XMusic
kosmas12 Jun 7, 2020
0ddd9c1
kosmas12 Jun 9, 2020
0abce0b
Update README.md
kosmas12 Jun 17, 2020
c9ba506
Code improvements
kosmas12 Jul 8, 2020
197626a
Code improvements
kosmas12 Jul 8, 2020
4641549
Code improvements
kosmas12 Jul 9, 2020
184ec9d
Split the file browser into functions
kosmas12 Jul 10, 2020
d3fcd6c
Fixed an error where the wrong array was free()'d
kosmas12 Jul 10, 2020
e53abd7
Fixed small error where driveLetter in GetFile() was spelled wrong
kosmas12 Jul 10, 2020
7065479
Added filtering for directories
kosmas12 Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,45 @@ Maths Calculator (C)/XCalculator.c.d
Maths Calculator (C)/bin/default.xbe
Maths Calculator (C)/main.exe
Maths Calculator (C)/calculator.iso
Maths Calculator (C)/main.pdb
Maths Calculator (C)/SDLTest.iso
Maths Calculator (C)/SDLtest.c.d
Maths Calculator (C)/SDLtest.c
Maths Calculator (C)/SDLtest.obj
Maths Calculator (C)/.vscode/settings.json
Maths Calculator (C)/XCalculator.iso
test
test.c
Mandelbrot Set (C)/.vscode/c_cpp_properties.json
Mandelbrot Set (C)/mandelbrot.c.d
Mandelbrot Set (C)/main.exe
Mandelbrot Set (C)/mandelbrot.obj
Mandelbrot Set (C)/MandelbrotSetX.iso
Mandelbrot Set (C)/bin/default.xbe
Mandelbrot Set (C)/.vscode/settings.json
Mandelbrot Set (C)/mandelbrot
C11 standard.pdf
Fibonacci Sequnce (C)/fibonacci
Mandelbrot Set (C)/main.pdb
.vscode/settings.json
n4713.pdf
.vscode/c_cpp_properties.json
Music player (C)/music
Music player (C)/player.c.d
Music player (C)/player.obj
Music player (C)/bin/default.xbe
Music player (C)/main.exe
Music player (C)/bin/nxdk.wav
Music player (C)/XMusic.iso
Music player (C)/bin/pausetest.wav
Test code/main.c
Test code/main.c.d
Test code/main.exe
Test code/main.obj
Test code/main.pdb
Test code/Makefile
Test code/bin/default.xbe
Test code/winapi_filefinD.iso
Test code/bin/CivilSin.wav
Test code/bin/O fortuna.wav
Music player (C)/bin/Pause Test.wav
7 changes: 7 additions & 0 deletions Mandelbrot Set (C)/Makefile.nxdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
XBE_TITLE=MandelbrotSetX
GEN_XISO = $(XBE_TITLE).iso
SRCS = mandelbrot.c
NXDK_DIR = /home/$(USERNAME)/nxdk
NXDK_SDL = y
include $(NXDK_DIR)/Makefile
DEBUG = y
44 changes: 44 additions & 0 deletions Mandelbrot Set (C)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# mandelbrot-c-sdl2

Forked from https://github.com/Geospace/mandelbrot-c-sdl2/tree/master

The Xbox port is made by me

Using the C language and the SDL2 library to draw the Mandelbrot set.

## Features

Controls:
* Use **D-Pad** to move
* Use **B** to zoom in
* Use **X** to zoom out

## Requirements

PC:
* C standard library with (G)CC
* SDL2 library
* Possibly MinGW if running Windows

Xbox:
* nxdk (https://github.com/XboxDev/nxdk)

To compile for nxdk, use:

make -f Makefile.nxdk

## Compilation

```
$ make help
Just use make (without any argument) to compile.
Use make clean in order to delete mandelbrot.
If you have errors during compilation, you can contact me for help.
Windows users, you can use MinGW with this project.
```

Then run the program and enjoy ! :-)

![screenshot](screenshotx.png "This is beautiful...")

Happy fractal !
146 changes: 146 additions & 0 deletions Mandelbrot Set (C)/headers/myFractal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// This file has no copyright.

#ifndef HEADERS_MYFRACTAL_H_
#define HEADERS_MYFRACTAL_H_

#if defined(NXDK)
#include <SDL.h>
#include <SDL_gamecontroller.h>
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_gamecontroller.h>
#endif
#include "myStructures.h"
#include "mySDL.h"

bool fractal_init = false;

Fractal *init_fractal() {

Fractal *fractal = malloc(sizeof(Fractal));

// Used to move camera
fractal->xMove = 0;
fractal->yMove = 0;

// Used to change the zoom and precision
fractal->zoom = 0.3;
fractal->iMax = 60;

fractal_init = true;

return fractal;
}

void draw_mandelbrot(Sdl *sdl, Fractal *fractal) {
int i;

SDL_LockSurface(sdl->surface);

uint32_t *pixels = sdl->surface->pixels;
SDL_PixelFormat *pixelFormat = sdl->surface->format;

int xFrame = WINDOW_WIDTH;
int yFrame = WINDOW_HEIGHT;

// Formula is Z(n+1) = Z(n)^2 + C
// https://en.wikipedia.org/wiki/Mandelbrot_set
Complex c;
Complex z;

// Coordinate of each point
int x;
int y;

// Calculate all the y for every x
for (y = 0; y < yFrame; y++) {
c.i = ((y - yFrame / 2) / (0.5 * yFrame * fractal->zoom)) - fractal->yMove;

for (x = 0; x < xFrame; x++) {
c.r = ((x - xFrame / 2) / (0.5 * xFrame * fractal->zoom)) - fractal->xMove;

z.r = 0;
z.i = 0;

i = 0;


// Iterate in order to know if a certain point is in the set or not
do {
z.b = z.r;
z.r = z.r * z.r - z.i * z.i + c.r;
z.i = 2 * z.i * z.b + c.i;
i++;
} while (z.r * z.r + z.i * z.i < 4 && i < fractal->iMax);
// We don't use square root in order to reduce calculation time

if (i >= fractal->iMax) {
// In the set
pixels[(y * xFrame + x)] = SDL_MapRGB(pixelFormat, 0, 0, 255);
} else {
// Not in the set
pixels[(y * xFrame + x)] = SDL_MapRGB(pixelFormat, 0, 0, (i * (255 / fractal->iMax)));
}

// Render using SDL_RenderDrawPoint() is slow and should
// be replaced by SDL_RenderDrawPoints()
}
}
SDL_UnlockSurface(sdl->surface);
SDL_UpdateWindowSurface(sdl->window);
}


void is_user_moving(Sdl *sdl, Fractal *fractal) {

// Delta time to sync everything
float delta = 0.30;

// Movement speed
float moveStep = 0.5;
float zoomStep = 3.0;

while (SDL_PollEvent(&sdl->event)) {
if (sdl->event.type == SDL_CONTROLLERBUTTONDOWN) {
switch (sdl->event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
fractal->xMove = fractal->xMove + (moveStep / fractal->zoom * delta);
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
fractal->xMove = fractal->xMove - (moveStep / fractal->zoom * delta);
break;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
fractal->yMove = fractal->yMove + (moveStep / fractal->zoom * delta);
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
fractal->yMove = fractal->yMove - (moveStep / fractal->zoom * delta);
break;
case SDL_CONTROLLER_BUTTON_B:
fractal->zoom = fractal->zoom + (moveStep * fractal->zoom * delta);
fractal->iMax = fractal->iMax + zoomStep * delta;
break;
case SDL_CONTROLLER_BUTTON_X:
fractal->zoom = fractal->zoom - (moveStep * fractal->zoom * delta);
fractal->iMax = fractal->iMax - zoomStep * delta;
break;
default:
break;
}
}
}
}

bool is_user_exiting (Sdl *sdl)
{
if(sdl->event.type == SDL_QUIT)
{
return true;
}
else
{
return false;
}

}

#endif // HEADERS_MYFRACTAL_H_
95 changes: 95 additions & 0 deletions Mandelbrot Set (C)/headers/mySDL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// This file has no copyright.

#ifndef HEADERS_MYSDL_H_
#define HEADERS_MYSDL_H_

#if defined(NXDK)
#include <SDL.h>
#include <SDL_gamecontroller.h>
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_gamecontroller.h>
#endif
#include <stdbool.h>
#include <assert.h>

bool sdl_init = false;

SDL_GameController *controller = NULL; // We initialize a controller and give it a NULL value for now

static bool isNewlyPressed(bool is_held, bool *was_held) {

if (is_held) { // If the button is held in this frame
if (*was_held) { // If it was held in the previous frame
return false; // The button isn't newly pressed
}
else { // If it wasn't held in the previous frame
*was_held = true; // Set was_held to true because the current frame will be the previous frame in the next frame
return true; // The button is newly pressed, so we return true
}

}
else { // If it isn't held in the current frame
*was_held = false; // Set was_held to false
return false; // The button isn't pressed at all, so we return false
}
}


float remap(float value, float from_min, float from_max, float to_min, float to_max) { // Function to remap values to other values
value = ((value - from_min) / (from_max - from_min)) * (to_max - to_min) + to_min;
return value;
}

static float getAxis(int sdl_axis) { // Function to get an axis from the controller

const float deadzone = 0.2f;

// Get input in range -1 to +1
float amount = (float)SDL_GameControllerGetAxis(controller, sdl_axis) / (float)0x8000;

// Reject if the stick is in deadzone
if (fabsf(amount) < deadzone) {
return 0.0f;
}

if (amount > 0.0f) {
amount = remap(amount, deadzone, +1.0f, 0.0f, +1.0f); // Remap from +[0.2, 1.0] to +[0.0, 1.0]
}
else {
amount = -remap(-amount, deadzone, +1.0f, 0.0f, +1.0f); // Remap from -[0.2, 1.0] to -[0.0, 1.0]
}
return amount;
}

Sdl *init_sdl() {

Sdl *sdl = malloc(sizeof(Sdl));

SDL_Init(SDL_INIT_GAMECONTROLLER|SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");

sdl->window = SDL_CreateWindow(WINDOW_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, 0);

sdl->surface = SDL_GetWindowSurface(sdl->window);

assert(sdl->surface != NULL);

sdl_init = true;

return sdl;
}

/*
void draw_cross(Sdl *sdl) {
// Draw a little cross when user zooms in/out or moves
int length = 15;
SDL_SetRenderDrawColor(sdl->renderer, 255, 255, 255, 255);

SDL_RenderDrawLine(sdl->renderer, WINDOW_WIDTH / 2 - length / 2,
WINDOW_HEIGHT / 2, WINDOW_WIDTH / 2 + length / 2, WINDOW_HEIGHT / 2);
SDL_RenderDrawLine(sdl->renderer, WINDOW_WIDTH / 2, WINDOW_HEIGHT
/ 2 - length / 2, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + length / 2);
} */

#endif // HEADERS_MYSDL_H_
54 changes: 54 additions & 0 deletions Mandelbrot Set (C)/headers/myStructures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file has no copyright.

#ifndef HEADERS_MYSTRUCTURES_H_
#define HEADERS_MYSTRUCTURES_H_
#if defined(NXDK)
#include <SDL.h>
#include <SDL_gamecontroller.h>
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_gamecontroller.h>
#endif

// This has to be a square
#define WINDOW_WIDTH 480
#define WINDOW_HEIGHT 480

#define WINDOW_TITLE "Mandelbrot Fractal, by Geographer (Xbox port by Kosmas12)"

typedef struct Sdl {
SDL_Window *window;
SDL_Surface *surface;
SDL_PixelFormat *format;
SDL_Event event;
} Sdl;

typedef struct Complex {
// Real part, imaginary part and a backup
double r;
double i;
double b;
} Complex;

typedef struct Fractal {
// See myFractal.h
double xMove;
double yMove;
double zoom;
unsigned int iMax;
} Fractal;

void free_everything(Sdl *sdl, Fractal *fractal) {

SDL_DestroyWindow(sdl->window);
free(sdl);

free(fractal);

SDL_Quit();

// You may observe memory leaks using this program
// SDL2 leaks by itself
}

#endif // HEADERS_MYSTRUCTURES_H_
Loading