Added layers

This commit is contained in:
captain4lk 2020-04-19 22:15:50 +02:00
parent c65988dd8b
commit 79a01b9db6
94 changed files with 38948 additions and 1676 deletions

View file

@ -1,4 +1,4 @@
(C) 2019 Lukas Holzbeierlein (Captain4LK)
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -6,20 +6,17 @@ It's made for low resolutions (eg. 256x240), but can be used for higher resoluti
## License
SLK is released under the zlib license, see LICENSE.md for details.
Some of the examples may be released under a different license though.
## Using the engine
To use SLK you need to have the following libraries installed:
* [zlib](https://www.zlib.net/)
* [libpng](http://www.libpng.org/pub/png/libpng.html)
* [SDL 2](https://www.libsdl.org/)
You need to link your programm to the following libraries:
* Opengl
* zlib
* libpng
* SDL 2
## Plattforms

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -1,42 +0,0 @@
JASC-PAL
0100
39
0 0 0
33 48 56
67 125 160
77 146 188
154 40 144
255 255 255
216 183 143
255 215 168
56 33 33
160 67 69
188 77 79
75 154 39
74 59 31
229 171 61
253 199 96
35 121 234
0 148 255
50 56 33
136 160 67
159 188 77
196 63 49
5 4 3
27 36 71
61 111 67
97 165 63
143 208 50
23 21 22
103 57 49
180 117 56
192 144 169
189 164 153
201 212 253
128 123 122
211 151 65
248 197 58
248 246 68
181 231 203
66 191 232
39 137 205

View file

@ -1,20 +0,0 @@
JASC-PAL
0100
17
0 0 0
0 0 0
255 255 255
247 226 107
163 206 39
68 137 26
49 162 242
178 220 239
0 87 132
224 111 139
190 38 51
164 100 34
235 137 49
157 157 157
47 72 78
73 60 43
27 38 50

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

View file

@ -1,81 +0,0 @@
#include "../../include/SLK/SLK.h"
#include <time.h>
#include <stdint.h>
uint8_t seconds, minutes, hours;
char sec[8], min[8], hr[8];
SLK_Color text;
int main(int argc, char *argv[])
{
SLK_setup(72,112,"Binary Clock",0,4);
SLK_set_FPS(5);
SLK_show_cursor(1);
SLK_set_clear_color(SLK_create_color(0,0,0,255));
SLK_clear_screen();
text = SLK_create_color(255,255,255,255);
while(SLK_running())
{
SLK_update();
time_t raw;
struct tm *timeinfo;
time(&raw);
timeinfo = localtime(&raw);
seconds = timeinfo->tm_sec;
minutes = timeinfo->tm_min;
hours = timeinfo->tm_hour;
sprintf(sec,"%02d",seconds);
sprintf(min,"%02d",minutes);
sprintf(hr,"%02d",hours);
SLK_clear_screen();
SLK_draw_string(55,1,1,sec,text);
SLK_draw_string(28,1,1,min,text);
SLK_draw_string(1,1,1,hr,text);
if(seconds&1)
SLK_fill_rectangle(55,10,16,16,text);
if(seconds&2)
SLK_fill_rectangle(55,27,16,16,text);
if(seconds&4)
SLK_fill_rectangle(55,44,16,16,text);
if(seconds&8)
SLK_fill_rectangle(55,61,16,16,text);
if(seconds&16)
SLK_fill_rectangle(55,78,16,16,text);
if(seconds&32)
SLK_fill_rectangle(55,95,16,16,text);
if(minutes&1)
SLK_fill_rectangle(28,10,16,16,text);
if(minutes&2)
SLK_fill_rectangle(28,27,16,16,text);
if(minutes&4)
SLK_fill_rectangle(28,44,16,16,text);
if(minutes&8)
SLK_fill_rectangle(28,61,16,16,text);
if(minutes&16)
SLK_fill_rectangle(28,78,16,16,text);
if(minutes&32)
SLK_fill_rectangle(28,95,16,16,text);
if(hours&1)
SLK_fill_rectangle(1,10,16,16,text);
if(hours&2)
SLK_fill_rectangle(1,27,16,16,text);
if(hours&4)
SLK_fill_rectangle(1,44,16,16,text);
if(hours&8)
SLK_fill_rectangle(1,61,16,16,text);
if(hours&16)
SLK_fill_rectangle(1,78,16,16,text);
SLK_update_screen();
}
return 0;
}

675
examples/efelder/LICENSE.md Normal file
View file

@ -0,0 +1,675 @@
### GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
<https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
### Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom
to share and change all versions of a program--to make sure it remains
free software for all its users. We, the Free Software Foundation, use
the GNU General Public License for most of our software; it applies
also to any other work released this way by its authors. You can apply
it to your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you
have certain responsibilities if you distribute copies of the
software, or if you modify it: responsibilities to respect the freedom
of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the
manufacturer can do so. This is fundamentally incompatible with the
aim of protecting users' freedom to change the software. The
systematic pattern of such abuse occurs in the area of products for
individuals to use, which is precisely where it is most unacceptable.
Therefore, we have designed this version of the GPL to prohibit the
practice for those products. If such problems arise substantially in
other domains, we stand ready to extend this provision to those
domains in future versions of the GPL, as needed to protect the
freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish
to avoid the special danger that patents applied to a free program
could make it effectively proprietary. To prevent this, the GPL
assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
### TERMS AND CONDITIONS
#### 0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds
of works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of
an exact copy. The resulting work is called a "modified version" of
the earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user
through a computer network, with no transfer of a copy, is not
conveying.
An interactive user interface displays "Appropriate Legal Notices" to
the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
#### 1. Source Code.
The "source code" for a work means the preferred form of the work for
making modifications to it. "Object code" means any non-source form of
a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users can
regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same
work.
#### 2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey,
without conditions so long as your license otherwise remains in force.
You may convey covered works to others for the sole purpose of having
them make modifications exclusively for you, or provide you with
facilities for running those works, provided that you comply with the
terms of this License in conveying all material for which you do not
control copyright. Those thus making or running the covered works for
you must do so exclusively on your behalf, under your direction and
control, on terms that prohibit them from making any copies of your
copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the
conditions stated below. Sublicensing is not allowed; section 10 makes
it unnecessary.
#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such
circumvention is effected by exercising rights under this License with
respect to the covered work, and you disclaim any intention to limit
operation or modification of the work as a means of enforcing, against
the work's users, your or third parties' legal rights to forbid
circumvention of technological measures.
#### 4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
#### 5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these
conditions:
- a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
- b) The work must carry prominent notices stating that it is
released under this License and any conditions added under
section 7. This requirement modifies the requirement in section 4
to "keep intact all notices".
- c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
- d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
#### 6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of
sections 4 and 5, provided that you also convey the machine-readable
Corresponding Source under the terms of this License, in one of these
ways:
- a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
- b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the Corresponding
Source from a network server at no charge.
- c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
- d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
- e) Convey the object code using peer-to-peer transmission,
provided you inform other peers where the object code and
Corresponding Source of the work are being offered to the general
public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal,
family, or household purposes, or (2) anything designed or sold for
incorporation into a dwelling. In determining whether a product is a
consumer product, doubtful cases shall be resolved in favor of
coverage. For a particular product received by a particular user,
"normally used" refers to a typical or common use of that class of
product, regardless of the status of the particular user or of the way
in which the particular user actually uses, or expects or is expected
to use, the product. A product is a consumer product regardless of
whether the product has substantial commercial, industrial or
non-consumer uses, unless such uses represent the only significant
mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to
install and execute modified versions of a covered work in that User
Product from a modified version of its Corresponding Source. The
information must suffice to ensure that the continued functioning of
the modified object code is in no case prevented or interfered with
solely because modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or
updates for a work that has been modified or installed by the
recipient, or for the User Product in which it has been modified or
installed. Access to a network may be denied when the modification
itself materially and adversely affects the operation of the network
or violates the rules and protocols for communication across the
network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
#### 7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders
of that material) supplement the terms of this License with terms:
- a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
- b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
- c) Prohibiting misrepresentation of the origin of that material,
or requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
- d) Limiting the use for publicity purposes of names of licensors
or authors of the material; or
- e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
- f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions
of it) with contractual assumptions of liability to the recipient,
for any liability that these contractual assumptions directly
impose on those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions; the
above requirements apply either way.
#### 8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
#### 9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run
a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
#### 10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
#### 11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims owned
or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within the
scope of its coverage, prohibits the exercise of, or is conditioned on
the non-exercise of one or more of the rights that are specifically
granted under this License. You may not convey a covered work if you
are a party to an arrangement with a third party that is in the
business of distributing software, under which you make payment to the
third party based on the extent of your activity of conveying the
work, and under which the third party grants, to any of the parties
who would receive the covered work from you, a discriminatory patent
license (a) in connection with copies of the covered work conveyed by
you (or copies made from those copies), or (b) primarily for and in
connection with specific products or compilations that contain the
covered work, unless you entered into that arrangement, or that patent
license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
#### 12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under
this License and any other pertinent obligations, then as a
consequence you may not convey it at all. For example, if you agree to
terms that obligate you to collect a royalty for further conveying
from those to whom you convey the Program, the only way you could
satisfy both those terms and this License would be to refrain entirely
from conveying the Program.
#### 13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
#### 14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions
of the GNU General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in
detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies that a certain numbered version of the GNU General Public
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that numbered version or
of any later version published by the Free Software Foundation. If the
Program does not specify a version number of the GNU General Public
License, you may choose any version ever published by the Free
Software Foundation.
If the Program specifies that a proxy can decide which future versions
of the GNU General Public License can be used, that proxy's public
statement of acceptance of a version permanently authorizes you to
choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
#### 15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
CORRECTION.
#### 16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#### 17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
### How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively state
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper
mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands \`show w' and \`show c' should show the
appropriate parts of the General Public License. Of course, your
program's commands might be different; for a GUI interface, you would
use an "about box".
You should also get your employer (if you work as a programmer) or
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. For more information on this, and how to apply and follow
the GNU GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your
program into proprietary programs. If your program is a subroutine
library, you may consider it more useful to permit linking proprietary
applications with the library. If this is what you want to do, use the
GNU Lesser General Public License instead of this License. But first,
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.

View file

@ -0,0 +1,56 @@
/*
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Captain4LK
commandant4lk@gmail.com
*/
#include "ULK_file.h"
char *ULK_file_load(const char *path)
{
char *data = NULL;
size_t file_size = 0;
FILE *f = fopen(path,"rb");
fseek(f,0,SEEK_END);
file_size = ftell(f);
fseek(f,0,SEEK_SET);
data = malloc(file_size+1);
fread(data,file_size,1,f);
data[file_size] = '\0';
fclose(f);
return data;
}
void ULK_file_destroy_data(char *data)
{
if(data!=NULL)
free(data);
}
void ULK_file_dump(const char *data, const size_t size, const char *path)
{
FILE *f = fopen(path,"wb");
fwrite(data,size,1,f);
}

View file

@ -0,0 +1,36 @@
/*
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Captain4LK
commandant4lk@gmail.com
*/
#ifndef _ULK_FILE_H_
#define _ULK_FILE_H_
#include <stdio.h>
#include <stdlib.h>
char *ULK_file_load(const char *path);
void ULK_file_destroy_data(char *data);
void ULK_file_dump(const char *data, const size_t size, const char *path);
#endif

View file

@ -0,0 +1,832 @@
/*
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Captain4LK
commandant4lk@gmail.com
*/
#include "ULK_vector.h"
#define EPSILON 0.000001f
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
void ULK_vector_2d_add(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
out[0] = a[0]+b[0];
out[1] = a[1]+b[1];
}
float ULK_vector_2d_angle(const ULK_vector_2d a, const ULK_vector_2d b)
{
float cosine = 0.0f;
float magnitude = sqrtf(a[0]*a[0]+a[1]*a[1])*sqrtf(b[0]*b[0]+b[1]*b[1]);
if(magnitude!=0.0f)
cosine = (a[0]*b[0]+a[1]*b[1])/magnitude;
return acosf(cosine);
}
void ULK_vector_2d_ceil(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = ceilf(in[0]);
out[1] = ceilf(in[1]);
}
ULK_vector_2d *ULK_vector_2d_clone(const ULK_vector_2d in)
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = in[0];
*out[1] = in[1];
return out;
}
void ULK_vector_2d_copy(ULK_vector_2d dst, const ULK_vector_2d src)
{
dst[0] = src[0];
dst[1] = src[1];
}
ULK_vector_2d *ULK_vector_2d_create()
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = 0.0f;
*out[1] = 0.0f;
return out;
}
void ULK_vector_2d_cross(ULK_vector_3d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
float z = a[0]*b[1]-a[1]*b[0];
out[0] = 0;
out[1] = 0;
out[2] = z;
}
float ULK_vector_2d_distance(const ULK_vector_2d a, const ULK_vector_2d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
return hypotf(x,y);
}
void ULK_vector_2d_divide(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
out[0] = a[0]/b[0];
out[1] = a[1]/b[1];
}
float ULK_vector_2d_dot(const ULK_vector_2d a, const ULK_vector_2d b)
{
return a[0]*b[0]+a[1]*b[1];
}
int ULK_vector_2d_equals(const ULK_vector_2d a, const ULK_vector_2d b)
{
return (fabs(a[0]-b[0])<=(EPSILON*MAX(1.0f,MAX(fabs(a[0]),fabs(b[0]))))&&fabs(a[1]-b[1])<=(EPSILON*MAX(1.0f,MAX(fabs(a[1]),fabs(b[1])))));
}
int ULK_vector_2d_exact_equals(const ULK_vector_2d a, const ULK_vector_2d b)
{
return (a[0]==b[0]&&a[1]==b[1]);
}
void ULK_vector_2d_floor(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = floorf(in[0]);
out[1] = floorf(in[1]);
}
ULK_vector_2d *ULK_vector_2d_from_values(const float x, const float y)
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = x;
*out[1] = y;
return out;
}
void ULK_vector_2d_invert(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = 1.0f/in[0];
out[1] = 1.0f/in[1];
}
float ULK_vector_2d_length(const ULK_vector_2d in)
{
return sqrtf(in[0]*in[0]+in[1]*in[1]);
}
void ULK_vector_2d_lerp(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b, const float t)
{
out[0] = a[0]+t*(b[0]-a[0]);
out[1] = a[1]+t*(b[1]-a[1]);
}
void ULK_vector_2d_max(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
float a_length = a[0]*a[0]+a[1]*a[1];
float b_length = b[0]*b[0]+b[1]*b[1];
if(a_length>b_length)
{
out[0] = a[0];
out[1] = a[1];
}
else
{
out[0] = b[0];
out[1] = b[1];
}
}
void ULK_vector_2d_min(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
float a_length = a[0]*a[0]+a[1]*a[1];
float b_length = b[0]*b[0]+b[1]*b[1];
if(a_length<b_length)
{
out[0] = a[0];
out[1] = a[1];
}
else
{
out[0] = b[0];
out[1] = b[1];
}
}
void ULK_vector_2d_multiply(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
out[0] = a[0]*b[0];
out[1] = a[1]*b[1];
}
void ULK_vector_2d_negate(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = -in[0];
out[1] = -in[1];
}
void ULK_vector_2d_normalize(ULK_vector_2d out, const ULK_vector_2d in)
{
float length = in[0]*in[0]+in[1]*in[1];
if(length>0)
length = 1.0f/sqrtf(length);
out[0] = in[0]*length;
out[1] = in[1]*length;
}
void ULK_vector_2d_rotate(ULK_vector_2d out, const ULK_vector_2d in, const ULK_vector_2d origin, const float radians)
{
float point0 = in[0]-origin[0];
float point1 = in[1]-origin[1];
float sin_rad = sinf(radians);
float cos_rad = cosf(radians);
out[0] = point0*cos_rad-point1*sin_rad+origin[0];
out[1] = point0*sin_rad+point1*cos_rad+origin[1];
}
void ULK_vector_2d_round(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = roundf(in[0]);
out[1] = roundf(in[1]);
}
void ULK_vector_2d_scale(ULK_vector_2d out, const ULK_vector_2d in, const float scale)
{
out[0] = in[0]*scale;
out[1] = in[1]*scale;
}
void ULK_vector_2d_set(ULK_vector_2d out, const float x, const float y)
{
out[0] = x;
out[1] = y;
}
float ULK_vector_2d_squared_distance(const ULK_vector_2d a, const ULK_vector_2d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
return x*x+y*y;
}
float ULK_vector_2d_squared_length(const ULK_vector_2d in)
{
return in[0]*in[0]+in[1]*in[1];
}
void ULK_vector_2d_subtract(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
out[0] = a[0]-b[0];
out[1] = a[1]-b[1];
}
void ULK_vector_2d_zero(ULK_vector_2d out)
{
out[0] = 0.0f;
out[1] = 0.0f;
}
void ULK_vector_3d_add(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
out[0] = a[0]+b[0];
out[1] = a[1]+b[1];
out[2] = a[2]+b[2];
}
float ULK_vector_3d_angle(const ULK_vector_3d a, const ULK_vector_3d b)
{
float magnitude = sqrtf(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])*sqrtf(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]);
float cosine = 0.0f;
if(magnitude!=0.0f)
cosine = ULK_vector_3d_dot(a,b)/magnitude;
return acosf(cosine);
}
void ULK_vector_3d_bezier(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, const float t)
{
float factor0 = (1-t)*(1-t)*(1-t);
float factor1 = 3*t*(1-t)*(1-t);
float factor2 = 3*t*t*(1-t);
float factor3 = t*t*t;
out[0] = a[0]*factor0+b[0]*factor1+c[0]*factor2+d[0]*factor3;
out[1] = a[1]*factor0+b[1]*factor1+c[1]*factor2+d[1]*factor3;
out[2] = a[2]*factor0+b[2]*factor1+c[2]*factor2+d[2]*factor3;
}
void ULK_vector_3d_ceil(ULK_vector_3d out, const ULK_vector_3d in)
{
out[0] = ceilf(in[0]);
out[1] = ceilf(in[1]);
out[2] = ceilf(in[2]);
}
ULK_vector_3d *ULK_vector_3d_clone(const ULK_vector_3d in)
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
return out;
}
void ULK_vector_3d_copy(ULK_vector_3d dst, const ULK_vector_3d src)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
ULK_vector_3d *ULK_vector_3d_create()
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = 0.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
return out;
}
void ULK_vector_3d_cross(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
float a0 = a[0];
float a1 = a[1];
float a2 = a[2];
float b0 = b[0];
float b1 = b[1];
float b2 = b[2];
out[0] = a1*b2-a2*b1;
out[1] = a2*b0-a0*b2;
out[2] = a0*b1-a1*b0;
}
float ULK_vector_3d_distance(const ULK_vector_3d a, const ULK_vector_3d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
float z = b[2]-a[2];
return sqrtf(x*x+y*y+z*z);
}
void ULK_vector_3d_divide(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
out[0] = a[0]/b[0];
out[1] = a[1]/b[1];
out[2] = a[2]/b[2];
}
float ULK_vector_3d_dot(const ULK_vector_3d a, const ULK_vector_3d b)
{
return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
}
int ULK_vector_3d_equals(const ULK_vector_3d a, const ULK_vector_3d b)
{
return (fabs(a[0]-b[0])<=EPSILON*MAX(1.0f,MAX(fabs(a[0]),fabs(b[0])))&&fabs(a[1]-b[1])<=EPSILON*MAX(1.0f,MAX(fabs(a[1]),fabs(b[1])))&&fabs(a[2]-b[2])<=EPSILON*MAX(1.0f,MAX(fabs(a[2]),fabs(b[2]))));
}
int ULK_vector_3d_exact_equals(const ULK_vector_3d a, const ULK_vector_3d b)
{
return (a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]);
}
void ULK_vector_3d_floor(ULK_vector_3d out, const ULK_vector_3d in)
{
out[0] = floorf(in[0]);
out[1] = floorf(in[1]);
out[2] = floorf(in[2]);
}
ULK_vector_3d *ULK_vector_3d_from_values(const float x, const float y, const float z)
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = x;
*out[1] = y;
*out[2] = z;
return out;
}
void ULK_vector_3d_hermite(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, float t)
{
float factor0 = t*t*(2*t-3)+1;
float factor1 = t*t*(t-2)+t;
float factor2 = t*t*(t-1);
float factor3 = t*t*(3-2*t);
out[0] = a[0]*factor0+b[0]*factor1+c[0]*factor2+d[0]*factor3;
out[1] = a[1]*factor0+b[1]*factor1+c[1]*factor2+d[1]*factor3;
out[2] = a[2]*factor0+b[2]*factor1+c[2]*factor2+d[2]*factor3;
}
void ULK_vector_3d_inverse(ULK_vector_3d out, const ULK_vector_3d in)
{
out[0] = 1.0f/in[0];
out[1] = 1.0f/in[1];
out[2] = 1.0f/in[2];
}
float ULK_vector_3d_length(const ULK_vector_3d in)
{
return sqrtf(in[0]*in[0]+in[1]*in[1]+in[2]*in[2]);
}
void ULK_vector_3d_lerp(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const float t)
{
out[0] = a[0]+t*(b[0]-a[0]);
out[1] = a[1]+t*(b[1]-a[1]);
out[2] = a[2]+t*(b[2]-a[2]);
}
void ULK_vector_3d_max(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
float a_length = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
float b_length = b[0]*b[0]+b[1]*b[1]+b[2]*b[2];
if(a_length>b_length)
{
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
}
else
{
out[0] = b[0];
out[1] = b[1];
out[2] = b[2];
}
}
void ULK_vector_3d_min(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
float a_length = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
float b_length = b[0]*b[0]+b[1]*b[1]+b[2]*b[2];
if(a_length<b_length)
{
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
}
else
{
out[0] = b[0];
out[1] = b[1];
out[2] = b[2];
}
}
void ULK_vector_3d_multiply(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
out[0] = a[0]*b[0];
out[1] = a[1]*b[1];
out[2] = a[2]*b[2];
}
void ULK_vector_3d_negate(ULK_vector_3d out, const ULK_vector_3d in)
{
out[0] = -in[0];
out[1] = -in[1];
out[2] = -in[2];
}
void ULK_vector_3d_normalize(ULK_vector_3d out, const ULK_vector_3d in)
{
float length = in[0]*in[0]+in[1]*in[1]+in[2]*in[2];
if(length>0)
length = 1.0f/sqrtf(length);
out[0] = in[0]*length;
out[1] = in[1]*length;
out[2] = in[2]*length;
}
void ULK_vector_3d_rotate_x(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad)
{
ULK_vector_3d p;
p[0] = in[0]-origin[0];
p[1] = in[1]-origin[1];
p[2] = in[2]-origin[2];
out[0] = p[0]+origin[0];
out[1] = p[1]*cosf(rad)-p[2]*sinf(rad)+origin[1];
out[2] = p[1]*sinf(rad)+p[2]*cosf(rad)+origin[2];
}
void ULK_vector_3d_rotate_y(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad)
{
ULK_vector_3d p;
p[0] = in[0]-origin[0];
p[1] = in[1]-origin[1];
p[2] = in[2]-origin[2];
out[0] = p[2]*sinf(rad)+p[0]*cosf(rad)+origin[0];
out[1] = p[1]+origin[1];
out[2] = p[2]*cosf(rad)-p[0]*sinf(rad)+origin[2];
}
void ULK_vector_3d_rotate_z(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad)
{
ULK_vector_3d p;
p[0] = in[0]-origin[0];
p[1] = in[1]-origin[1];
p[2] = in[2]-origin[2];
out[0] = p[0]*cosf(rad)-p[1]*sinf(rad)+origin[0];
out[1] = p[0]*sinf(rad)+p[1]*cosf(rad)+origin[1];
out[2] = p[2]+origin[2];
}
void ULK_vector_3d_round(ULK_vector_3d out, const ULK_vector_3d in)
{
out[0] = roundf(in[0]);
out[1] = roundf(in[1]);
out[2] = roundf(in[2]);
}
void ULK_vector_3d_scale(ULK_vector_3d out, const ULK_vector_3d in, const float scale)
{
out[0] = in[0]*scale;
out[1] = in[1]*scale;
out[2] = in[2]*scale;
}
void ULK_vector_3d_set(ULK_vector_3d out, const float x, const float y, const float z)
{
out[0] = x;
out[1] = y;
out[2] = z;
}
float ULK_vector_3d_squared_distance(const ULK_vector_3d a, const ULK_vector_3d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
float z = b[2]-a[2];
return x*x+y*y+z*z;
}
float ULK_vector_3d_squared_length(const ULK_vector_3d in)
{
return in[0]*in[0]+in[1]*in[1]+in[2]*in[2];
}
void ULK_vector_3d_subtract(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
out[0] = a[0]-b[0];
out[1] = a[1]-b[1];
out[2] = a[2]-b[2];
}
void ULK_vector_3d_zero(ULK_vector_3d out)
{
out[0] = 0.0f;
out[1] = 0.0f;
out[2] = 0.0f;
}
void ULK_vector_4d_add(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
out[0] = a[0]+b[0];
out[1] = a[1]+b[1];
out[2] = a[2]+b[2];
out[3] = a[3]+b[3];
}
void ULK_vector_4d_ceil(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = ceilf(in[0]);
out[1] = ceilf(in[1]);
out[2] = ceilf(in[2]);
out[3] = ceilf(in[3]);
}
ULK_vector_4d *ULK_vector_4d_clone(const ULK_vector_4d in)
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
return out;
}
void ULK_vector_4d_copy(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = in[3];
}
ULK_vector_4d *ULK_vector_4d_create()
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = 0.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 0.0f;
return out;
}
void ULK_vector_4d_cross(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const ULK_vector_4d c)
{
float A = b[0]*c[1]-b[1]*c[0];
float B = b[0]*c[2]-b[2]*c[0];
float C = b[0]*c[3]-b[3]*c[0];
float D = b[1]*c[2]-b[2]*c[1];
float E = b[1]*c[3]-b[3]*c[1];
float F = b[2]*c[3]-b[3]*c[2];
float G = a[0];
float H = a[1];
float I = a[2];
float J = a[3];
out[0] = H*F-I*E+J*D;
out[1] = -(G*F)+I*C-J*B;
out[2] = G*E-H*C+J*A;
out[3] = -(G*D)+H*B-I*A;
}
float ULK_vector_4d_distance(const ULK_vector_4d a, const ULK_vector_4d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
float z = b[2]-a[2];
float w = b[3]-a[3];
return sqrtf(x*x+y*y+z*z+w*w);
}
void ULK_vector_4d_divide(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
out[0] = a[0]/b[0];
out[1] = a[1]/b[1];
out[2] = a[2]/b[2];
out[3] = a[3]/b[3];
}
float ULK_vector_4d_dot(const ULK_vector_4d a, const ULK_vector_4d b)
{
return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3];
}
int ULK_vector_4d_equals(const ULK_vector_4d a, const ULK_vector_4d b)
{
return (fabs(a[0]-b[0])<=EPSILON*MAX(1.0f,MAX(fabs(a[0]),fabs(b[0])))&&fabs(a[1]-b[1])<=EPSILON*MAX(1.0f,MAX(fabs(a[1]),fabs(b[1])))&&fabs(a[2]-b[2])<=EPSILON*MAX(1.0f,MAX(fabs(a[2]),fabs(b[2])))&&fabs(a[3]-b[3])<=EPSILON*MAX(1.0f,MAX(fabs(a[3]),fabs(b[3]))));
}
int ULK_vector_4d_exact_equals(const ULK_vector_4d a, const ULK_vector_4d b)
{
return (a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]);
}
void ULK_vector_4d_floor(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = floorf(in[0]);
out[1] = floorf(in[1]);
out[2] = floorf(in[2]);
out[3] = floorf(in[3]);
}
ULK_vector_4d *ULK_vector_4d_from_values(const float x, const float y, const float z, const float w)
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = x;
*out[1] = y;
*out[2] = z;
*out[3] = w;
return out;
}
void ULK_vector_4d_inverse(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = 1.0f/in[0];
out[1] = 1.0f/in[1];
out[2] = 1.0f/in[2];
out[3] = 1.0f/in[3];
}
float ULK_vector_4d_length(const ULK_vector_4d in)
{
return sqrtf(in[0]*in[0]+in[1]*in[1]+in[2]*in[2]+in[3]*in[3]);
}
void ULK_vector_4d_lerp(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const float t)
{
out[0] = a[0]+t*(b[0]-a[0]);
out[1] = a[1]+t*(b[1]-a[1]);
out[2] = a[2]+t*(b[2]-a[2]);
out[3] = a[3]+t*(b[3]-a[3]);
}
void ULK_vector_4d_max(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
float a_length = a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3];
float b_length = b[0]*b[0]+b[1]*b[1]+b[2]*b[2]+b[3]*b[3];
if(a_length>b_length)
{
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
}
else
{
out[0] = b[0];
out[1] = b[1];
out[2] = b[2];
out[3] = b[3];
}
}
void ULK_vector_4d_min(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
float a_length = a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3];
float b_length = b[0]*b[0]+b[1]*b[1]+b[2]*b[2]+b[3]*b[3];
if(a_length<b_length)
{
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
}
else
{
out[0] = b[0];
out[1] = b[1];
out[2] = b[2];
out[3] = b[3];
}
}
void ULK_vector_4d_multiply(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
out[0] = a[0]*b[0];
out[1] = a[1]*b[1];
out[2] = a[2]*b[2];
out[3] = a[3]*b[3];
}
void ULK_vector_4d_negate(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = -in[0];
out[1] = -in[1];
out[2] = -in[2];
out[3] = -in[3];
}
void ULK_vector_4d_normalize(ULK_vector_4d out, const ULK_vector_4d in)
{
float length = in[0]*in[0]+in[1]*in[1]+in[2]*in[2]+in[3]*in[3];
if(length>0)
length = 1.0f/sqrtf(length);
out[0] = in[0]*length;
out[1] = in[1]*length;
out[2] = in[2]*length;
out[3] = in[3]*length;
}
void ULK_vector_4d_round(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = roundf(in[0]);
out[1] = roundf(in[1]);
out[2] = roundf(in[2]);
out[3] = roundf(in[3]);
}
void ULK_vector_4d_scale(ULK_vector_4d out, const ULK_vector_4d in, const float scale)
{
out[0] = in[0]*scale;
out[1] = in[1]*scale;
out[2] = in[2]*scale;
out[3] = in[3]*scale;
}
void ULK_vector_4d_set(ULK_vector_4d out, const float x, const float y, const float z, const float w)
{
out[0] = x;
out[1] = y;
out[2] = z;
out[3] = w;
}
float ULK_vector_4d_squared_distance(const ULK_vector_4d a, const ULK_vector_4d b)
{
float x = b[0]-a[0];
float y = b[1]-a[1];
float z = b[2]-a[2];
float w = b[3]-a[3];
return x*x+y*y+z*z+w*w;
}
float ULK_vector_4d_squared_length(const ULK_vector_4d in)
{
return in[0]*in[0]+in[1]*in[1]+in[2]*in[2]+in[3]*in[3];
}
void ULK_vector_4d_subtract(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b)
{
out[0] = a[0]-b[0];
out[1] = a[1]-b[1];
out[2] = a[2]-b[2];
out[3] = a[3]-b[3];
}
void ULK_vector_4d_zero(ULK_vector_4d out)
{
out[0] = 0.0f;
out[1] = 0.0f;
out[2] = 0.0f;
out[3] = 0.0f;
}

View file

@ -0,0 +1,132 @@
/*
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Captain4LK
commandant4lk@gmail.com
*/
#ifndef _ULK_VECTOR_H_
#define _ULK_VECTOR_H_
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef float ULK_vector_2d[2];
typedef float ULK_vector_3d[3];
typedef float ULK_vector_4d[4];
void ULK_vector_2d_add(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_angle(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_ceil(ULK_vector_2d out, const ULK_vector_2d in);
ULK_vector_2d *ULK_vector_2d_clone(const ULK_vector_2d in);
void ULK_vector_2d_copy(ULK_vector_2d dst, const ULK_vector_2d src);
ULK_vector_2d *ULK_vector_2d_create();
void ULK_vector_2d_cross(ULK_vector_3d out, const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_distance(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_divide(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_dot(const ULK_vector_2d a, const ULK_vector_2d b);
int ULK_vector_2d_equals(const ULK_vector_2d a, const ULK_vector_2d b);
int ULK_vector_2d_exact_equals(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_floor(ULK_vector_2d out, const ULK_vector_2d in);
ULK_vector_2d *ULK_vector_2d_from_values(const float x, const float y);
void ULK_vector_2d_invert(ULK_vector_2d out, const ULK_vector_2d in);
float ULK_vector_2d_length(const ULK_vector_2d in);
void ULK_vector_2d_lerp(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b, const float t);
void ULK_vector_2d_max(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_min(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_multiply(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_negate(ULK_vector_2d out, const ULK_vector_2d in);
void ULK_vector_2d_normalize(ULK_vector_2d out, const ULK_vector_2d in);
void ULK_vector_2d_rotate(ULK_vector_2d out, const ULK_vector_2d in, const ULK_vector_2d origin, const float radians);
void ULK_vector_2d_round(ULK_vector_2d out, const ULK_vector_2d in);
void ULK_vector_2d_scale(ULK_vector_2d out, const ULK_vector_2d in, const float scale);
void ULK_vector_2d_set(ULK_vector_2d out, const float x, const float y);
float ULK_vector_2d_squared_distance(const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_squared_length(const ULK_vector_2d in);
void ULK_vector_2d_subtract(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_zero(ULK_vector_2d out);
void ULK_vector_3d_add(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_angle(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_bezier(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, const float t);
void ULK_vector_3d_ceil(ULK_vector_3d out, const ULK_vector_3d in);
ULK_vector_3d *ULK_vector_3d_clone(const ULK_vector_3d in);
void ULK_vector_3d_copy(ULK_vector_3d dst, const ULK_vector_3d src);
ULK_vector_3d *ULK_vector_3d_create();
void ULK_vector_3d_cross(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_distance(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_divide(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_dot(const ULK_vector_3d a, const ULK_vector_3d b);
int ULK_vector_3d_equals(const ULK_vector_3d a, const ULK_vector_3d b);
int ULK_vector_3d_exact_equals(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_floor(ULK_vector_3d out, const ULK_vector_3d in);
ULK_vector_3d *ULK_vector_3d_from_values(const float x, const float y, const float z);
void ULK_vector_3d_hermite(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, float t);
void ULK_vector_3d_inverse(ULK_vector_3d out, const ULK_vector_3d in);
float ULK_vector_3d_length(const ULK_vector_3d in);
void ULK_vector_3d_lerp(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const float t);
void ULK_vector_3d_max(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_min(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_multiply(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_negate(ULK_vector_3d out, const ULK_vector_3d in);
void ULK_vector_3d_normalize(ULK_vector_3d out, const ULK_vector_3d in);
void ULK_vector_3d_rotate_x(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad);
void ULK_vector_3d_rotate_y(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad);
void ULK_vector_3d_rotate_z(ULK_vector_3d out, const ULK_vector_3d in, const ULK_vector_3d origin, const float rad);
void ULK_vector_3d_round(ULK_vector_3d out, const ULK_vector_3d in);
void ULK_vector_3d_scale(ULK_vector_3d out, const ULK_vector_3d in, const float scale);
void ULK_vector_3d_set(ULK_vector_3d out, const float x, const float y, const float z);
float ULK_vector_3d_squared_distance(const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_squared_length(const ULK_vector_3d in);
void ULK_vector_3d_subtract(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_zero(ULK_vector_3d out);
void ULK_vector_4d_add(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_ceil(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_clone(const ULK_vector_4d in);
void ULK_vector_4d_copy(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_create();
void ULK_vector_4d_cross(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const ULK_vector_4d c);
float ULK_vector_4d_distance(const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_divide(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
float ULK_vector_4d_dot(const ULK_vector_4d a, const ULK_vector_4d b);
int ULK_vector_4d_equals(const ULK_vector_4d a, const ULK_vector_4d b);
int ULK_vector_4d_exact_equals(const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_floor(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_from_values(const float x, const float y, const float z, const float w);
void ULK_vector_4d_inverse(ULK_vector_4d out, const ULK_vector_4d in);
float ULK_vector_4d_length(const ULK_vector_4d in);
void ULK_vector_4d_lerp(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const float t);
void ULK_vector_4d_max(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_min(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_multiply(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_negate(ULK_vector_4d out, const ULK_vector_4d in);
void ULK_vector_4d_normalize(ULK_vector_4d out, const ULK_vector_4d in);
void ULK_vector_4d_round(ULK_vector_4d out, const ULK_vector_4d in);
void ULK_vector_4d_scale(ULK_vector_4d out, const ULK_vector_4d in, const float scale);
void ULK_vector_4d_set(ULK_vector_4d out, const float x, const float y, const float z, const float w);
float ULK_vector_4d_squared_distance(const ULK_vector_4d a, const ULK_vector_4d b);
float ULK_vector_4d_squared_length(const ULK_vector_4d in);
void ULK_vector_4d_subtract(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_zero(ULK_vector_4d out);
#endif

View file

@ -0,0 +1,9 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o efelder *.c ../../lib/libSLK.a -lm -lSDL2 -ldl -lGL -lcjson -Wall
chmod +x efelder
./efelder
exit
/bin/bash

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

274
examples/efelder/main.c Normal file
View file

@ -0,0 +1,274 @@
/*
Copyright (C) 2020 by Captain4LK (Lukas Holzbeierlein)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../../include/SLK/SLK.h"
#include "ULK_file.h"
#include "ULK_vector.h"
#include <cjson/cJSON.h>
#define WIDTH 1920
#define HEIGHT 1080
typedef struct
{
int x;
int y;
int radius;
float charge;
char charge_str[16];
int test_points;
}Circle;
typedef struct
{
int type;
union
{
Circle circle;
};
}Shape;
Shape *shapes;
int shapes_count;
void load_shapes();
void draw_shapes();
void calculate_circle(int shape);
void calculate();
void calculate_pos(ULK_vector_2d out, float x, float y);
int main(int argc, char *argv[])
{
SLK_setup(WIDTH,HEIGHT,3,"SLK Engine",1,0);
SLK_timer_set_fps(30);
SLK_show_cursor(1);
SLK_layer_create(0,SLK_LAYER_RGB); //Layer for drawing shapes
SLK_layer_create(1,SLK_LAYER_RGB); //Layer for drawing electric field
SLK_layer_create(2,SLK_LAYER_RGB);
SLK_layer_activate(0,1);
SLK_layer_activate(1,0);
SLK_layer_activate(2,1);
load_shapes();
draw_shapes();
calculate();
while(SLK_running())
{
SLK_update();
SLK_render_update();
}
return 0;
}
void load_shapes()
{
char *buffer = ULK_file_load("objects.json");
cJSON *json = NULL;
cJSON *circles = NULL;
int objects_count = 0;
int circles_count = 0;
int i;
if(buffer==NULL)
{
printf("Failed to load objects.json!\n");
return;
}
json = cJSON_Parse(buffer);
if(json==NULL)
printf("Json file seems to be faulty!\n");
//Load all shapes here and count them
circles = cJSON_GetObjectItem(json,"circles");
if(circles==NULL)
printf("No circles specified!\n");
circles_count = cJSON_GetArraySize(circles);
printf("Found %d circles\n",circles_count);
objects_count+=circles_count;
//Allocate enough space for all shapes
shapes_count = objects_count;
shapes = malloc(sizeof(Shape)*shapes_count);
objects_count = 0;
//Load all circles
for(i = 0;i<circles_count;i++)
{
cJSON *circle = cJSON_GetArrayItem(circles,i);
shapes[objects_count].circle.x = cJSON_GetObjectItem(circle,"x")->valueint;
shapes[objects_count].circle.y = cJSON_GetObjectItem(circle,"y")->valueint;
shapes[objects_count].circle.radius = cJSON_GetObjectItem(circle,"radius")->valueint;
shapes[objects_count].circle.charge = cJSON_GetObjectItem(circle,"charge")->valuedouble;
shapes[objects_count].circle.test_points = cJSON_GetObjectItem(circle,"test_points")->valueint;
shapes[objects_count].type = 0;
sprintf(shapes[objects_count].circle.charge_str,"%07fC",shapes[objects_count].circle.charge);
objects_count++;
}
}
void draw_shapes()
{
int i;
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
for(i = 0;i<shapes_count;i++)
{
if(shapes[i].type==0) //Circle
{
SLK_draw_rgb_circle(shapes[i].circle.x,shapes[i].circle.y,shapes[i].circle.radius,SLK_color_create(255,255,255,255));
SLK_draw_rgb_string(shapes[i].circle.x-72,shapes[i].circle.y-8,2,shapes[i].circle.charge_str,SLK_color_create(255,0,0,255));
}
}
}
void calculate()
{
int i;
SLK_layer_set_current(1);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
for(i = 0;i<shapes_count;i++)
{
switch(shapes[i].type)
{
case 0:
calculate_circle(i);
break;
}
}
SLK_layer_set_current(2);
SLK_draw_rgb_clear();
//Calculate electrical
for(int x = 0;x<WIDTH;x++)
{
for(int y = 0;y<HEIGHT;y++)
{
ULK_vector_2d point;
ULK_vector_2d center;
ULK_vector_2d_set(point,(float)x,(float)y);
float potential = 0.0f;
for(int i = 0;i<shapes_count;i++)
{
if(shapes[i].type==0)
{
ULK_vector_2d distance;
float length;
ULK_vector_2d_set(center,(float)shapes[i].circle.x,(float)shapes[i].circle.y);
ULK_vector_2d_subtract(distance,center,point);
length = ULK_vector_2d_length(distance);
if(length!=0.0f)
potential+=8987551788.0f*(shapes[i].circle.charge/length);
}
}
uint8_t color = (uint8_t)(((potential/10000000.000000f)*255.0f));
if(color<5)
SLK_draw_rgb_color(x,y,SLK_color_create(255,255,255,255));
}
}
}
void calculate_circle(int shape)
{
int i;
int o;
for(i = 0;i<shapes[shape].circle.test_points;i++)
{
ULK_vector_2d origin;
ULK_vector_2d point;
ULK_vector_2d pos;
int tries = 0;
int negative = shapes[shape].circle.charge<0.0f;
float angle = ((float)i/(float)shapes[shape].circle.test_points)*6.2831853f;
ULK_vector_2d_set(origin,shapes[shape].circle.x,shapes[shape].circle.y);
ULK_vector_2d_set(point,shapes[shape].circle.x,shapes[shape].circle.y-shapes[shape].circle.radius);
ULK_vector_2d_rotate(point,point,origin,angle);
ULK_vector_2d_copy(pos,point);
while(tries<10000)
{
tries++;
ULK_vector_2d norm;
ULK_vector_2d distance;
ULK_vector_2d result;
ULK_vector_2d force_result;
float force;
float length;
ULK_vector_2d_zero(force_result);
for(o = 0;o<shapes_count;o++)
{
if(shapes[o].type==0)
{
ULK_vector_2d center;
ULK_vector_2d_set(center,shapes[o].circle.x,shapes[o].circle.y);
ULK_vector_2d_subtract(distance,center,pos);
length = ULK_vector_2d_length(distance);
ULK_vector_2d_normalize(norm,distance);
ULK_vector_2d_scale(norm,norm,-1.0f);
force = 8987551788.0f*(fabs(shapes[o].circle.charge)/(length*length))*0.000000001602;
if(((shapes[o].circle.charge<0.0f)^negative)&&shape!=o)
ULK_vector_2d_scale(norm,norm,-force);
else
ULK_vector_2d_scale(norm,norm,force);
ULK_vector_2d_copy(result,norm);
}
ULK_vector_2d_add(force_result,force_result,result);
}
//ULK_vector_2d_scale(force_result,force_result,FACTOR);
ULK_vector_2d_normalize(force_result,force_result);
ULK_vector_2d_add(pos,pos,force_result);
SLK_draw_rgb_color((int)pos[0],(int)pos[1],SLK_color_create(255,128,0,255));
}
printf("%d of %d calculated, %f\n",i,shapes[shape].circle.test_points,angle);
}
}
void calculate_pos(ULK_vector_2d out, float x, float y)
{
}

View file

@ -0,0 +1,25 @@
{
"circles":
[
{
"x":1520,
"y":540,
"radius":128,
"charge":2.0,
"test_points":45
},
{
"x":400,
"y":540,
"radius":128,
"charge":-2.0,
"test_points":45
},
{
"x":960,
"y":64,
"radius":64,
"charge":-2.0,
"test_points":45
}]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o hecate_map_editor main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x hecate_map_editor
./hecate_map_editor
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

View file

@ -1,320 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "../../include/SLK/SLK.h"
typedef struct
{
int32_t x,y;
uint8_t used;
}NPC_spawn;
typedef struct
{
int32_t x,y;
uint8_t used;
}Enemy_spawn;
typedef struct
{
int32_t x,y;
uint8_t used;
}Item_spawn;
typedef struct
{
uint16_t tiles[15][16];
NPC_spawn npc_spawner[10];
Enemy_spawn enemy_spawner[10];
Item_spawn item_spawner[10];
}Room_template;
Room_template rooms[15][50];
int intersect(int x, int y, int rx, int ry, int rw, int rh);
void save();
void editor_menu();
void editor_tiles();
void editor_enemies();
void editor_items();
void editor_npcs();
SLK_Sprite_rgb *tiles[160];
SLK_Sprite_rgb *tile_select;
SLK_Sprite_rgb *room_buttons[15];
SLK_Sprite_rgb *menu_buttons[2];
SLK_Sprite_rgb *marker;
int mode = 0;
int room_type = 0;
int room_number = 0;
int selected_tile = 0;
//Magic numbers, yay!
int room_selection[15] = {14,10,13,6,12,11,2,9,5,4,8,7,1,3,0};
char room_number_str[64];
int mouse_x,mouse_y;
int intersect(int x, int y, int rx, int ry, int rw, int rh)
{
if(INBOUNDS(rx, rx + rw, x)&&INBOUNDS(ry, ry + rh, y))
return 1;
return 0;
}
void save()
{
FILE *f = fopen("data/rooms.hmt","wb");
fwrite(rooms,sizeof(rooms),1,f);
fclose(f);
}
int main(int argc, char *argv[])
{
SLK_setup(512,240,"Hecate map editor",0,3);
SLK_set_FPS(30);
SLK_set_clear_color(SLK_create_color(34,34,34,255));
SLK_clear_screen();
FILE *f = fopen("data/rooms.hmt","rb");
fread(rooms,sizeof(rooms),1,f);
fclose(f);
SLK_Sprite_rgb *tileset = SLK_load_sprite_rgb("assets/tileset.png");
tile_select = SLK_create_sprite_rgb(256,160);
SLK_set_draw_target(tile_select);
SLK_draw_partial_sprite_rgb(tileset,0,0,0,0,256,160);
for(int y = 0; y < 10; y++)
{
for(int x = 0; x < 16; x++)
{
tiles[y*16+x] = SLK_create_sprite_rgb(16,16);
SLK_set_draw_target(tiles[y*16+x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*16,y*16,16,16);
}
}
for(int x = 0; x < 15; x++)
{
room_buttons[x] = SLK_create_sprite_rgb(16,16);
SLK_set_draw_target(room_buttons[x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*16,160,16,16);
}
for(int x = 0; x < 2; x++)
{
menu_buttons[x] = SLK_create_sprite_rgb(32,16);
SLK_set_draw_target(menu_buttons[x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*32+240,160,32,16);
}
marker = SLK_create_sprite_rgb(16,16);
SLK_set_draw_target(marker);
SLK_draw_partial_sprite_rgb(tileset,0,0,0,144,16,16);
SLK_destroy_sprite_rgb(tileset);
SLK_set_draw_target(NULL);
sprintf(room_number_str,"%d",room_number);
while(SLK_running())
{
SLK_update();
SLK_get_mouse_pos(&mouse_x,&mouse_y);
switch(mode)
{
case 0:
//Menu
editor_menu();
break;
case 1:
//Tile editor
editor_tiles();
break;
case 2:
//Enemy spawner editor
editor_enemies();
break;
case 3:
//Item spawner editor
editor_items();
break;
case 4:
//NPC spawner editor
editor_npcs();
break;
}
SLK_update_screen();
}
save();
return 0;
}
void editor_menu()
{
SLK_clear_screen();
for(int y = 0; y < 3; y++)
for(int x = 0; x < 5; x++)
SLK_draw_sprite_rgb(room_buttons[y*5+x],x*32+32,y*32+32);
SLK_draw_sprite_rgb(tile_select,256,0);
SLK_draw_sprite_rgb(menu_buttons[0],64,128);
SLK_draw_sprite_rgb(menu_buttons[1],112,128);
if(SLK_mouse_pressed(SLK_BUTTON_LEFT))
{
if(intersect(mouse_x,mouse_y,112,128,32,16))
SLK_quit();
if(intersect(mouse_x,mouse_y,64,128,32,16))
save();
for(int y = 0; y < 3; y++)
for(int x = 0; x < 5; x++)
if(intersect(mouse_x,mouse_y, x * 32 + 32, y * 32 + 32, 16, 16))
room_type = room_selection[y*5+x];
}
if(SLK_key_pressed(SLK_KEY_ESCAPE))
mode = 1;
}
void editor_tiles()
{
if(SLK_mouse_pressed(SLK_BUTTON_LEFT)&&mouse_x>=256&&INBOUNDS(0,160,mouse_y))
selected_tile = (mouse_y/16)*16+((mouse_x-256)/16);
if(SLK_mouse_down(SLK_BUTTON_LEFT)&&mouse_x<256)
rooms[room_type][room_number].tiles[mouse_y/16][mouse_x/16] = selected_tile;
if(SLK_key_pressed(SLK_KEY_ESCAPE))
mode = 0;
if(SLK_key_pressed(SLK_KEY_E))
mode = 2;
if(SLK_key_pressed(SLK_KEY_I))
mode = 3;
if(SLK_key_pressed(SLK_KEY_N))
mode = 4;
if(SLK_key_pressed(SLK_KEY_LEFT)&&room_number>0)
{
room_number--;
sprintf(room_number_str,"%d",room_number);
}
if(SLK_key_pressed(SLK_KEY_RIGHT)&&room_number<49)
{
room_number++;
sprintf(room_number_str,"%d",room_number);
}
SLK_clear_screen();
for(int y = 0;y<15;y++)
for(int x = 0;x<16;x++)
SLK_draw_sprite_rgb(tiles[rooms[room_type][room_number].tiles[y][x]],x*16,y*16);
SLK_draw_sprite_rgb(tile_select,256,0);
SLK_draw_sprite_rgb(marker,selected_tile%16*16+256,selected_tile/16*16);
SLK_draw_string(256,216,1,room_number_str,SLK_create_color(255,255,255,255));
}
void editor_enemies()
{
if(SLK_key_pressed(SLK_KEY_ESCAPE))
mode = 0;
if(SLK_key_pressed(SLK_KEY_T))
mode = 1;
if(SLK_key_pressed(SLK_KEY_I))
mode = 3;
if(SLK_key_pressed(SLK_KEY_N))
mode = 4;
if(SLK_key_pressed(SLK_KEY_LEFT)&&room_number>0)
{
room_number--;
sprintf(room_number_str,"%d",room_number);
}
if(SLK_key_pressed(SLK_KEY_RIGHT)&&room_number<49)
{
room_number++;
sprintf(room_number_str,"%d",room_number);
}
SLK_clear_screen();
for(int y = 0;y<15;y++)
for(int x = 0;x<16;x++)
SLK_draw_sprite_rgb(tiles[rooms[room_type][room_number].tiles[y][x]],x*16,y*16);
SLK_draw_string(256,216,1,room_number_str,SLK_create_color(255,255,255,255));
}
void editor_items()
{
if(SLK_key_pressed(SLK_KEY_ESCAPE))
mode = 0;
if(SLK_key_pressed(SLK_KEY_T))
mode = 1;
if(SLK_key_pressed(SLK_KEY_E))
mode = 2;
if(SLK_key_pressed(SLK_KEY_N))
mode = 4;
if(SLK_key_pressed(SLK_KEY_LEFT)&&room_number>0)
{
room_number--;
sprintf(room_number_str,"%d",room_number);
}
if(SLK_key_pressed(SLK_KEY_RIGHT)&&room_number<49)
{
room_number++;
sprintf(room_number_str,"%d",room_number);
}
SLK_clear_screen();
for(int y = 0;y<15;y++)
for(int x = 0;x<16;x++)
SLK_draw_sprite_rgb(tiles[rooms[room_type][room_number].tiles[y][x]],x*16,y*16);
SLK_draw_string(256,216,1,room_number_str,SLK_create_color(255,255,255,255));
}
void editor_npcs()
{
if(SLK_key_pressed(SLK_KEY_ESCAPE))
mode = 0;
if(SLK_key_pressed(SLK_KEY_T))
mode = 1;
if(SLK_key_pressed(SLK_KEY_E))
mode = 2;
if(SLK_key_pressed(SLK_KEY_I))
mode = 3;
if(SLK_key_pressed(SLK_KEY_LEFT)&&room_number>0)
{
room_number--;
sprintf(room_number_str,"%d",room_number);
}
if(SLK_key_pressed(SLK_KEY_RIGHT)&&room_number<49)
{
room_number++;
sprintf(room_number_str,"%d",room_number);
}
SLK_clear_screen();
for(int y = 0;y<15;y++)
for(int x = 0;x<16;x++)
SLK_draw_sprite_rgb(tiles[rooms[room_type][room_number].tiles[y][x]],x*16,y*16);
SLK_draw_string(256,216,1,room_number_str,SLK_create_color(255,255,255,255));
}

View file

@ -1 +0,0 @@
colorscheme luke

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,66 +0,0 @@
#include "../../include/SLK/SLK.h"
typedef struct
{
int x,y;
SLK_Color c;
}Pixel;
typedef struct
{
Pixel *data;
int used;
int space;
}Pixel_vector;
int main(int argc, char *argv[])
{
SLK_setup(256,224,"SLK Engine",0,3);
SLK_set_FPS(60);
SLK_show_cursor(1);
SLK_set_clear_color(SLK_create_color(0,0,0,255));
SLK_clear_screen();
SLK_Sprite_rgb *logo = SLK_load_sprite_rgb("../assets/logo.png");
Pixel_vector logo_printer = {malloc(sizeof(Pixel)*10),0,10};
int pixel = 1;
for(int y = logo->height;y>0;y--)
{
for(int x = 0;x<logo->width;x++)
{
if(SLK_get_pixel_rgb(logo,x,y).a)
{
logo_printer.data[logo_printer.used].c = SLK_get_pixel_rgb(logo,x,y);
logo_printer.data[logo_printer.used].x = x;
logo_printer.data[logo_printer.used].y = y;
logo_printer.used++;
if(logo_printer.used==logo_printer.space)
{
logo_printer.space+=10;
logo_printer.data = realloc(logo_printer.data,sizeof(Pixel)*logo_printer.space);
}
}
}
}
while(SLK_running())
{
SLK_update();
for(int i = 0;i<5;i++)
{
if(pixel<logo_printer.used)
{
SLK_draw_line(0,0,logo_printer.data[pixel-1].x,logo_printer.data[pixel-1].y,SLK_create_color(0,0,0,255));
SLK_draw(logo_printer.data[pixel].x,logo_printer.data[pixel].y,logo_printer.data[pixel].c);
SLK_draw_line(0,0,logo_printer.data[pixel].x,logo_printer.data[pixel].y,SLK_create_color(255,255,255,255));
pixel++;
}
}
SLK_update_screen();
}
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,102 +0,0 @@
#include "main.h"
int main()
{
SLK_setup(256,224,"Mode 7",0,3);
SLK_set_FPS(30);
float fWorldX = 1000.0f;
float fWorldY = 1000.0f;
float fWorldA = 0.1f;
float fNear = 0.005f;
float fFar = 0.03f;
float fFoVHalf = 3.14159f / 4.0f;
track = SLK_load_sprite_rgb("assets/track.png");
sky = SLK_load_sprite_rgb("assets/sky.png");
while(SLK_running())
{
SLK_update();
if(SLK_key_down(SLK_KEY_Q))
fNear += 0.01f;
if(SLK_key_down(SLK_KEY_A))
fNear -= 0.01f;
if(SLK_key_down(SLK_KEY_W))
fFar += 0.001f;
if(SLK_key_down(SLK_KEY_S))
fFar -= 0.001f;
if(SLK_key_down(SLK_KEY_Y)
fFoVHalf += 0.01f;
if(SLK_key_down(SLK_KEY_X))
fFoVHalf -= 0.01f;
float fFarX1 = fWorldX + cosf(fWorldA - fFoVHalf) * fFar;
float fFarY1 = fWorldY + sinf(fWorldA - fFoVHalf) * fFar;
float fNearX1 = fWorldX + cosf(fWorldA - fFoVHalf) * fNear;
float fNearY1 = fWorldY + sinf(fWorldA - fFoVHalf) * fNear;
float fFarX2 = fWorldX + cosf(fWorldA + fFoVHalf) * fFar;
float fFarY2 = fWorldY + sinf(fWorldA + fFoVHalf) * fFar;
float fNearX2 = fWorldX + cosf(fWorldA + fFoVHalf) * fNear;
float fNearY2 = fWorldY + sinf(fWorldA + fFoVHalf) * fNear;
for (int y = 0; y < engine->screen_height / 2; y++)
{
float fSampleDepth = (float)y / ((float)engine->screen_height / 2.0f);
float fStartX = (fFarX1 - fNearX1) / (fSampleDepth) + fNearX1;
float fStartY = (fFarY1 - fNearY1) / (fSampleDepth) + fNearY1;
float fEndX = (fFarX2 - fNearX2) / (fSampleDepth) + fNearX2;
float fEndY = (fFarY2 - fNearY2) / (fSampleDepth) + fNearY2;
for (int x = 0; x < engine->screen_width; x++)
{
float fSampleWidth = (float)x / (float)engine->screen_width;
float fSampleX = (fEndX - fStartX) * fSampleWidth + fStartX;
float fSampleY = (fEndY - fStartY) * fSampleWidth + fStartY;
fSampleX = fmod(fSampleX, 1.0f);
fSampleY = fmod(fSampleY, 1.0f);
draw(engine,x,y + (engine->screen_height / 2),sample_pixel(track,fSampleX,fSampleY));
draw(engine,x,(engine->screen_height / 2)-y,sample_pixel(sky,fSampleX,fSampleY));
}
}
if(engine->keyboard_state[KEY_LEFT].held)
fWorldA -= 0.05f;
if(engine->keyboard_state[KEY_RIGHT].held)
fWorldA += 0.05f;
if(engine->keyboard_state[KEY_UP].held)
{
fWorldX += cosf(fWorldA) * 0.005f;
fWorldY += sinf(fWorldA) * 0.005f;
}
if(engine->keyboard_state[KEY_DOWN].held)
{
fWorldX -= cosf(fWorldA) * 0.005f;
fWorldY -= sinf(fWorldA) * 0.005f;
}
engine_update_screen(engine);
}
printf("You shall close: %d\n",get_current_engine()->running);
return 0;
}

View file

@ -1,10 +0,0 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#include "../../include/SLK/SLK.h"
SLK_Sprite_rgb *track;
SLK_Sprite_rgb *sky;
#endif // _MAIN_H_

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,47 @@
JASC-PAL
0100
44
0 0 0 0
34 32 52 255
208 70 72 255
146 38 59 255
220 182 65 255
170 102 34 255
117 31 32 255
138 70 2 255
130 138 88 255
169 183 87 255
85 68 68 255
136 119 119 255
59 51 40 255
170 51 51 255
61 98 179 255
68 124 207 255
204 170 68 255
200 148 55 255
56 56 57 255
77 78 76 255
203 159 118 255
175 128 85 255
250 250 250 255
170 73 81 255
204 204 190 255
53 53 53 255
62 62 62 255
67 67 67 255
187 84 50 255
204 119 51 255
255 255 255 255
80 84 54 255
23 129 120 255
143 96 53 255
148 74 156 255
78 74 78 255
119 85 85 255
104 110 70 255
119 34 171 255
48 52 22 255
138 52 77 255
122 51 51 255
86 37 47 255
171 179 192 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

View file

@ -1,7 +1,7 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -ldl -Wall
chmod +x engine
./engine
exit

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,7 +1,6 @@
JASC-PAL
0100
17
0 0 0
16
69 36 52
20 12 28
211 170 154

View file

@ -7,77 +7,92 @@ typedef struct
int type;
int frame;
int flip;
}Dino;
}Entity;
typedef struct
{
Dino *dinos;
Entity *entities;
int used;
int space;
}Dino_army;
}Entities;
Dino_army world;
SLK_Sprite *dino_sprites[4][24];
Entities world;
SLK_Pal_sprite *dino_sprites[10][4];
SLK_RGB_sprite *dino_sprites_rgb[10][4];
SLK_RGB_sprite *gui_00;
SLK_RGB_sprite *gui_01;
int frame = 0;
char time_stat[48];
int render_mode = 0;
void add_dino();
void add_entity();
void load_pal_sprites();
void load_rgb_sprites();
int sort(const void *e0, const void *e1);
int main(int argc, char *argv[])
{
SLK_setup(320,240,"SLK Engine",1,1);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(1);
SLK_clear_screen();
SLK_setup(320,240,5,"SLK Engine",0,SLK_WINDOW_MAX);
SLK_timer_set_fps(30);
srand(time(NULL));
SLK_load_palette("../assets/performance.pal");
SLK_Sprite *tileset = SLK_load_sprite("../assets/dino_sprites_doux.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[0][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[0][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite(tileset);
SLK_layer_create(0,SLK_LAYER_RGB);
SLK_layer_create(1,SLK_LAYER_PAL);
SLK_layer_create(2,SLK_LAYER_RGB);
SLK_layer_create(4,SLK_LAYER_RGB);
tileset = SLK_load_sprite("../assets/dino_sprites_mort.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[1][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[1][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite(tileset);
SLK_layer_activate(0,1);
SLK_layer_activate(1,1);
SLK_layer_activate(2,1);
SLK_layer_activate(4,1);
tileset = SLK_load_sprite("../assets/dino_sprites_tard.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[2][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[2][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite(tileset);
SLK_layer_set_current(0);
SLK_layer_set_current(1);
tileset = SLK_load_sprite("../assets/dino_sprites_vita.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[3][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[3][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite(tileset);
SLK_draw_pal_set_clear_paxel(SLK_color_create_paxel(0,SLK_TRANSPARENT));
SLK_draw_pal_clear();
SLK_draw_rgb_set_clear_color(SLK_color_create(255,255,255,0));
SLK_draw_rgb_clear();
load_pal_sprites();
load_rgb_sprites();
gui_00 = SLK_rgb_sprite_load("assets/gui_00.png");
gui_01 = SLK_rgb_sprite_load("assets/gui_01.png");
SLK_RGB_sprite *gui_02 = SLK_rgb_sprite_load("assets/gui_02.png");
SLK_layer_set_current(0);
SLK_draw_rgb_sprite(gui_02,0,220);
SLK_draw_rgb_sprite(gui_01,206,2);
SLK_draw_rgb_string(214,10,1,"pal renderer",SLK_color_create(255,255,255,255));
SLK_rgb_sprite_destroy(gui_02);
SLK_RGB_sprite *gui_03 = SLK_rgb_sprite_load("assets/gui_03.png");
SLK_layer_set_current(4);
SLK_draw_rgb_sprite(gui_03,0,0);
SLK_rgb_sprite_destroy(gui_03);
world.space = 100;
world.used = 0;
world.dinos = malloc(sizeof(Dino)*world.space);
double time = 0;
world.entities= malloc(sizeof(Entity)*world.space);
double time = 0.1f;
while(world.used<1000)
add_dino();
while(world.used<10)
add_entity();
while(SLK_running())
{
SLK_update();
SLK_clear_screen();
if(render_mode==0)
{
SLK_layer_set_current(1);
SLK_draw_pal_clear();
}
else if(render_mode==1)
{
SLK_layer_set_current(2);
SLK_draw_rgb_clear();
}
frame++;
int next_frame = frame%4==0;
@ -86,42 +101,126 @@ int main(int argc, char *argv[])
{
if(next_frame)
{
world.dinos[i].frame++;
if(world.dinos[i].frame>3)
world.dinos[i].frame = 0;
world.entities[i].frame++;
if(world.entities[i].frame>3)
world.entities[i].frame = 0;
}
if(render_mode==0)
{
SLK_draw_pal_sprite(dino_sprites[world.entities[i].type][world.entities[i].frame],world.entities[i].x,world.entities[i].y);
}
else if(render_mode==1)
{
SLK_draw_rgb_sprite(dino_sprites_rgb[world.entities[i].type][world.entities[i].frame],world.entities[i].x,world.entities[i].y);
}
SLK_draw_sprite(dino_sprites[world.dinos[i].type][world.dinos[i].frame],world.dinos[i].x,world.dinos[i].y);
}
time+=((double)(clock()-start)/CLOCKS_PER_SEC);
if(next_frame)
sprintf(time_stat,"%04lf %04d",time/((double)frame)/*/world.used*10.0f*/,world.used);
sprintf(time_stat,"%08lf %04d",time/((double)frame)/*/world.used*10.0f*/,world.used);
if(SLK_key_down(SLK_KEY_SPACE))
add_dino();
SLK_fill_rectangle(0,0,104,8,SLK_create_paxel(2,SLK_OPAQUE));
SLK_draw_string(0,0,1,time_stat,SLK_create_paxel(3,SLK_OPAQUE));
if(SLK_key_down(SLK_KEY_SPACE)&&world.used<9999)
add_entity();
SLK_update_screen();
if(SLK_key_pressed(SLK_KEY_P))
{
render_mode = 0;
time = 0.0f;
frame = 0;
SLK_layer_activate(2,0);
SLK_layer_activate(1,1);
SLK_layer_set_current(0);
SLK_draw_rgb_sprite(gui_01,206,2);
SLK_draw_rgb_string(214,10,1,"pal renderer",SLK_color_create(255,255,255,255));
}
if(SLK_key_pressed(SLK_KEY_R))
{
render_mode = 1;
time = 0.0f;
frame = 0;
SLK_layer_activate(2,1);
SLK_layer_activate(1,0);
SLK_layer_set_current(0);
SLK_draw_rgb_sprite(gui_01,206,2);
SLK_draw_rgb_string(214,10,1,"rgb renderer",SLK_color_create(255,255,255,255));
}
SLK_layer_set_current(0);
SLK_draw_rgb_sprite(gui_00,2,2);
SLK_draw_rgb_string(10,10,1,time_stat,SLK_color_create(255,255,255,255));
SLK_render_update();
}
return 0;
}
void add_dino()
void add_entity()
{
world.dinos[world.used].frame = rand()%4;
world.dinos[world.used].x = rand()%320-12;
world.dinos[world.used].y = rand()%240-12;
world.dinos[world.used].type = rand()%4;
world.dinos[world.used].flip = rand()%2;
world.entities[world.used].frame = rand()%4;
world.entities[world.used].x = rand()%294+5;
world.entities[world.used].y = rand()%201+10;
world.entities[world.used].type = rand()%10;
world.entities[world.used].flip = rand()%2;
world.used++;
qsort(world.entities,world.used,sizeof(Entity),sort);
if(world.used>=world.space)
{
world.space+=100;
world.dinos = realloc(world.dinos,sizeof(Dino)*world.space);
world.entities = realloc(world.entities,sizeof(Entity)*world.space);
}
}
void load_pal_sprites()
{
SLK_layer_set_current(1);
SLK_layer_set_palette(1,SLK_palette_load("assets/palette.pal"));
SLK_Pal_sprite *tileset = SLK_pal_sprite_load("assets/sprites.slk");
for(int y = 0;y<10;y++)
{
for(int x = 0;x<4;x++)
{
dino_sprites[y][x] = SLK_pal_sprite_create(16,24);
SLK_pal_sprite_copy_partial(dino_sprites[y][x],tileset,0,0,x*16,y*24,16,24);
}
}
SLK_pal_sprite_destroy(tileset);
}
void load_rgb_sprites()
{
SLK_layer_set_current(2);
SLK_RGB_sprite *tileset = SLK_rgb_sprite_load("assets/sprites.png");
for(int y = 0;y<10;y++)
{
for(int x = 0;x<4;x++)
{
dino_sprites_rgb[y][x] = SLK_rgb_sprite_create(16,24);
SLK_draw_rgb_set_target(dino_sprites_rgb[y][x]);
SLK_draw_rgb_clear();
SLK_draw_rgb_sprite_partial(tileset,0,0,x*16,y*24,16,24);
}
}
SLK_rgb_sprite_destroy(tileset);
}
int sort(const void *e0, const void *e1)
{
if(((Entity *)e0)->y<((Entity *)e1)->y)
return -1;
else if(((Entity *)e0)->y>((Entity *)e1)->y)
return 1;
else
return 0;
}

View file

@ -0,0 +1,19 @@
JASC-PAL
0100
16
69 36 52
20 12 28
211 170 154
223 239 215
211 125 44
219 215 93
211 69 73
134 77 48
77 73 77
48 52 109
117 113 97
109 195 203
134 150 162
109 170 44
52 101 36
89 125 207

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,22 +0,0 @@
#include "../../include/SLK/SLK.h"
int main(int argc, char *argv[])
{
SLK_setup(256,224,"SLK Engine",0,3);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(SLK_create_color(0,0,0,255));
SLK_clear_screen();
while(SLK_running())
{
SLK_update();
SLK_draw_rectangle(2,2,20,20,SLK_create_color(255,255,255,255));
SLK_draw_line(30,22,100,100,SLK_create_color(255,128,0,255));
SLK_update_screen();
}
return 0;
}

View file

@ -1,8 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o voxelspace *.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x voxelspace
./voxelspace
/bin/bash

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,19 +0,0 @@
#include "../../include/SLK/SLK.h"
int main(int argc, char *argv[])
{
SLK_setup(256,224,"SLK Engine",1,0);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(SLK_create_color(0,0,0,255));
SLK_clear_screen();
while(SLK_running())
{
SLK_update();
SLK_update_screen();
}
return 0;
}

View file

@ -1,9 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine *.c ../../lib/libSLK.a -lm -lSDL2 -lGL -Wall
chmod +x engine
./engine
exit
/bin/bash

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -o engine main.c ../../lib/libSLK.a -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
start engine
cmd /k

View file

@ -1,73 +0,0 @@
#include "../../include/SLK/SLK.h"
void update_menu();
SLK_Sprite *sprites_blocks[26];
int mode = 0;
int game_mode_left = 0;
int game_mode_right = 0;
int main(int argc, char *argv[])
{
SLK_setup(323,240,"Tetris",1,0);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(0);
SLK_clear_screen();
SLK_load_palette("../assets/tetris.pal");
SLK_Sprite *tileset = SLK_load_sprite("../assets/tetris.slk");
for(int x = 0;x<26;x++)
{
sprites_blocks[x] = SLK_create_sprite(16,16);
SLK_copy_partial_sprite(sprites_blocks[x],tileset,0,0,x*16,0,16,16);
}
SLK_destroy_sprite(tileset);
while(SLK_running())
{
SLK_update();
switch(mode)
{
case 0:
update_menu();
break;
}
SLK_update_screen();
}
return 0;
}
void update_menu()
{
if(game_mode_left==0)
{
SLK_draw_string(10,80,3,"T",SLK_create_paxel(10,SLK_OPAQUE));
SLK_draw_string(26,80,3,"e",SLK_create_paxel(12,SLK_OPAQUE));
SLK_draw_string(42,80,3,"t",SLK_create_paxel(3,SLK_OPAQUE));
SLK_draw_string(58,80,3,"r",SLK_create_paxel(4,SLK_OPAQUE));
SLK_draw_string(74,80,3,"i",SLK_create_paxel(6,SLK_OPAQUE));
SLK_draw_string(90,80,3,"s",SLK_create_paxel(9,SLK_OPAQUE));
}
else
{
}
if(game_mode_right==0)
{
}
else
{
}
SLK_draw_rectangle(0,0,162,240,SLK_create_paxel(2,SLK_OPAQUE));
SLK_draw_rectangle(161,0,162,240,SLK_create_paxel(2,SLK_OPAQUE));
//SLK_draw_line(162,0,162,240,SLK_create_paxel(3,SLK_OPAQUE));
}

View file

@ -31,10 +31,8 @@
#include <math.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <GL/gl.h>
#include <SDL2/SDL.h>
#include <png.h>
#include "../glad/glad.h"
//Macros
//Fast integer inbounds checking

View file

@ -22,22 +22,96 @@
#define _SLK_FUNCTIONS_H_
//SLK_Sprite functionality
SLK_Sprite *SLK_create_sprite(int width, int height);
void SLK_destroy_sprite(SLK_Sprite *s);
SLK_Paxel SLK_get_paxel(SLK_Sprite *s, int x, int y);
void SLK_set_paxel(SLK_Sprite *s, int x, int y, SLK_Paxel c);
SLK_Sprite *SLK_load_sprite(const char *path);
void SLK_save_sprite(const char *path, SLK_Sprite *s);
//--------------------------------------------
#include "SLK_types.h"
//SLK_Palette functionality
void SLK_load_palette(const char *path);
//--------------------------------------------
//Palette subsystem: SLK_palette.c
SLK_Palette *SLK_palette_load(const char *path);
//SLK_draw functionality
void SLK_draw(int x, int y, SLK_Paxel p);
void SLK_draw_nc(int x, int y, SLK_Paxel p);
//Timer subsystem: SLK_timer.c
void SLK_timer_set_fps(const int FPS);
void SLK_timer_update();
float SLK_timer_get_delta();
//Render subsystem: SLK_render.c
void SLK_render_init();
void SLK_render_update();
//Pal sprite subsystem: SLK_sprite_pal.c
SLK_Pal_sprite *SLK_pal_sprite_create(const int width, const int height);
void SLK_pal_sprite_destroy(SLK_Pal_sprite *s);
SLK_Paxel SLK_pal_sprite_get_paxel(const SLK_Pal_sprite *s, const int x, const int y);
void SLK_pal_sprite_set_paxel(SLK_Pal_sprite *s, const int x, const int y, const SLK_Paxel c);
SLK_Pal_sprite *SLK_pal_sprite_load(const char *path);
void SLK_pal_sprite_save(const char *path, const SLK_Pal_sprite *s);
void SLK_pal_sprite_copy_partial(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src, const int x, const int y, const int ox, const int oy, const int width, const int height);
void SLK_pal_sprite_copy(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src);
//Draw pal subsystem: SLK_draw_pal.c
void SLK_draw_pal_set_target(SLK_Pal_sprite *s);
void SLK_draw_pal_set_clear_paxel(SLK_Paxel paxel);
void SLK_draw_pal_clear();
void SLK_draw_pal_paxel(int x, int y, SLK_Paxel paxel);
void SLK_draw_pal_string(int x, int y, int scale, const char *text, SLK_Paxel paxel);
void SLK_draw_pal_sprite(const SLK_Pal_sprite *s, int x, int y);
void SLK_draw_pal_sprite_partial(const SLK_Pal_sprite *s, int x, int y, int ox, int oy, int width, int height);
void SLK_draw_pal_sprite_flip(const SLK_Pal_sprite *s, int x, int y, int flip);
void SLK_draw_pal_line(int x0, int y0, int x1, int y1, SLK_Paxel paxel);
void SLK_draw_pal_vertical_line(int x, int y0, int y1, SLK_Paxel paxel);
void SLK_draw_pal_horizontal_line(int x0, int x1, int y, SLK_Paxel paxel);
void SLK_draw_pal_rectangle(int x, int y, int width, int height, SLK_Paxel paxel);
void SLK_draw_pal_fill_rectangle(int x, int y, int width, int height, SLK_Paxel paxel);
//RGB sprite subsystem: SLK_sprite_rgb.c
SLK_RGB_sprite *SLK_rgb_sprite_create(const int width, const int height);
void SLK_rgb_sprite_destroy(SLK_RGB_sprite *s);
SLK_Color SLK_rgb_sprite_get_pixel(const SLK_RGB_sprite *s, const int x, const int y);
void SLK_rgb_sprite_set_pixel(SLK_RGB_sprite *s, const int x, const int y, const SLK_Color c);
SLK_RGB_sprite *SLK_rgb_sprite_load(const char *path);
void SLK_rgb_sprite_save(const char *path, const SLK_RGB_sprite *s);
//Draw rgb subsystem: SLK_draw_rgb.c
void SLK_draw_rgb_set_target(SLK_RGB_sprite *s);
void SLK_draw_rgb_set_clear_color(SLK_Color color);
void SLK_draw_rgb_clear();
void SLK_draw_rgb_color(int x, int y, SLK_Color color);
void SLK_draw_rgb_string(int x, int y, int scale, const char *text, SLK_Color color);
void SLK_draw_rgb_sprite(const SLK_RGB_sprite *s, int x, int y);
void SLK_draw_rgb_sprite_partial(const SLK_RGB_sprite *s, int x, int y, int ox, int oy, int width, int height);
void SLK_draw_rgb_circle(int x, int y, int radius, SLK_Color color);
void SLK_draw_rgb_horizontal_line(int x0, int x1, int y, SLK_Color color);
//Color subsystem: SLK_color.c
SLK_Color SLK_color_create(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SLK_Paxel SLK_color_create_paxel(uint8_t index, uint8_t mask);
//Input subsystem: SLK_input.c
int SLK_key_down(const int key);
int SLK_key_pressed(const int key);
int SLK_key_released(const int key);
int SLK_mouse_down(const int key);
int SLK_mouse_pressed(const int key);
int SLK_mouse_released(const int key);
void SLK_mouse_get_pos(int *x, int *y);
void SLK_text_input_start(char *text);
void SLK_text_input_stop();
//Layer subsystem: SLK_layer.c
void SLK_layer_create(const unsigned index, const int type);
void SLK_layer_activate(const unsigned index, const int active);
void SLK_layer_set_palette(const unsigned index, SLK_Palette *pal);
void SLK_layer_set_current(const unsigned index);
//Core subsystem: SLK_core.c
void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int pixel_scale);
void SLK_end();
void SLK_update();
void SLK_update_viewport();
void SLK_update_mouse(int x, int y);
void SLK_show_cursor(int shown);
int SLK_running();
void SLK_quit();
/*//SLK_draw functionality
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Paxel p);
void SLK_draw_sprite(const SLK_Sprite *s, const int x, const int y);
void SLK_draw_sprite_partial(SLK_Sprite *s, int x, int y, int ox, int oy, int width, int height);
@ -49,42 +123,6 @@ void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Paxel p);
void SLK_clear_screen();
//--------------------------------------------
//SLK_copy functionality
void SLK_copy_partial_sprite(SLK_Sprite *dst, SLK_Sprite *src, int x, int y, int ox, int oy, int width, int height);
//--------------------------------------------
//SLK_color functionality
SLK_Color SLK_create_color(uint8 r, uint8 g, uint8 b, uint8 a);
SLK_Paxel SLK_create_paxel(uint8_t index, uint8_t mask);
//--------------------------------------------
//SLK_input functionality
int SLK_key_down(int key);
int SLK_key_pressed(int key);
int SLK_key_released(int key);
int SLK_mouse_down(int key);
int SLK_mouse_pressed(int key);
int SLK_mouse_released(int key);
void SLK_get_mouse_pos(int *x, int *y);
void SLK_start_text_input(char *text);
void SLK_stop_text_input();
//--------------------------------------------
//SLK_core functionality
void SLK_set_clear_color(int index);
void SLK_setup(int width, int height, const char *title, int fullscreen, int pixel_scale);
void SLK_end();
void SLK_update();
void SLK_update_viewport();
void SLK_update_mouse(int x, int y);
void SLK_update_screen();
void SLK_set_FPS(int FPS);
void SLK_show_cursor(int shown);
int SLK_running();
void SLK_quit();
void SLK_set_draw_target(SLK_Sprite *new_target);
void SLK_start_timer();
void SLK_end_timer();
//--------------------------------------------
/--------------------------------------------*/
#endif //_SLK_FUNCTIONS_H_

View file

@ -1,5 +1,5 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -18,34 +18,24 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _4LK_TYPES_H_
#ifndef _SLK_TYPES_H_
#define _4LK_TYPES_H_
#define _SLK_TYPES_H_
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef float float32;
typedef double float64;
#include <stdint.h>
#include "../glad/glad.h"
typedef struct
{
union
{
uint32 n;
uint32_t n;
struct
{
uint8 r;
uint8 g;
uint8 b;
uint8 a;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
};
}SLK_Color;
@ -65,21 +55,60 @@ typedef struct
{
int width;
int height;
int changed;
SLK_Color *data;
}SLK_Sprite_rgb;
}SLK_RGB_sprite;
typedef struct
{
int width;
int height;
int changed;
SLK_Paxel *data;
}SLK_Sprite;
}SLK_Pal_sprite;
typedef struct
{
uint8 pressed;
uint8 released;
uint8 held;
GLint id;
}SLK_GPU_sprite;
typedef struct
{
SLK_Pal_sprite *target;
SLK_RGB_sprite *render;
SLK_Palette *palette;
GLuint texture;
}SLK_Layer_pal;
typedef struct
{
SLK_RGB_sprite *target;
GLuint texture;
}SLK_Layer_rgb;
typedef struct
{
}SLK_Layer_gpu;
typedef struct
{
int type;
int active;
union
{
SLK_Layer_pal type_0;
SLK_Layer_rgb type_1;
SLK_Layer_gpu type_2;
};
}SLK_Layer;
typedef struct
{
int pressed;
int released;
int held;
}SLK_Button;
enum SLK_key
@ -106,10 +135,27 @@ enum SLK_mouse_button
SLK_BUTTON_LEFT,SLK_BUTTON_RIGHT,SLK_BUTTON_MIDDLE,SLK_BUTTON_X1,SLK_BUTTON_X2,
};
enum SLK_layer
{
SLK_LAYER_PAL,SLK_LAYER_RGB,SLK_LAYER_GPU,
};
enum SLK_mask
{
SLK_OPAQUE = 0,
SLK_TRANSPARENT = 255,
};
#endif //_4LK_TYPES_H_
enum SLK_flip
{
SLK_FLIP_NONE = 0,
SLK_FLIP_VERTICAL = 1,
SLK_FLIP_HORIZONTAL = 2,
};
enum SLK_window_scale
{
SLK_WINDOW_MAX = -1,
};
#endif //_SLK_TYPES_H_

16768
include/glad/glad.h Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,16 +0,0 @@
CC = gcc
DEPS = $(wildcard ../include/SLK/*.h)
DEPS := $(wildcard ../src/*.h)
SRC = $(wildcard ../src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
%.o: ../src/%.c $(DEPS)
$(CC) -O2 -S $< -lm -lSDL2 -lGL -Wall
libSLK.a: $(OBJ)
ar cr libSLK.a *.o
clean:
rm -f *.o *.a

View file

@ -1,7 +1,7 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -c ../src/*.c -lm -lSDL2 -lGL -Wall -fvisibility=hidden
gcc -O3 -c ../src/*/*.c -lm -lSDL2 -ldl -lGL -Wall -fvisibility=hidden
ar cr libSLK.a *.o
exit

View file

@ -1,5 +0,0 @@
gcc --version
cd %~dp0
gcc -O3 -c ../src/*.c -static -static-libgcc -lmingw32 -lopengl32 -lz -lpng.dll -lSDL2main -lSDL2.dll -Wall
ar cr libSLK.a *.o
cmd /k

View file

@ -18,17 +18,24 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
#include "../../include/SLK/SLK.h"
void SLK_copy_partial_sprite(SLK_Sprite *dst, SLK_Sprite *src, int x, int y, int ox, int oy, int width, int height)
SLK_Color SLK_color_create(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Paxel c = SLK_get_paxel(src, tx + ox, ty + oy);
SLK_set_paxel(dst,x + tx, y +ty, c);
}
}
SLK_Color c;
c.r = r;
c.g = g;
c.b = b;
c.a = a;
return c;
}
SLK_Paxel SLK_color_create_paxel(uint8_t index, uint8_t mask)
{
SLK_Paxel p;
p.index = index;
p.mask = mask;
return p;
}

View file

@ -18,15 +18,9 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_set_FPS(int FPS)
{
FPS = FPS;
frame_delay = 1000/FPS;
}
void SLK_quit()
{
running = 0;
@ -37,72 +31,16 @@ int SLK_running()
return running;
}
void SLK_set_clear_color(int index)
{
clear_color = index;
}
void SLK_show_cursor(int shown)
{
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE);
}
SLK_Color SLK_create_color(uint8 r, uint8 g, uint8 b, uint8 a)
{
SLK_Color c;
c.r = r;
c.g = g;
c.b = b;
c.a = 0;
return c;
}
SLK_Paxel SLK_create_paxel(uint8_t index, uint8_t mask)
{
SLK_Paxel p;
p.index = index;
p.mask = mask;
return p;
}
void SLK_update_screen()
{
for(int i = 0;i<target->width*target->height;i++)
target->data[i] = palette.colors[default_draw_target->data[i].index];
glClear(GL_COLOR_BUFFER_BIT);
glViewport(view_x,view_y,view_width,view_height);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,screen_width,screen_height,GL_RGBA,GL_UNSIGNED_BYTE,target->data);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0f,1.0f,0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f,1.0f,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
//glFinish();
SDL_GL_SwapWindow(sdl_window);
}
void SLK_update()
{
frametime = SDL_GetTicks()-framestart;
if(frame_delay>frametime)
SDL_Delay(frame_delay-frametime);
gone_fps++;
framestart = SDL_GetTicks();
SLK_timer_update();
//Event managing, done
//Event managing
SDL_Event event;
while(SDL_PollEvent(&event))
{
@ -224,32 +162,43 @@ void SLK_update_mouse(int x, int y)
mouse_y_cache = 1;
}
void SLK_set_draw_target(SLK_Sprite *new_target)
{
if(new_target)
draw_target = new_target;
else
draw_target = default_draw_target;
}
void SLK_setup(int width, int height, const char *title, int fullscreen, int pixel_scale)
void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int pixel_scale)
{
screen_width = width;
screen_height = height;
layer_count = layer_num;
layers = malloc(sizeof(SLK_Layer)*layer_num);
memset(layers,0,sizeof(SLK_Layer)*layer_num);
font_sprite = SLK_load_sprite("data/font8x8.slk");
SLK_load_palette("data/palette.pal");
default_draw_target = SLK_create_sprite(screen_width,screen_height);
target = SLK_create_sprite_rgb(screen_width,screen_height);
SLK_set_draw_target(NULL);
if(SDL_Init(SDL_INIT_EVERYTHING)<0)
{
printf("FATAL ERROR: failed to init sdl\n");
exit(-1);
}
if(pixel_scale==SLK_WINDOW_MAX)
{
SDL_Rect max_size;
if(SDL_GetDisplayUsableBounds(0,&max_size)<0)
{
printf("Failed to get max dimensions: %s\n",SDL_GetError());
}
else
{
int max_x,max_y;
max_x = max_size.w/screen_width;
max_y = max_size.h/screen_height;
pixel_scale = (max_x>max_y)?max_y:max_x;
}
}
if(pixel_scale<=0)
pixel_scale = 1;
SDL_GL_LoadLibrary(NULL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,1);
@ -272,22 +221,13 @@ void SLK_setup(int width, int height, const char *title, int fullscreen, int pix
exit(-1);
}
SDL_GL_SetSwapInterval(0);
printf("OpenGL loaded\n");
printf("Vendor: %s\n",glGetString(GL_VENDOR));
printf("Renderer: %s\n",glGetString(GL_RENDERER));
printf("Version: %s\n",glGetString(GL_VERSION));
printf("SDL_GL_GetSwapInterval: %d\nErrors: %s\n",SDL_GL_GetSwapInterval(),SDL_GetError());
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
SDL_GetWindowSize(sdl_window,&window_width,&window_height);
glViewport(0,0,width,height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
SLK_update_viewport();
SLK_render_init();
text_sprite_pal = SLK_pal_sprite_load("data/font8x8.slk");
text_sprite_rgb = SLK_rgb_sprite_load("data/font8x8.png");
key_map[0x00] = SLK_KEY_NONE;
key_map[SDL_SCANCODE_A] = SLK_KEY_A;
@ -383,14 +323,6 @@ void SLK_setup(int width, int height, const char *title, int fullscreen, int pix
mouse_map[SDL_BUTTON_X1] = SLK_BUTTON_X1;
mouse_map[SDL_BUTTON_X2] = SLK_BUTTON_X2;
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&gl_buffer);
glBindTexture(GL_TEXTURE_2D,gl_buffer);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,
0,GL_RGB,GL_UNSIGNED_BYTE,target->data);
running = 1;
memset(new_key_state,0,sizeof(new_key_state));
memset(new_mouse_state,0,sizeof(new_mouse_state));
@ -401,14 +333,3 @@ void SLK_end()
{
}
void SLK_start_timer()
{
timer = clock();
}
void SLK_end_timer()
{
printf("Time: %lf\n",((double)(clock()-timer)/CLOCKS_PER_SEC));
}

307
src/SLK/SLK_draw_pal.c Normal file
View file

@ -0,0 +1,307 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_draw_pal_set_target(SLK_Pal_sprite *s)
{
if(s==NULL)
{
target_pal = target_pal_default;
return;
}
target_pal = s;
}
void SLK_draw_pal_set_clear_paxel(SLK_Paxel paxel)
{
target_pal_clear = paxel;
}
void SLK_draw_pal_clear()
{
for(int i = 0;i<target_pal->width*target_pal->height;i++)
target_pal->data[i] = target_pal_clear;
}
void SLK_draw_pal_paxel(int x, int y, SLK_Paxel paxel)
{
if(INBOUNDS(0,target_pal->width,x)&&INBOUNDS(0,target_pal->height,y))
{
int index = y*target_pal->width+x;
target_pal->data[index].index = (target_pal->data[index].index&paxel.mask)|paxel.index;
}
}
void SLK_draw_pal_string(int x, int y, int scale, const char *text, SLK_Paxel paxel)
{
int sx = 0;
int sy = 0;
for (int i = 0;text[i];i++)
{
if (text[i]=='\n')
{
sx = 0;
sy+=8*scale;
}
else
{
int ox = (text[i]-32) % 16;
int oy = (text[i]-32) / 16;
if(scale>1)
{
for(int x_ = 0;x_<8;x_++)
for(int y_ = 0;y_<8;y_++)
if(!text_sprite_pal->data[(y_+oy*8)*128+x_+ox*8].mask)
for(int is = 0;is<scale;is++)
for(int js = 0;js<scale;js++)
SLK_draw_pal_paxel(x+sx+(x_*scale)+is,y+sy+(y_*scale)+js,paxel);
}
else
{
for(int x_ = 0; x_ < 8; x_++)
for(int y_ = 0; y_ < 8; y_++)
if(!text_sprite_pal->data[(y_+oy*8)*128+x_+ox*8].mask)
SLK_draw_pal_paxel(x+sx+x_,y+sy+y_,paxel);
}
sx += 8*scale;
}
}
}
void SLK_draw_pal_sprite(const SLK_Pal_sprite *s, int x, int y)
{
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>target_pal->width)
draw_end_x = s->width+(target_pal->width-x-draw_end_x);
if(y+draw_end_y>target_pal->height)
draw_end_y = s->height+(target_pal->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+x1];
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
void SLK_draw_pal_sprite_partial(const SLK_Pal_sprite *s, int x, int y, int ox, int oy, int width, int height)
{
int draw_start_y = oy;
int draw_start_x = ox;
int draw_end_x = ox+width;
int draw_end_y = oy+height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>target_pal->width)
draw_end_x = s->width+(target_pal->width-x-draw_end_x);
if(y+draw_end_y>target_pal->height)
draw_end_y = s->height+(target_pal->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+x1];
int index = (y1+y-oy)*target_pal->width+x1+x-ox;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
void SLK_draw_pal_sprite_flip(const SLK_Pal_sprite *s, int x, int y, int flip)
{
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>target_pal->width)
draw_end_x = s->width+(target_pal->width-x-draw_end_x);
if(y+draw_end_y>target_pal->height)
draw_end_y = s->height+(target_pal->height-y-draw_end_y);
if(flip==SLK_FLIP_NONE)
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+x1];
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
else if(flip==SLK_FLIP_VERTICAL)
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[(s->height-y1)*s->width+x1];
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
else if(flip==SLK_FLIP_HORIZONTAL)
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+(s->width-x1)];
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
else if(flip==(SLK_FLIP_VERTICAL|SLK_FLIP_HORIZONTAL))
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[(s->height-y1)*s->width+(s->width-x1)];
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&p.mask)|p.index;
}
}
}
}
void SLK_draw_pal_line(int x0, int y0, int x1, int y1, SLK_Paxel paxel)
{
int changed = 0;
int x = x0;
int y = y0;
int dx = abs(x1-x0);
int dy = abs(y1-y0);
int sign_x = SIGNUM(x1-x0);
int sign_y = SIGNUM(y1-y0);
if(dy>dx)
{
SWAP(dx,dy);
changed = 1;
}
int error = 2*dy-dx;
for(int i = 1;i<=dx;i++)
{
SLK_draw_pal_paxel(x,y,paxel);
while(error>=0)
{
if(changed)
x+=1;
else
y+=1;
error-=2*dx;
}
if(changed)
y+=sign_y;
else
x+=sign_x;
error+=2*dy;
}
}
void SLK_draw_pal_vertical_line(int x, int y0, int y1, SLK_Paxel paxel)
{
for(int y = y0;y<y1;y++)
SLK_draw_pal_paxel(x,y,paxel);
}
void SLK_draw_pal_horizontal_line(int x0, int x1, int y, SLK_Paxel paxel)
{
for(int x = x0;x<x1;x++)
SLK_draw_pal_paxel(x,y,paxel);
}
void SLK_draw_pal_rectangle(int x, int y, int width, int height, SLK_Paxel paxel)
{
for(int y_ = y;y_<y+height;y_++)
{
SLK_draw_pal_paxel(x,y_,paxel);
SLK_draw_pal_paxel(x+width-1,y_,paxel);
}
for(int x_ = x;x_<x+width;x_++)
{
SLK_draw_pal_paxel(x_,y,paxel);
SLK_draw_pal_paxel(x_,y+height-1,paxel);
}
}
void SLK_draw_pal_fill_rectangle(int x, int y, int width, int height, SLK_Paxel paxel)
{
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = width;
int draw_end_y = height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>target_pal->width)
draw_end_x = width+(target_pal->width-x-draw_end_x);
if(y+draw_end_y>target_pal->height)
draw_end_y = height+(target_pal->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
int index = (y1+y)*target_pal->width+x1+x;
target_pal->data[index].index = (target_pal->data[index].index&paxel.mask)|paxel.index;
}
}
}

171
src/SLK/SLK_draw_rgb.c Normal file
View file

@ -0,0 +1,171 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the autors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_draw_rgb_set_target(SLK_RGB_sprite *s)
{
if(s==NULL)
{
target_rgb = target_rgb_default;
return;
}
target_rgb = s;
}
void SLK_draw_rgb_set_clear_color(SLK_Color color)
{
target_rgb_clear = color;
}
void SLK_draw_rgb_clear()
{
for(int i = 0;i<target_rgb->width*target_rgb->height;i++)
target_rgb->data[i] = target_rgb_clear;
}
void SLK_draw_rgb_color(int x, int y, SLK_Color color)
{
if(color.a&&INBOUNDS(0,target_rgb->width,x)&&INBOUNDS(0,target_rgb->height,y))
target_rgb->data[y*target_rgb->width+x] = color;
}
void SLK_draw_rgb_string(int x, int y, int scale, const char *text, SLK_Color color)
{
int sx = 0;
int sy = 0;
for (int i = 0;text[i];i++)
{
if (text[i]=='\n')
{
sx = 0;
sy+=8*scale;
}
else
{
int ox = (text[i]-32) % 16;
int oy = (text[i]-32) / 16;
if(scale>1)
{
for(int x_ = 0;x_<8;x_++)
for(int y_ = 0;y_<8;y_++)
if(!text_sprite_pal->data[(y_+oy*8)*128+x_+ox*8].mask)
for(int is = 0;is<scale;is++)
for(int js = 0;js<scale;js++)
SLK_draw_rgb_color(x+sx+(x_*scale)+is,y+sy+(y_*scale)+js,color);
}
else
{
for(int x_ = 0; x_ < 8; x_++)
for(int y_ = 0; y_ < 8; y_++)
if(!text_sprite_pal->data[(y_+oy*8)*128+x_+ox*8].mask)
SLK_draw_rgb_color(x+sx+x_,y+sy+y_,color);
}
sx += 8*scale;
}
}
}
void SLK_draw_rgb_sprite(const SLK_RGB_sprite *s, int x, int y)
{
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>target_pal->width)
draw_end_x = s->width+(target_pal->width-x-draw_end_x);
if(y+draw_end_y>target_pal->height)
draw_end_y = s->height+(target_pal->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Color c = s->data[y1*s->width+x1];
if(c.a)
target_rgb->data[(y1+y)*target_rgb->width+x1+x] = c;
}
}
}
void SLK_draw_rgb_sprite_partial(const SLK_RGB_sprite *s, int x, int y, int ox, int oy, int width, int height)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Color c = SLK_rgb_sprite_get_pixel(s, tx + ox, ty + oy);
SLK_draw_rgb_color(x + tx, y +ty, c);
}
}
}
void SLK_draw_rgb_circle(int x, int y, int radius, SLK_Color color)
{
int x_ = 0;
int y_ = radius;
int d = 1-radius;
while(x_<y_)
{
if(d<0)
{
d = d+2*x_+3;
x_+=1;
}
else
{
d = d+2*(x_-y_)+5;
x_+=1;
y_-=1;
}
SLK_draw_rgb_color(x+x_,y+y_,color);
SLK_draw_rgb_color(x+x_,y-y_,color);
SLK_draw_rgb_color(x-x_,y+y_,color);
SLK_draw_rgb_color(x-x_,y-y_,color);
SLK_draw_rgb_color(x+y_,y+x_,color);
SLK_draw_rgb_color(x+y_,y-x_,color);
SLK_draw_rgb_color(x-y_,y+x_,color);
SLK_draw_rgb_color(x-y_,y-x_,color);
SLK_draw_rgb_horizontal_line(x-x_,x+x_,y+y_,color);
SLK_draw_rgb_horizontal_line(x-x_,x+x_,y-y_,color);
SLK_draw_rgb_horizontal_line(x-y_,x+y_,y+x_,color);
SLK_draw_rgb_horizontal_line(x-y_,x+y_,y-x_,color);
SLK_draw_rgb_horizontal_line(x-radius,x+radius,y,color);
}
}
void SLK_draw_rgb_horizontal_line(int x0, int x1, int y, SLK_Color color)
{
for(int x = x0;x<x1;x++)
SLK_draw_rgb_color(x,y,color);
}

View file

@ -18,46 +18,46 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
int SLK_key_down(int key)
int SLK_key_down(const int key)
{
return keyboard_state[key].held;
}
int SLK_key_pressed(int key)
int SLK_key_pressed(const int key)
{
return keyboard_state[key].pressed;
}
int SLK_key_released(int key)
int SLK_key_released(const int key)
{
return keyboard_state[key].released;
}
int SLK_mouse_down(int key)
int SLK_mouse_down(const int key)
{
return mouse_state[key].held;
}
int SLK_mouse_pressed(int key)
int SLK_mouse_pressed(const int key)
{
return mouse_state[key].pressed;
}
int SLK_mouse_released(int key)
int SLK_mouse_released(const int key)
{
return mouse_state[key].released;
}
void SLK_get_mouse_pos(int *x, int *y)
void SLK_mouse_get_pos(int *x, int *y)
{
*x = mouse_x_cache;
*y = mouse_y_cache;
}
void SLK_start_text_input(char *text)
void SLK_text_input_start(char *text)
{
text_input = text;
text_input_active = 1;
@ -65,7 +65,7 @@ void SLK_start_text_input(char *text)
SDL_StartTextInput();
}
void SLK_stop_text_input()
void SLK_text_input_stop()
{
text_input_active = 0;

99
src/SLK/SLK_layer.c Normal file
View file

@ -0,0 +1,99 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_layer_create(const unsigned index, const int type)
{
if(index>=layer_count)
return;
layers[index].type = type;
layers[index].active = 1;
switch(type)
{
case SLK_LAYER_PAL:
layers[index].type_0.target = SLK_pal_sprite_create(screen_width,screen_height);
layers[index].type_0.render = SLK_rgb_sprite_create(screen_width,screen_height);
glGenTextures(1,&layers[index].type_0.texture);
glBindTexture(GL_TEXTURE_2D,layers[index].type_0.texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,
0,GL_RGBA,GL_UNSIGNED_BYTE,layers[index].type_0.render->data);
break;
case SLK_LAYER_RGB:
layers[index].type_1.target = SLK_rgb_sprite_create(screen_width,screen_height);
glGenTextures(1,&layers[index].type_1.texture);
glBindTexture(GL_TEXTURE_2D,layers[index].type_1.texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,
0,GL_RGBA,GL_UNSIGNED_BYTE,layers[index].type_1.target->data);
break;
case SLK_LAYER_GPU:
break;
}
}
void SLK_layer_activate(const unsigned index, const int active)
{
if(index>=layer_count)
return;
layers[index].active = active;
}
void SLK_layer_set_palette(const unsigned index, SLK_Palette *pal)
{
if(index>=layer_count||layers[index].type!=SLK_LAYER_PAL)
return;
layers[index].type_0.palette = pal;
}
void SLK_layer_set_current(const unsigned index)
{
if(index>=layer_count)
return;
current_layer = &layers[index];
if(layers[index].type==SLK_LAYER_PAL)
{
target_pal_default = layers[index].type_0.target;
target_pal = layers[index].type_0.target;
}
else if(layers[index].type==SLK_LAYER_RGB)
{
target_rgb_default = layers[index].type_1.target;
target_rgb = layers[index].type_1.target;
}
}

View file

@ -18,43 +18,48 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height)
{
SLK_Sprite_rgb *s = malloc(sizeof(SLK_Sprite_rgb));
if(s==NULL)
/*
* Loads a paltte from a .pal
* file.
* Support for other types
* is planned
*/
SLK_Palette *SLK_palette_load(const char *path)
{
SLK_Palette *palette = malloc(sizeof(SLK_Palette));
FILE *f = fopen(path,"r");
if(!f)
{
printf("Failed to allocate memory for Sprite\n");
exit(-1);
printf("Unable to load palette\n");
return palette;
}
s->width = width;
s->height = height;
char buffer[512];
int colors = 0;
s->data = malloc(width*height*sizeof(SLK_Color));
memset(s->data,0,width*height*sizeof(SLK_Color));
return s;
}
for(int i = 0;i<259&&fgets(buffer,512,f);i++)
{
if(i==2)
{
int found;
sscanf(buffer,"%d",&found);
printf("Found %d colors\n",found);
}
else if(i>2)
{
int r,g,b,a;
sscanf(buffer,"%d %d %d %d",&r,&g,&b,&a);
palette->colors[colors].r = r;
palette->colors[colors].g = g;
palette->colors[colors].b = b;
palette->colors[colors].a = a;
colors++;
}
}
void SLK_destroy_sprite_rgb(SLK_Sprite_rgb *s)
{
free(s->data);
free(s);
}
SLK_Color SLK_get_pixel_rgb(SLK_Sprite_rgb *s, int x, int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
else
return SLK_create_color(0,0,0,0);
}
void SLK_set_pixel_rgb(SLK_Sprite_rgb *s, int x, int y, SLK_Color c)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
return palette;
}

95
src/SLK/SLK_render.c Normal file
View file

@ -0,0 +1,95 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "../../include/SLK/SLK_functions.h"
#include "SLK_variables.h"
void SLK_render_init()
{
printf("OpenGL loaded\n");
gladLoadGLLoader(SDL_GL_GetProcAddress);
printf("Vendor: %s\n",glGetString(GL_VENDOR));
printf("Renderer: %s\n",glGetString(GL_RENDERER));
printf("Version: %s\n",glGetString(GL_VERSION));
//glDisable(GL_DEPTH_TEST);
//glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glViewport(0,0,screen_width,screen_height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void SLK_render_update()
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(view_x,view_y,view_width,view_height);
for(int l = layer_count-1;l>=0;l--)
{
if(layers[l].active)
{
switch(layers[l].type)
{
case SLK_LAYER_PAL:
for(int i = 0;i<layers[l].type_0.render->width*layers[l].type_0.render->height;i++)
layers[l].type_0.render->data[i] = layers[l].type_0.palette->colors[layers[l].type_0.target->data[i].index];
glBindTexture(GL_TEXTURE_2D,layers[l].type_0.texture);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_0.render->data);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0f,1.0f,0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f,1.0f,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
break;
case SLK_LAYER_RGB:
glBindTexture(GL_TEXTURE_2D,layers[l].type_1.texture);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_1.target->data);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0f,1.0f,0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f,1.0f,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
break;
}
}
}
SDL_GL_SwapWindow(sdl_window);
}

135
src/SLK/SLK_sprite_pal.c Normal file
View file

@ -0,0 +1,135 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "SLK_variables.h"
/*
* Creates a sprite with the requested dimensions
* and returns a pointer to its location
*/
SLK_Pal_sprite *SLK_pal_sprite_create(const int width, const int height)
{
SLK_Pal_sprite *s = malloc(sizeof(SLK_Pal_sprite));
s->width = width;
s->height = height;
s->data = malloc(width*height*sizeof(SLK_Paxel));
memset(s->data,0,sizeof(SLK_Paxel)*width*height);
return s;
}
/*
* Destroys a previously allocated sprite.
* The user may not now that s->data also
* needs to be freed
*/
void SLK_pal_sprite_destroy(SLK_Pal_sprite *s)
{
free(s->data);
free(s);
}
/*
* Returns the paxel at the specified
* location.
* The paxel layout may change in
* the future
*/
SLK_Paxel SLK_pal_sprite_get_paxel(const SLK_Pal_sprite *s, const int x, const int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
else
return (SLK_Paxel){0,0};
}
/*
* Sets the paxel at the specified
* position.
* Again, the paxel layout may change
* in the future
*/
void SLK_pal_sprite_set_paxel(SLK_Pal_sprite *s, const int x, const int y, const SLK_Paxel c)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
}
/*
* Loads a sprite from a .slk file.
* Current layout:
* int width,
* int height,
* width*height*SLK_Paxel data
*/
SLK_Pal_sprite *SLK_pal_sprite_load(const char *path)
{
FILE *f = fopen(path,"rb");
if(!f)
return SLK_pal_sprite_create(1,1);
int width, height;
fread(&width,sizeof(int),1,f);
fread(&height,sizeof(int),1,f);
SLK_Pal_sprite *s = SLK_pal_sprite_create(width,height);
fread(s->data,sizeof(SLK_Paxel),width*height,f);
fclose(f);
return s;
}
/*
* Saves a sprite to a file
* with the above specified
* layout
*/
void SLK_pal_sprite_save(const char *path, const SLK_Pal_sprite *s)
{
FILE *f = fopen(path,"wb");
if(!f)
return;
fwrite(&s->width,sizeof(int),1,f);
fwrite(&s->height,sizeof(int),1,f);
fwrite(s->data,sizeof(SLK_Paxel),s->width*s->height,f);
fclose(f);
}
void SLK_pal_sprite_copy_partial(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src, const int x, const int y, const int ox, const int oy, const int width, const int height)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Paxel c = SLK_pal_sprite_get_paxel(src, tx + ox, ty + oy);
SLK_pal_sprite_set_paxel(dst,x + tx, y +ty, c);
}
}
}
void SLK_pal_sprite_copy(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src)
{
for(int x = 0;x<src->width;x++)
for(int y = 0;y<src->height;y++)
SLK_pal_sprite_set_paxel(dst,x,y,SLK_pal_sprite_get_paxel(src,x,y));
}

89
src/SLK/SLK_sprite_rgb.c Normal file
View file

@ -0,0 +1,89 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../include/SLK/SLK.h"
#include "../../include/SLK/SLK_functions.h"
#include "SLK_variables.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
//https://github.com/nothings/stb
SLK_RGB_sprite *SLK_rgb_sprite_create(const int width, const int height)
{
SLK_RGB_sprite *s = malloc(sizeof(SLK_RGB_sprite));
s->width = width;
s->height = height;
s->data = malloc(width*height*sizeof(SLK_Color));
memset(s->data,0,width*height*sizeof(SLK_Color));
return s;
}
void SLK_rgb_sprite_destroy(SLK_RGB_sprite *s)
{
free(s->data);
free(s);
}
SLK_Color SLK_rgb_sprite_get_pixel(const SLK_RGB_sprite *s, const int x, const int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
else
return SLK_color_create(0,0,0,0);
}
void SLK_rgb_sprite_set_pixel(SLK_RGB_sprite *s, const int x, const int y, const SLK_Color c)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
}
SLK_RGB_sprite *SLK_rgb_sprite_load(const char *path)
{
unsigned char *data = NULL;
int width = 1;
int height = 1;
SLK_RGB_sprite *out;
data = stbi_load(path,&width,&height,NULL,4);
if(data==NULL)
{
printf("Unable to load %s\n",path);
return SLK_rgb_sprite_create(1,1);
}
out = SLK_rgb_sprite_create(width,height);
memcpy(out->data,data,width*height*sizeof(SLK_Color));
stbi_image_free(data);
return out;
}
void SLK_rgb_sprite_save(const char *path, const SLK_RGB_sprite *s)
{
stbi_write_png(path,s->width,s->height,4,(void *)s->data,s->width*sizeof(SLK_Color));
}

View file

@ -1,5 +1,5 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -18,35 +18,35 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
#include "../../include/SLK/SLK.h"
SLK_Sprite *SLK_create_sprite(int width, int height)
{
SLK_Sprite *s = malloc(sizeof(SLK_Sprite));
s->width = width;
s->height = height;
s->data = malloc(width*height*sizeof(SLK_Paxel));
return s;
}
int fps;
int frametime;
int framedelay;
int framestart;
float delta;
void SLK_destroy_sprite(SLK_Sprite *s)
void SLK_timer_set_fps(const int FPS)
{
free(s->data);
free(s);
}
SLK_Paxel SLK_get_paxel(SLK_Sprite *s, int x, int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
if(FPS<1||FPS>1000)
fps = 1000;
else
return (SLK_Paxel){0,0};
fps = FPS;
framedelay = 1000/FPS;
}
void SLK_set_paxel(SLK_Sprite *s, int x, int y, SLK_Paxel c)
void SLK_timer_update()
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
frametime = SDL_GetTicks()-framestart;
if(framedelay>frametime)
SDL_Delay(framedelay-frametime);
delta = (float)(SDL_GetTicks()-framestart)/1000.0f;
framestart = SDL_GetTicks();
}
float SLK_timer_get_delta()
{
return delta;
}

View file

@ -22,15 +22,17 @@
#define _SLK_VARIABLES_H_
SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height);
void SLK_destroy_sprite_rgb(SLK_Sprite_rgb *s);
SLK_Color SLK_get_pixel_rgb(SLK_Sprite_rgb *s, int x, int y);
void SLK_set_pixel_rgb(SLK_Sprite_rgb *s, int x, int y, SLK_Color c);
#include <SDL2/SDL.h>
#include "../../include/SLK/SLK_types.h"
SLK_Sprite *draw_target;
SLK_Sprite *default_draw_target;
SLK_Sprite_rgb *target;
int clear_color;
SLK_Pal_sprite *target_pal;
SLK_Pal_sprite *target_pal_default;
SLK_Paxel target_pal_clear;
SLK_Pal_sprite *text_sprite_pal;
SLK_RGB_sprite *target_rgb;
SLK_RGB_sprite *target_rgb_default;
SLK_Color target_rgb_clear;
SLK_RGB_sprite *text_sprite_rgb;
int screen_width;
int screen_height;
@ -42,37 +44,26 @@ int view_width;
int view_height;
int running;
int layer_count;
SLK_Layer *layers;
SLK_Layer *current_layer;
int mouse_x_cache;
int mouse_y_cache;
uint8 new_key_state[256];
uint8 old_key_state[256];
uint8_t new_key_state[256];
uint8_t old_key_state[256];
SLK_Button keyboard_state[256];
uint8 new_mouse_state[6];
uint8 old_mouse_state[6];
uint8_t new_mouse_state[6];
uint8_t old_mouse_state[6];
SLK_Button mouse_state[6];
uint8 key_map[SDL_NUM_SCANCODES];
uint8 mouse_map[6];
uint8_t key_map[SDL_NUM_SCANCODES];
uint8_t mouse_map[6];
SDL_Window *sdl_window;
SDL_GLContext sdl_gl_context;
GLuint gl_buffer;
int frametime;
Uint32 framestart;
int FPS;
int frame_delay;
uint8 gone_fps;
char *text_input;
int text_input_active;
void load_font_sprite();
SLK_Sprite *font_sprite;
SLK_Palette palette;
clock_t timer;
#endif

7656
src/SLK/stb_image.h Normal file

File diff suppressed because it is too large Load diff

1666
src/SLK/stb_image_write.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,233 +0,0 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_clear_screen()
{
for(int b = 0;b<draw_target->width*draw_target->height;b++)
{
draw_target->data[b].index = clear_color;
draw_target->data[b].mask = SLK_OPAQUE;
}
}
void SLK_draw_rectangle(int x, int y, int width, int height, SLK_Paxel p)
{
width--;
height--;
for(int dx = 0;dx<width+1;dx++)
{
SLK_draw(dx+x,y,p);
SLK_draw(dx+x,y+height,p);
}
for(int dy = 0;dy<height+1;dy++)
{
SLK_draw(x,y+dy,p);
SLK_draw(x+width,y+dy,p);
}
}
void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Paxel p)
{
for(int x_ = x;x_<x+width;x_++)
for(int y_ = y;y_<y+height;y_++)
SLK_draw(x_,y_,p);
}
void SLK_draw(int x, int y, SLK_Paxel p)
{
if(INBOUNDS(0,draw_target->width,x)&&INBOUNDS(0,draw_target->height,y))
draw_target->data[y*draw_target->width+x].index = (draw_target->data[y*draw_target->width+x].index&p.mask)|p.index;
}
void SLK_draw_nc(int x, int y, SLK_Paxel p)
{
draw_target->data[y*draw_target->width+x].index = (draw_target->data[y*draw_target->width+x].index&p.mask)|p.index;
}
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Paxel p)
{
int32 sx = 0;
int32 sy = 0;
for (int i = 0;text[i];i++)
{
if (text[i]=='\n')
{
sx = 0;
sy+=8*scale;
}
else
{
int32 ox = (text[i]-32) % 16;
int32 oy = (text[i]-32) / 16;
if(scale>1)
{
for(uint32 x_ = 0;x_<8;x_++)
for(uint32 y_ = 0;y_<8;y_++)
if(!font_sprite->data[(y_+oy*8)*128+x_+ox*8].mask)
for(uint32 is = 0;is<scale;is++)
for(uint32 js = 0;js<scale;js++)
SLK_draw(x+sx+(x_*scale)+is,y+sy+(y_*scale)+js,p);
}
else
{
for(uint32 x_ = 0; x_ < 8; x_++)
for(uint32 y_ = 0; y_ < 8; y_++)
if(!font_sprite->data[(y_+oy*8)*128+x_+ox*8].mask)
SLK_draw(x+sx+x_,y+sy+y_,p);
}
sx += 8*scale;
}
}
}
void SLK_draw_sprite_partial(SLK_Sprite *s, int x, int y, int ox, int oy, int width, int height)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Paxel p = SLK_get_paxel(s, tx + ox, ty + oy);
SLK_draw(x+ tx,y+ty,p);
}
}
}
void SLK_draw_sprite(const SLK_Sprite *s, const int x, const int y)
{
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>draw_target->width)
draw_end_x = s->width+(draw_target->width-x-draw_end_x);
if(y+draw_end_y>draw_target->height)
draw_end_y = s->height+(draw_target->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+x1];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
void SLK_draw_sprite_flip(const SLK_Sprite *s, const int x, const int y, const int flip)
{
SLK_Paxel p;
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>draw_target->width)
draw_end_x = s->width+(draw_target->width-x-draw_end_x);
if(y+draw_end_y>draw_target->height)
draw_end_y = s->height+(draw_target->height-y-draw_end_y);
if(flip)
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
p = s->data[y1*s->width+(s->width-x1-1)];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
else
{
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
p = s->data[y1*s->width+x1];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
}
void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Paxel p)
{
int changed = 0;
int x = x1;
int y = y1;
int dx = abs(x2-x1);
int dy = abs(y2-y1);
int sign_x = SIGNUM(x2-x1);
int sign_y = SIGNUM(y2-y1);
if(dy>dx)
{
SWAP(dx,dy);
changed = 1;
}
int error = 2*dy-dx;
for(int i = 1;i<=dx;i++)
{
SLK_draw(x,y,p);
while(error>=0)
{
if(changed)
x+=1;
else
y+=1;
error-=2*dx;
}
if(changed)
y+=sign_y;
else
x+=sign_x;
error+=2*dy;
}
}
void SLK_draw_vertical_line(int x, int y1, int y2, SLK_Paxel p)
{
for(int y = y1;y<y1+1;y++)
{
draw_target->data[(y)*draw_target->width+x].index = (draw_target->data[(y)*draw_target->width+x].index&p.mask)|p.index;
}
}

View file

@ -1,200 +0,0 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
/*SLK_Sprite_rgb *SLK_load_sprite_rgb(const char *path)
{
SLK_Sprite_rgb *s = NULL;
int width,height;
png_structp png;
png_infop info;
FILE *f = fopen(path,"rb");
png = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
info = png_create_info_struct(png);
png_init_io(png,f);
png_read_info(png,info);
png_byte color_type;
png_byte bit_depth;
png_bytep *row_pointers;
width = png_get_image_width(png,info);
height = png_get_image_height(png,info);
color_type = png_get_color_type(png,info);
bit_depth = png_get_bit_depth(png,info);
if(bit_depth==16)
png_set_strip_16(png);
if(color_type==PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png);
if(color_type==PNG_COLOR_TYPE_GRAY&&bit_depth<8)
png_set_expand_gray_1_2_4_to_8(png);
if(png_get_valid(png,info,PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
if(color_type==PNG_COLOR_TYPE_RGB||
color_type==PNG_COLOR_TYPE_GRAY||
color_type==PNG_COLOR_TYPE_PALETTE)
png_set_filler(png,0xFF,PNG_FILLER_AFTER);
if(color_type==PNG_COLOR_TYPE_GRAY||
color_type==PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
png_read_update_info(png,info);
row_pointers = (png_bytep*)malloc(sizeof(png_bytep)*height);
for(int y = 0;y<height;y++)
{
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info));
}
png_read_image(png,row_pointers);
s = SLK_create_sprite_rgb(width,height);
for(int y = 0; y < height; y++)
{
png_bytep row = row_pointers[y];
for (int x = 0; x<width; x++)
{
png_bytep px = &(row[x * 4]);
s->data[y*s->width+x] = SLK_create_color(px[0],px[1],px[2],px[3]);
}
}
for(int y = 0;y<height;y++)
free(row_pointers[y]);
free(row_pointers);
fclose(f);
return s;
}
void SLK_save_sprite_rgb(const char *path, SLK_Sprite_rgb *s)
{
FILE *f;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
png_byte **row_pointers = NULL;
int pixel_size = 4;
int depth = 8;
f = fopen(path,"wb");
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
info_ptr = png_create_info_struct(png_ptr);
png_set_IHDR (png_ptr,
info_ptr,
s->width,
s->height,
depth,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
row_pointers = png_malloc(png_ptr,s->height*sizeof(SLK_Color*));
for(int y = 0;y<s->height;y++)
{
png_byte *row = png_malloc(png_ptr,sizeof(uint8_t)*s->width*pixel_size);
row_pointers[y] = row;
for (int x = 0;x<s->width;x++)
{
SLK_Color pixel = SLK_get_pixel_rgb(s,x,y);
*row++ = pixel.r;
*row++ = pixel.g;
*row++ = pixel.b;
*row++ = pixel.a;
}
}
png_init_io (png_ptr,f);
png_set_rows (png_ptr,info_ptr,row_pointers);
png_write_png (png_ptr,info_ptr,PNG_TRANSFORM_IDENTITY,NULL);
for (int y = 0;y<s->height;y++)
{
png_free(png_ptr,row_pointers[y]);
}
png_free (png_ptr, row_pointers);
fclose(f);
}*/
SLK_Sprite *SLK_load_sprite(const char *path)
{
FILE *f = fopen(path,"rb");
if(!f)
return SLK_create_sprite(1,1);
int width, height;
fread(&width,sizeof(int),1,f);
fread(&height,sizeof(int),1,f);
SLK_Sprite *s = SLK_create_sprite(width,height);
fread(s->data,sizeof(SLK_Paxel),width*height,f);
fclose(f);
return s;
}
void SLK_save_sprite(const char *path, SLK_Sprite *s)
{
FILE *f = fopen(path,"wb");
if(!f)
return;
fwrite(&s->width,sizeof(int),1,f);
fwrite(&s->height,sizeof(int),1,f);
fwrite(s->data,sizeof(SLK_Paxel),s->width*s->height,f);
fclose(f);
}
void SLK_load_palette(const char *path)
{
FILE *f = fopen(path,"r");
if(!f)
{
printf("Unable to load palette\n");
return;
}
char buffer[512];
int colors = 0;
for(int i = 0;i<259&&fgets(buffer,512,f);i++)
{
if(i==2)
{
int found;
sscanf(buffer,"%d",&found);
printf("Found %d colors\n",found);
}
else if(i>2)
{
int r,g,b;
sscanf(buffer,"%d %d %d",&r,&g,&b);
palette.colors[colors].r = r;
palette.colors[colors].g = g;
palette.colors[colors].b = b;
palette.colors[colors].a = 255;
colors++;
}
}
}

9382
src/glad/glad.c Normal file

File diff suppressed because one or more lines are too long