# HG changeset patch # User John Tsiombikas # Date 1443066565 -10800 # Node ID a3c4fcc9f8f39238d7872a87e4ad96fc71042fdd # Parent 3bccfc7d10fe1e08f5f8eae7e5634a30ee46b7bf - started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually) diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 .hgignore --- a/.hgignore Wed Sep 23 05:44:58 2015 +0300 +++ b/.hgignore Thu Sep 24 06:49:25 2015 +0300 @@ -8,3 +8,4 @@ ^build/ \.png$ ^data/ +\.DS_Store diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 istereo.xcodeproj/project.pbxproj --- a/istereo.xcodeproj/project.pbxproj Wed Sep 23 05:44:58 2015 +0300 +++ b/istereo.xcodeproj/project.pbxproj Thu Sep 24 06:49:25 2015 +0300 @@ -22,6 +22,14 @@ 060ECAF31BB2441600CE9B80 /* color.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF21BB2441600CE9B80 /* color.p.glsl */; settings = {ASSET_TAGS = (); }; }; 060ECAF61BB2496100CE9B80 /* ui.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF41BB2496100CE9B80 /* ui.p.glsl */; settings = {ASSET_TAGS = (); }; }; 060ECAF71BB2496100CE9B80 /* ui.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF51BB2496100CE9B80 /* ui.v.glsl */; settings = {ASSET_TAGS = (); }; }; + 060ECAFE1BB2BD5C00CE9B80 /* drawgl.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAF91BB2BD5C00CE9B80 /* drawgl.c */; settings = {ASSET_TAGS = (); }; }; + 060ECAFF1BB2BD5C00CE9B80 /* font.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAFC1BB2BD5C00CE9B80 /* font.c */; settings = {ASSET_TAGS = (); }; }; + 060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAFD1BB2BD5C00CE9B80 /* utf8.c */; settings = {ASSET_TAGS = (); }; }; + 060ECB031BB361C300CE9B80 /* assman.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB011BB361C300CE9B80 /* assman.c */; settings = {ASSET_TAGS = (); }; }; + 060ECB051BB361D900CE9B80 /* assman.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB041BB361D900CE9B80 /* assman.c */; settings = {ASSET_TAGS = (); }; }; + 060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */; settings = {ASSET_TAGS = (); }; }; + 060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB081BB3989500CE9B80 /* uitheme.cc */; settings = {ASSET_TAGS = (); }; }; + 060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */; settings = {ASSET_TAGS = (); }; }; 0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; }; 0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; }; 0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; }; @@ -161,6 +169,17 @@ 060ECAF21BB2441600CE9B80 /* color.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = color.p.glsl; path = sdr/color.p.glsl; sourceTree = ""; }; 060ECAF41BB2496100CE9B80 /* ui.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.p.glsl; path = sdr/ui.p.glsl; sourceTree = ""; }; 060ECAF51BB2496100CE9B80 /* ui.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.v.glsl; path = sdr/ui.v.glsl; sourceTree = ""; }; + 060ECAF91BB2BD5C00CE9B80 /* drawgl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = drawgl.c; path = libs/drawtext/drawgl.c; sourceTree = ""; }; + 060ECAFA1BB2BD5C00CE9B80 /* drawtext_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = drawtext_impl.h; path = libs/drawtext/drawtext_impl.h; sourceTree = ""; }; + 060ECAFB1BB2BD5C00CE9B80 /* drawtext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = drawtext.h; path = libs/drawtext/drawtext.h; sourceTree = ""; }; + 060ECAFC1BB2BD5C00CE9B80 /* font.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = font.c; path = libs/drawtext/font.c; sourceTree = ""; }; + 060ECAFD1BB2BD5C00CE9B80 /* utf8.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = utf8.c; path = libs/drawtext/utf8.c; sourceTree = ""; }; + 060ECB011BB361C300CE9B80 /* assman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = assman.c; path = src/assman.c; sourceTree = ""; }; + 060ECB021BB361C300CE9B80 /* assman.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = assman.h; path = src/assman.h; sourceTree = ""; }; + 060ECB041BB361D900CE9B80 /* assman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = assman.c; path = src/ios/assman.c; sourceTree = ""; }; + 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "linux-libertine_s24.glyphmap"; path = "data/linux-libertine_s24.glyphmap"; sourceTree = ""; }; + 060ECB081BB3989500CE9B80 /* uitheme.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = uitheme.cc; path = src/uitheme.cc; sourceTree = ""; }; + 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = font.p.glsl; path = sdr/font.p.glsl; sourceTree = ""; }; 0669D6471BA851BE00611CFA /* istereo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = istereo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0669D6741BA858BF00611CFA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = ""; }; 0669D67A1BA85DDE00611CFA /* app_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_delegate.h; path = src/ios/app_delegate.h; sourceTree = ""; }; @@ -364,6 +383,18 @@ name = goatkit; sourceTree = ""; }; + 060ECAF81BB2BD4B00CE9B80 /* drawtext */ = { + isa = PBXGroup; + children = ( + 060ECAF91BB2BD5C00CE9B80 /* drawgl.c */, + 060ECAFA1BB2BD5C00CE9B80 /* drawtext_impl.h */, + 060ECAFB1BB2BD5C00CE9B80 /* drawtext.h */, + 060ECAFC1BB2BD5C00CE9B80 /* font.c */, + 060ECAFD1BB2BD5C00CE9B80 /* utf8.c */, + ); + name = drawtext; + sourceTree = ""; + }; 0669D63E1BA851BE00611CFA = { isa = PBXGroup; children = ( @@ -388,7 +419,10 @@ 0669D6761BA858D600611CFA /* src */ = { isa = PBXGroup; children = ( + 060ECB011BB361C300CE9B80 /* assman.c */, + 060ECB021BB361C300CE9B80 /* assman.h */, 060ECAED1BB22A4400CE9B80 /* ui.cc */, + 060ECB081BB3989500CE9B80 /* uitheme.cc */, 060ECAEE1BB22A4400CE9B80 /* ui.h */, 0669D6821BACDF6C00611CFA /* cam.c */, 0669D6831BACDF6C00611CFA /* cam.h */, @@ -412,6 +446,7 @@ 0669D6791BA85DCC00611CFA /* ios */ = { isa = PBXGroup; children = ( + 060ECB041BB361D900CE9B80 /* assman.c */, 0669D67A1BA85DDE00611CFA /* app_delegate.h */, 0669D67B1BA85DDE00611CFA /* app_delegate.m */, 0669D67C1BA85DDE00611CFA /* main.m */, @@ -424,6 +459,7 @@ 0669D6971BAD01C200611CFA /* libs */ = { isa = PBXGroup; children = ( + 060ECAF81BB2BD4B00CE9B80 /* drawtext */, 060ECAC81BB1A9BA00CE9B80 /* goatkit */, 0669D69C1BAD01EA00611CFA /* vmath */, 0669D69B1BAD01E300611CFA /* imago2 */, @@ -601,6 +637,7 @@ 0669D77B1BAD028300611CFA /* sdr */ = { isa = PBXGroup; children = ( + 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */, 060ECAF41BB2496100CE9B80 /* ui.p.glsl */, 060ECAF51BB2496100CE9B80 /* ui.v.glsl */, 0669D77C1BAD02A200611CFA /* test.p.glsl */, @@ -618,6 +655,7 @@ 0669D7881BAD02B000611CFA /* data */ = { isa = PBXGroup; children = ( + 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */, 0669D7891BAD02DC00611CFA /* stonewall_normal.jpg */, 0669D78A1BAD02DC00611CFA /* stonewall.jpg */, 0669D78B1BAD02DC00611CFA /* text.png */, @@ -697,8 +735,10 @@ 0669D7901BAD02DC00611CFA /* tiles.jpg in Resources */, 0669D7871BAD02A200611CFA /* tunnel.v.glsl in Resources */, 0669D78F1BAD02DC00611CFA /* text.png in Resources */, + 060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */, 0669D7851BAD02A200611CFA /* text.v.glsl in Resources */, 0669D7831BAD02A200611CFA /* test.v.glsl in Resources */, + 060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -709,6 +749,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */, 0669D7121BAD024700611CFA /* jcparam.c in Sources */, 0669D7551BAD025B00611CFA /* pngwio.c in Sources */, 0669D70F1BAD024700611CFA /* jcmarker.c in Sources */, @@ -729,6 +770,7 @@ 0669D6B81BAD020B00611CFA /* ray_c.c in Sources */, 0669D71D1BAD024700611CFA /* jddctmgr.c in Sources */, 0669D7571BAD025B00611CFA /* pngwtran.c in Sources */, + 060ECB051BB361D900CE9B80 /* assman.c in Sources */, 0669D7081BAD024700611CFA /* jcapistd.c in Sources */, 0669D72C1BAD024700611CFA /* jidctflt.c in Sources */, 060ECADB1BB1A9CC00CE9B80 /* textbox.cc in Sources */, @@ -739,6 +781,7 @@ 0669D7281BAD024700611CFA /* jerror.c in Sources */, 0669D7221BAD024700611CFA /* jdmaster.c in Sources */, 0669D76F1BAD027000611CFA /* adler32.c in Sources */, + 060ECAFF1BB2BD5C00CE9B80 /* font.c in Sources */, 0669D7541BAD025B00611CFA /* pngvcrd.c in Sources */, 0669D72A1BAD024700611CFA /* jfdctfst.c in Sources */, 0669D7791BAD027000611CFA /* uncompr.c in Sources */, @@ -765,7 +808,9 @@ 0669D71F1BAD024700611CFA /* jdinput.c in Sources */, 0669D7581BAD025B00611CFA /* pngwutil.c in Sources */, 0669D7261BAD024700611CFA /* jdsample.c in Sources */, + 060ECAFE1BB2BD5C00CE9B80 /* drawgl.c in Sources */, 0669D7701BAD027000611CFA /* compress.c in Sources */, + 060ECB031BB361C300CE9B80 /* assman.c in Sources */, 0669D7111BAD024700611CFA /* jcomapi.c in Sources */, 0669D71A1BAD024700611CFA /* jdatasrc.c in Sources */, 060ECADC1BB1A9CC00CE9B80 /* theme.cc in Sources */, @@ -803,6 +848,7 @@ 0669D7751BAD027000611CFA /* inffast.c in Sources */, 0669D7491BAD025B00611CFA /* pngerror.c in Sources */, 0669D7171BAD024700611CFA /* jdapimin.c in Sources */, + 060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */, 0669D7331BAD024700611CFA /* jquant2.c in Sources */, 0669D74D1BAD025B00611CFA /* pngpread.c in Sources */, 0669D7071BAD024700611CFA /* jcapimin.c in Sources */, @@ -915,6 +961,8 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", HAVE_OPENGL_H, + HAVE_CONFIG_H, + NO_FREETYPE, ); HEADER_SEARCH_PATHS = libs; INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist"; @@ -931,7 +979,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; - GCC_PREPROCESSOR_DEFINITIONS = HAVE_OPENGL_H; + GCC_PREPROCESSOR_DEFINITIONS = ( + HAVE_OPENGL_H, + HAVE_CONFIG_H, + NO_FREETYPE, + ); HEADER_SEARCH_PATHS = libs; INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 6.0; diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/COPYING --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/COPYING Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + + 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 +. diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/COPYING.LESSER --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/COPYING.LESSER Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser 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 +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/README Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,19 @@ +libdrawtext - 0.2.1 +------------------- + +Libdrawtext is a simple library for fast anti-aliased text rendering in OpenGL. + +Copyright (C) 2011-2014 John Tsiombikas +You may freely use, modify and/or redistribute libdrawtext, under the terms of +the GNU Lesser General Public License (LGPL) version 3 (or at your option, any +later version published by the Free Software Foundation). See COPYING, and +COPYING.LESSER for details. + +website: http://nuclear.mutantstargoat.com/sw/libdrawtext + +master repository (hg): http://nuclear.mutantstargoat.com/hg/libdrawtext +mirror repository (git): https://github.com/jtsiomb/libdrawtext.git + +Feel free to send in bug reports, patches, and other comments to +nuclear@member.fsf.org +Only plain text email messages, hard-wrapped at 72 columns will be accepted. diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/drawgl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/drawgl.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,306 @@ +/* +libdrawtext - a simple library for fast text rendering in OpenGL +Copyright (C) 2011-2012 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef NO_OPENGL +#include +#include +#include + +#include + +#ifndef _MSC_VER +#include +#else +#include +#endif + +#ifdef TARGET_IPHONE +#include +#define GL_ES +#elif defined(ANDROID) +#include +#define GL_ES +#else +#include +#endif + +#include "drawtext.h" +#include "drawtext_impl.h" + +struct vertex { + float x, y; + float s, t; +}; + +struct quad { + struct vertex v[6]; +}; + +static void cleanup(void); +static void add_glyph(struct glyph *g, float x, float y); + +#define QBUF_SZ 512 +static struct quad *qbuf; +static int num_quads; +static int vattr = -1; +static int tattr = -1; +static unsigned int font_tex; +static int buf_mode = DTX_NBF; + + +int dtx_gl_init(void) +{ + if(qbuf) { + return 0; /* already initialized */ + } + +#ifdef __glew_h__ + glewInit(); +#endif + + if(!(qbuf = malloc(QBUF_SZ * sizeof *qbuf))) { + return -1; + } + num_quads = 0; + + atexit(cleanup); + return 0; +} + +static void cleanup(void) +{ + free(qbuf); +} + + +void dtx_vertex_attribs(int vert_attr, int tex_attr) +{ + vattr = vert_attr; + tattr = tex_attr; +} + +static void set_glyphmap_texture(struct dtx_glyphmap *gmap) +{ + if(!gmap->tex) { + glGenTextures(1, &gmap->tex); + glBindTexture(GL_TEXTURE_2D, gmap->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + +#ifdef GL_ES + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, gmap->xsz, gmap->ysz, 0, GL_ALPHA, GL_UNSIGNED_BYTE, gmap->pixels); + glGenerateMipmap(GL_TEXTURE_2D); +#else + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, gmap->xsz, gmap->ysz, GL_ALPHA, GL_UNSIGNED_BYTE, gmap->pixels); +#endif + } + + if(font_tex != gmap->tex) { + dtx_flush(); + } + font_tex = gmap->tex; +} + +void dtx_glyph(int code) +{ + struct dtx_glyphmap *gmap; + + if(!dtx_font || !(gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code))) { + return; + } + set_glyphmap_texture(gmap); + + add_glyph(gmap->glyphs + code - gmap->cstart, 0, 0); + dtx_flush(); +} + +static const char *put_char(const char *str, float *pos_x, float *pos_y, int *should_flush) +{ + struct dtx_glyphmap *gmap; + float px, py; + int code = dtx_utf8_char_code(str); + str = dtx_utf8_next_char((char*)str); + + if(buf_mode == DTX_LBF && code == '\n') { + *should_flush = 1; + } + + px = *pos_x; + py = *pos_y; + + if((gmap = dtx_proc_char(code, pos_x, pos_y))) { + int idx = code - gmap->cstart; + + set_glyphmap_texture(gmap); + add_glyph(gmap->glyphs + idx, px, py); + } + return str; +} + +void dtx_string(const char *str) +{ + int should_flush = buf_mode == DTX_NBF; + float pos_x = 0.0f; + float pos_y = 0.0f; + + if(!dtx_font) { + return; + } + + while(*str) { + str = put_char(str, &pos_x, &pos_y, &should_flush); + } + + if(should_flush) { + dtx_flush(); + } +} + +void dtx_printf(const char *fmt, ...) +{ + va_list ap; + int buf_size; + char *buf, tmp; + + if(!dtx_font) { + return; + } + + va_start(ap, fmt); + buf_size = vsnprintf(&tmp, 0, fmt, ap); + va_end(ap); + + if(buf_size == -1) { + buf_size = 512; + } + + buf = alloca(buf_size + 1); + va_start(ap, fmt); + vsnprintf(buf, buf_size + 1, fmt, ap); + va_end(ap); + + dtx_string(buf); +} + +static void qvertex(struct vertex *v, float x, float y, float s, float t) +{ + v->x = x; + v->y = y; + v->s = s; + v->t = t; +} + +static void add_glyph(struct glyph *g, float x, float y) +{ + struct quad *qptr = qbuf + num_quads; + + x -= g->orig_x; + y -= g->orig_y; + + qvertex(qptr->v + 0, x, y, g->nx, g->ny + g->nheight); + qvertex(qptr->v + 1, x + g->width, y, g->nx + g->nwidth, g->ny + g->nheight); + qvertex(qptr->v + 2, x + g->width, y + g->height, g->nx + g->nwidth, g->ny); + + qvertex(qptr->v + 3, x, y, g->nx, g->ny + g->nheight); + qvertex(qptr->v + 4, x + g->width, y + g->height, g->nx + g->nwidth, g->ny); + qvertex(qptr->v + 5, x, y + g->height, g->nx, g->ny); + + if(++num_quads >= QBUF_SZ) { + dtx_flush(); + } +} + +void dtx_flush(void) +{ + int vbo; + + if(!num_quads) { + return; + } + + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, 0); + +#ifndef GL_ES + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_TEXTURE_2D); +#endif + glBindTexture(GL_TEXTURE_2D, font_tex); + + if(vattr != -1) { + glEnableVertexAttribArray(vattr); + glVertexAttribPointer(vattr, 2, GL_FLOAT, 0, sizeof(struct vertex), qbuf); +#ifndef GL_ES + } else { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), qbuf); +#endif + } + if(tattr != -1) { + glEnableVertexAttribArray(tattr); + glVertexAttribPointer(tattr, 2, GL_FLOAT, 0, sizeof(struct vertex), &qbuf->v[0].s); +#ifndef GL_ES + } else { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), &qbuf->v[0].s); +#endif + } + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glDepthMask(0); + + glDrawArrays(GL_TRIANGLES, 0, num_quads * 6); + + glDepthMask(1); + + if(vattr != -1) { + glDisableVertexAttribArray(vattr); +#ifndef GL_ES + } else { + glDisableClientState(GL_VERTEX_ARRAY); +#endif + } + if(tattr != -1) { + glDisableVertexAttribArray(tattr); +#ifndef GL_ES + } else { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +#endif + } + +#ifndef GL_ES + glPopAttrib(); +#else + glDisable(GL_BLEND); +#endif + + if(vbo) { + glBindBuffer(GL_ARRAY_BUFFER, vbo); + } + + num_quads = 0; +} + +#endif /* !def NO_OPENGL */ diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/drawtext.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/drawtext.h Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,195 @@ +/* +libdrawtext - a simple library for fast text rendering in OpenGL +Copyright (C) 2011-2014 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#ifndef LIBDRAWTEXT_H_ +#define LIBDRAWTEXT_H_ + +#include +#include +#include "assman.h" + +struct dtx_font; +struct dtx_glyphmap; + +/* draw buffering modes */ +enum { + DTX_NBF, /* unbuffered */ + DTX_LBF, /* line buffered */ + DTX_FBF /* fully buffered */ +}; + +struct dtx_box { + float x, y; + float width, height; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Open a truetype/opentype/whatever font. + * + * If sz is non-zero, the default ASCII glyphmap at the requested point size is + * automatically created as well, and ready to use. + * + * To use other unicode ranges and different font sizes you must first call + * dtx_prepare or dtx_prepare_range before issuing any drawing calls, otherwise + * nothing will be rendered. + */ +struct dtx_font *dtx_open_font(const char *fname, int sz); +/* open a font by loading a precompiled glyphmap (see: dtx_save_glyphmap) + * this works even when compiled without freetype support + */ +struct dtx_font *dtx_open_font_glyphmap(const char *fname); +/* close a font opened by either of the above */ +void dtx_close_font(struct dtx_font *fnt); + +/* prepare an ASCII glyphmap for the specified font size */ +void dtx_prepare(struct dtx_font *fnt, int sz); +/* prepare an arbitrary unicode range glyphmap for the specified font size */ +void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend); + +int dtx_get_font_glyphmap_count(struct dtx_font *fnt); +struct dtx_glyphmap *dtx_get_font_glyphmap_idx(struct dtx_font *fnt, int idx); + +/* Finds the glyphmap that contains the specified character code and matches the requested size + * Returns null if it hasn't been created (you should call dtx_prepare/dtx_prepare_range). + */ +struct dtx_glyphmap *dtx_get_font_glyphmap(struct dtx_font *fnt, int sz, int code); + +/* Finds the glyphmap that contains the specified unicode range and matches the requested font size + * Will automatically generate one if it can't find it. + */ +struct dtx_glyphmap *dtx_get_font_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend); + +/* Creates and returns a glyphmap for a particular unicode range and font size. + * The generated glyphmap is added to the font's list of glyphmaps. + */ +struct dtx_glyphmap *dtx_create_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend); +/* free a glyphmap */ +void dtx_free_glyphmap(struct dtx_glyphmap *gmap); + +/* returns a pointer to the raster image of a glyphmap (1 byte per pixel grayscale) */ +unsigned char *dtx_get_glyphmap_image(struct dtx_glyphmap *gmap); +/* returns the point size of the glyphmap */ +int dtx_get_glyphmap_ptsize(struct dtx_glyphmap *gmap); +/* returns the width of the glyphmap image in pixels */ +int dtx_get_glyphmap_width(struct dtx_glyphmap *gmap); +/* returns the height of the glyphmap image in pixels */ +int dtx_get_glyphmap_height(struct dtx_glyphmap *gmap); + +/* The following functions can be used even when the library is compiled without + * freetype support. + */ +struct dtx_glyphmap *dtx_load_glyphmap(const char *fname); +struct dtx_glyphmap *dtx_load_glyphmap_stream(FILE *fp); +struct dtx_glyphmap *dtx_load_glyphmap_asset(ass_file *fp); +int dtx_save_glyphmap(const char *fname, const struct dtx_glyphmap *gmap); +int dtx_save_glyphmap_stream(FILE *fp, const struct dtx_glyphmap *gmap); + +/* adds a glyphmap to a font */ +void dtx_add_glyphmap(struct dtx_font *fnt, struct dtx_glyphmap *gmap); + +/* ---- rendering ---- */ + +/* before drawing anything this function must set the font to use */ +void dtx_use_font(struct dtx_font *fnt, int sz); + +/* sets the buffering mode + * - DTX_NBUF: every call to dtx_string gets rendered immediately. + * - DTX_LBUF: renders when the buffer is full or the string contains a newline. + * - DTX_FBUF: renders only when the buffer is full (you must call dtx_flush explicitly). + */ +void dtx_draw_buffering(int mode); + +/* Sets the vertex attribute indices to use for passing vertex and texture coordinate + * data. By default both are -1 which means you don't have to use a shader, and if you + * do they are accessible through gl_Vertex and gl_MultiTexCoord0, as usual. + * + * NOTE: If you are using OpenGL ES 2.x or OpenGL >= 3.1 pure (non-compatibility) context + * you must specify valid attribute indices. + */ +void dtx_vertex_attribs(int vert_attr, int tex_attr); + +/* draws a single glyph at the origin */ +void dtx_glyph(int code); +/* draws a utf-8 string starting at the origin. \n \r and \t are handled appropriately. */ +void dtx_string(const char *str); + +void dtx_printf(const char *fmt, ...); + +/* render any pending glyphs (see dtx_draw_buffering) */ +void dtx_flush(void); + + +/* ---- encodings ---- */ + +/* returns a pointer to the next character in a utf-8 stream */ +char *dtx_utf8_next_char(char *str); + +/* returns the unicode character codepoint of the utf-8 character starting at str */ +int dtx_utf8_char_code(const char *str); + +/* returns the number of bytes of the utf-8 character starting at str */ +int dtx_utf8_nbytes(const char *str); + +/* returns the number of utf-8 character in a zero-terminated utf-8 string */ +int dtx_utf8_char_count(const char *str); + +/* Converts a unicode code-point to a utf-8 character by filling in the buffer + * passed at the second argument, and returns the number of bytes taken by that + * utf-8 character. + * It's valid to pass a null buffer pointer, in which case only the byte count is + * returned (useful to figure out how much memory to allocate for a buffer). + */ +size_t dtx_utf8_from_char_code(int code, char *buf); + +/* Converts a unicode utf-16 wchar_t string to utf-8, filling in the buffer passed + * at the second argument. Returns the size of the resulting string in bytes. + * + * It's valid to pass a null buffer pointer, in which case only the size gets + * calculated and returned, which is useful for figuring out how much memory to + * allocate for the utf-8 buffer. + */ +size_t dtx_utf8_from_string(const wchar_t *str, char *buf); + + +/* ---- metrics ---- */ +float dtx_line_height(void); + +/* rendered dimensions of a single glyph */ +void dtx_glyph_box(int code, struct dtx_box *box); +float dtx_glyph_width(int code); +float dtx_glyph_height(int code); + +/* rendered dimensions of a string */ +void dtx_string_box(const char *str, struct dtx_box *box); +float dtx_string_width(const char *str); +float dtx_string_height(const char *str); + +/* returns the horizontal position of the n-th character of the rendered string + * (useful for placing cursors) + */ +float dtx_char_pos(const char *str, int n); + +int dtx_char_at_pt(const char *str, float pt); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBDRAWTEXT_H_ */ diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/drawtext_impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/drawtext_impl.h Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,73 @@ +/* +libdrawtext - a simple library for fast text rendering in OpenGL +Copyright (C) 2011-2012 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#ifndef TEXT_IMPL_H_ +#define TEXT_IMPL_H_ + +struct glyph { + int code; + float x, y, width, height; + /* normalized coords [0, 1] */ + float nx, ny, nwidth, nheight; + float orig_x, orig_y; + float advance; + struct glyph *next; +}; + +struct dtx_glyphmap { + int ptsize; + + int xsz, ysz; + unsigned char *pixels; + unsigned int tex; + + int cstart, cend; /* character range */ + int crange; + + float line_advance; + + struct glyph *glyphs; + struct dtx_glyphmap *next; +}; + +struct dtx_font { + /* freetype FT_Face */ + void *face; + + /* list of glyphmaps */ + struct dtx_glyphmap *gmaps; + int num_gmaps; + + /* last returned glyphmap (cache) */ + struct dtx_glyphmap *last_gmap; +}; + + +extern struct dtx_font *dtx_font; +extern int dtx_font_sz; + + +#define fperror(str) \ + fprintf(stderr, "%s: %s: %s\n", __FUNCTION__, (str), strerror(errno)) + +int dtx_gl_init(void); + +/* returns zero if it should NOT be printed and modifies xpos/ypos */ +/* implemented in font.c */ +struct dtx_glyphmap *dtx_proc_char(int code, float *xpos, float *ypos); + +#endif /* TEXT_IMPL_H_ */ diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/font.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/font.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,800 @@ +/* +libdrawtext - a simple library for fast text rendering in OpenGL +Copyright (C) 2011-2014 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#ifndef NO_FREETYPE +#define USE_FREETYPE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_FREETYPE +#include +#include FT_FREETYPE_H +#endif +#include "assman.h" +#include "drawtext.h" +#include "drawtext_impl.h" + +#define FTSZ_TO_PIXELS(x) ((x) / 64) +#define MAX_IMG_WIDTH 4096 + +struct dtx_font *dtx_font; +int dtx_font_sz; + + +#ifdef USE_FREETYPE +static int init_freetype(void); +static void cleanup(void); + +static void calc_best_size(int total_width, int max_gwidth, int max_gheight, + int padding, int pow2, int *imgw, int *imgh); +static int next_pow2(int x); + +static FT_Library ft; + + +static int init_done; + +static int init_freetype(void) +{ + if(!init_done) { + if(FT_Init_FreeType(&ft) != 0) { + return -1; + } + atexit(cleanup); + init_done = 1; + } + return 0; +} + +static void cleanup(void) +{ + if(init_done) { + FT_Done_FreeType(ft); + } +} +#endif /* USE_FREETYPE */ + +struct dtx_font *dtx_open_font(const char *fname, int sz) +{ + struct dtx_font *fnt = 0; + +#ifdef USE_FREETYPE + init_freetype(); + + if(!(fnt = calloc(1, sizeof *fnt))) { + fperror("failed to allocate font structure"); + return 0; + } + + if(FT_New_Face(ft, fname, 0, (FT_Face*)&fnt->face) != 0) { + fprintf(stderr, "failed to open font file: %s\n", fname); + return 0; + } + + /* pre-create the extended ASCII range glyphmap */ + if(sz) { + dtx_prepare_range(fnt, sz, 0, 256); + + if(!dtx_font) { + dtx_use_font(fnt, sz); + } + } +#else + fprintf(stderr, "ignoring call to dtx_open_font: not compiled with freetype support!\n"); +#endif + + return fnt; +} + +struct dtx_font *dtx_open_font_glyphmap(const char *fname) +{ + struct dtx_font *fnt; + struct dtx_glyphmap *gmap; + + if(!(fnt = calloc(1, sizeof *fnt))) { + fperror("failed to allocate font structure"); + return 0; + } + + if(fname) { + if(!(gmap = dtx_load_glyphmap(fname))) { + free(fnt); + return 0; + } + + dtx_add_glyphmap(fnt, gmap); + + if(!dtx_font) { + dtx_use_font(fnt, gmap->ptsize); + } + } + return fnt; +} + +void dtx_close_font(struct dtx_font *fnt) +{ + if(!fnt) return; + +#ifdef USE_FREETYPE + FT_Done_Face(fnt->face); +#endif + + /* destroy the glyphmaps */ + while(fnt->gmaps) { + void *tmp = fnt->gmaps; + fnt->gmaps = fnt->gmaps->next; + dtx_free_glyphmap(tmp); + } + + free(fnt); +} + +void dtx_prepare(struct dtx_font *fnt, int sz) +{ + if(!dtx_get_font_glyphmap_range(fnt, sz, 0, 256)) { + fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __FUNCTION__, sz); + } +} + +void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend) +{ + if(!dtx_get_font_glyphmap_range(fnt, sz, cstart, cend)) { + fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __FUNCTION__, sz, cstart, cend); + } +} + +int dtx_get_font_glyphmap_count(struct dtx_font *fnt) +{ + return fnt->num_gmaps; +} + +struct dtx_glyphmap *dtx_get_font_glyphmap_idx(struct dtx_font *fnt, int idx) +{ + int i; + struct dtx_glyphmap *gm = fnt->gmaps; + + for(i=0; inext; + if(!gm) return 0; + } + return gm; +} + +struct dtx_glyphmap *dtx_get_font_glyphmap(struct dtx_font *fnt, int sz, int code) +{ + struct dtx_glyphmap *gm; + + /* check to see if the last we've given out fits the bill */ + if(fnt->last_gmap && code >= fnt->last_gmap->cstart && code < fnt->last_gmap->cend && fnt->last_gmap->ptsize == sz) { + return fnt->last_gmap; + } + + /* otherwise search for the appropriate glyphmap */ + gm = fnt->gmaps; + while(gm) { + if(code >= gm->cstart && code < gm->cend && sz == gm->ptsize) { + fnt->last_gmap = gm; + return gm; + } + gm = gm->next; + } + return 0; +} + +struct dtx_glyphmap *dtx_get_font_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend) +{ + struct dtx_glyphmap *gm; + + /* search the available glyphmaps to see if we've got one that includes + * the requested range + */ + gm = fnt->gmaps; + while(gm) { + if(gm->cstart <= cstart && gm->cend >= cend && gm->ptsize == sz) { + return gm; + } + gm = gm->next; + } + + /* not found, create one and add it to the list */ + if(!(gm = dtx_create_glyphmap_range(fnt, sz, cstart, cend))) { + return 0; + } + return gm; +} + +struct dtx_glyphmap *dtx_create_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend) +{ + struct dtx_glyphmap *gmap = 0; + +#ifdef USE_FREETYPE + FT_Face face = fnt->face; + int i, j; + int gx, gy; + int padding = 4; + int total_width, max_width, max_height; + + FT_Set_Char_Size(fnt->face, 0, sz * 64, 72, 72); + + if(!(gmap = calloc(1, sizeof *gmap))) { + return 0; + } + + gmap->ptsize = sz; + gmap->cstart = cstart; + gmap->cend = cend; + gmap->crange = cend - cstart; + gmap->line_advance = FTSZ_TO_PIXELS((float)face->size->metrics.height); + + if(!(gmap->glyphs = malloc(gmap->crange * sizeof *gmap->glyphs))) { + free(gmap); + return 0; + } + + total_width = padding; + max_width = max_height = 0; + + for(i=0; icrange; i++) { + int w, h; + + FT_Load_Char(face, i + cstart, 0); + w = FTSZ_TO_PIXELS(face->glyph->metrics.width); + h = FTSZ_TO_PIXELS(face->glyph->metrics.height); + + if(w > max_width) max_width = w; + if(h > max_height) max_height = h; + + total_width += w + padding; + } + + calc_best_size(total_width, max_width, max_height, padding, 1, &gmap->xsz, &gmap->ysz); + + if(!(gmap->pixels = malloc(gmap->xsz * gmap->ysz))) { + free(gmap->glyphs); + free(gmap); + return 0; + } + memset(gmap->pixels, 0, gmap->xsz * gmap->ysz); + + gx = padding; + gy = padding; + + for(i=0; icrange; i++) { + float gwidth, gheight; + unsigned char *src, *dst; + FT_GlyphSlot glyph; + + FT_Load_Char(face, i + cstart, FT_LOAD_RENDER); + glyph = face->glyph; + gwidth = FTSZ_TO_PIXELS((float)glyph->metrics.width); + gheight = FTSZ_TO_PIXELS((float)glyph->metrics.height); + + if(gx > gmap->xsz - gwidth - padding) { + gx = padding; + gy += max_height + padding; + } + + src = glyph->bitmap.buffer; + dst = gmap->pixels + gy * gmap->xsz + gx; + + for(j=0; jbitmap.rows; j++) { + memcpy(dst, src, glyph->bitmap.width); + dst += gmap->xsz; + src += glyph->bitmap.pitch; + } + + gmap->glyphs[i].code = i; + gmap->glyphs[i].x = gx - 1; + gmap->glyphs[i].y = gy - 1; + gmap->glyphs[i].width = gwidth + 2; + gmap->glyphs[i].height = gheight + 2; + gmap->glyphs[i].orig_x = -FTSZ_TO_PIXELS((float)glyph->metrics.horiBearingX) + 1; + gmap->glyphs[i].orig_y = FTSZ_TO_PIXELS((float)glyph->metrics.height - glyph->metrics.horiBearingY) + 1; + gmap->glyphs[i].advance = FTSZ_TO_PIXELS((float)glyph->metrics.horiAdvance); + /* also precalc normalized */ + gmap->glyphs[i].nx = (float)gmap->glyphs[i].x / (float)gmap->xsz; + gmap->glyphs[i].ny = (float)gmap->glyphs[i].y / (float)gmap->ysz; + gmap->glyphs[i].nwidth = (float)gmap->glyphs[i].width / (float)gmap->xsz; + gmap->glyphs[i].nheight = (float)gmap->glyphs[i].height / (float)gmap->ysz; + + gx += gwidth + padding; + } + + /* add it to the glyphmaps list of the font */ + dtx_add_glyphmap(fnt, gmap); +#endif /* USE_FREETYPE */ + + return gmap; +} + +void dtx_free_glyphmap(struct dtx_glyphmap *gmap) +{ + if(gmap) { + free(gmap->pixels); + free(gmap->glyphs); + free(gmap); + } +} + +unsigned char *dtx_get_glyphmap_pixels(struct dtx_glyphmap *gmap) +{ + return gmap->pixels; +} + +int dtx_get_glyphmap_ptsize(struct dtx_glyphmap *gmap) +{ + return gmap->ptsize; +} + +int dtx_get_glyphmap_width(struct dtx_glyphmap *gmap) +{ + return gmap->xsz; +} + +int dtx_get_glyphmap_height(struct dtx_glyphmap *gmap) +{ + return gmap->ysz; +} + +struct dtx_glyphmap *dtx_load_glyphmap(const char *fname) +{ + ass_file *fp; + struct dtx_glyphmap *gmap; + + if(!(fp = ass_fopen(fname, "rb"))) { + return 0; + } + gmap = dtx_load_glyphmap_asset(fp); + ass_fclose(fp); + return gmap; +} + +struct dtx_glyphmap *dtx_load_glyphmap_asset(ass_file *fp) +{ + char buf[512]; + int hdr_lines = 0; + struct dtx_glyphmap *gmap; + struct glyph *glyphs = 0; + struct glyph *g; + int min_code = INT_MAX; + int max_code = INT_MIN; + int i, max_pixval, num_pixels; + + if(!(gmap = calloc(1, sizeof *gmap))) { + fperror("failed to allocate glyphmap"); + return 0; + } + gmap->ptsize = -1; + gmap->line_advance = FLT_MIN; + + while(hdr_lines < 3) { + char *line = buf; + if(!ass_fgets(buf, sizeof buf, fp)) { + fperror("unexpected end of file"); + goto err; + } + + while(isspace(*line)) { + line++; + } + + if(line[0] == '#') { + int c, res; + float x, y, xsz, ysz, orig_x, orig_y, adv, line_adv; + int ptsize; + + if((res = sscanf(line + 1, " size: %d\n", &ptsize)) == 1) { + gmap->ptsize = ptsize; + + } else if((res = sscanf(line + 1, " advance: %f\n", &line_adv)) == 1) { + gmap->line_advance = line_adv; + + } else if((res = sscanf(line + 1, " %d: %fx%f+%f+%f o:%f,%f adv:%f\n", + &c, &xsz, &ysz, &x, &y, &orig_x, &orig_y, &adv)) == 8) { + if(!(g = malloc(sizeof *g))) { + fperror("failed to allocate glyph"); + goto err; + } + g->code = c; + g->x = x; + g->y = y; + g->width = xsz; + g->height = ysz; + g->orig_x = orig_x; + g->orig_y = orig_y; + g->advance = adv; + /* normalized coordinates will be precalculated after everything is loaded */ + + g->next = glyphs; + glyphs = g; + + if(c < min_code) { + min_code = c; + } + if(c > max_code) { + max_code = c; + } + + } else { + fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__); + goto err; + } + + } else { + switch(hdr_lines) { + case 0: + if(0[line] != 'P' || 1[line] != '6') { + fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__); + goto err; + } + break; + + case 1: + if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) { + fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__); + goto err; + } + break; + + case 2: + { + char *endp; + max_pixval = strtol(line, &endp, 10); + if(endp == line) { + fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__); + goto err; + } + } + break; + + default: + break; /* can't happen */ + } + hdr_lines++; + } + } + + if(gmap->ptsize == -1 || gmap->line_advance == FLT_MIN) { + fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __FUNCTION__); + goto err; + } + + /* precalculate normalized glyph coordinates */ + g = glyphs; + while(g) { + g->nx = g->x / gmap->xsz; + g->ny = g->y / gmap->ysz; + g->nwidth = g->width / gmap->xsz; + g->nheight = g->height / gmap->ysz; + g = g->next; + } + + num_pixels = gmap->xsz * gmap->ysz; + if(!(gmap->pixels = malloc(num_pixels))) { + fperror("failed to allocate pixels"); + goto err; + } + + for(i=0; ipixels[i] = 255 * c / max_pixval; + ass_fseek(fp, 2, SEEK_CUR); + } + + gmap->cstart = min_code; + gmap->cend = max_code + 1; + gmap->crange = gmap->cend - gmap->cstart; + + if(!(gmap->glyphs = calloc(gmap->crange, sizeof *gmap->glyphs))) { + fperror("failed to allocate glyph info"); + goto err; + } + + while(glyphs) { + struct glyph *g = glyphs; + glyphs = glyphs->next; + + gmap->glyphs[g->code - gmap->cstart] = *g; + free(g); + } + return gmap; + +err: + dtx_free_glyphmap(gmap); + while(glyphs) { + void *tmp = glyphs; + glyphs = glyphs->next; + free(tmp); + } + return 0; +} + +int dtx_save_glyphmap(const char *fname, const struct dtx_glyphmap *gmap) +{ + FILE *fp; + int res; + + if(!(fp = fopen(fname, "wb"))) { + fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno)); + return -1; + } + res = dtx_save_glyphmap_stream(fp, gmap); + fclose(fp); + return res; +} + +int dtx_save_glyphmap_stream(FILE *fp, const struct dtx_glyphmap *gmap) +{ + int i, num_pixels; + struct glyph *g = gmap->glyphs; + + fprintf(fp, "P6\n%d %d\n", gmap->xsz, gmap->ysz); + fprintf(fp, "# size: %d\n", gmap->ptsize); + fprintf(fp, "# advance: %g\n", gmap->line_advance); + for(i=0; icrange; i++) { + fprintf(fp, "# %d: %gx%g+%g+%g o:%g,%g adv:%g\n", g->code, g->width, g->height, g->x, g->y, + g->orig_x, g->orig_y, g->advance); + g++; + } + fprintf(fp, "255\n"); + + num_pixels = gmap->xsz * gmap->ysz; + for(i=0; ipixels[i]; + fputc(c, fp); + fputc(c, fp); + fputc(c, fp); + } + return 0; +} + +void dtx_add_glyphmap(struct dtx_font *fnt, struct dtx_glyphmap *gmap) +{ + gmap->next = fnt->gmaps; + fnt->gmaps = gmap; + fnt->num_gmaps++; +} + + +void dtx_use_font(struct dtx_font *fnt, int sz) +{ + dtx_gl_init(); + + dtx_font = fnt; + dtx_font_sz = sz; +} + +float dtx_line_height(void) +{ + struct dtx_glyphmap *gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, '\n'); + + return gmap->line_advance; +} + +void dtx_glyph_box(int code, struct dtx_box *box) +{ + int cidx; + struct dtx_glyphmap *gmap; + gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code); + + cidx = code - gmap->cstart; + + box->x = gmap->glyphs[cidx].orig_x; + box->y = gmap->glyphs[cidx].orig_y; + box->width = gmap->glyphs[cidx].width; + box->height = gmap->glyphs[cidx].height; +} + +float dtx_glyph_width(int code) +{ + struct dtx_box box; + dtx_glyph_box(code, &box); + return box.width; +} + +float dtx_glyph_height(int code) +{ + struct dtx_box box; + dtx_glyph_box(code, &box); + return box.height; +} + +void dtx_string_box(const char *str, struct dtx_box *box) +{ + int code; + float pos_x = 0.0f, pos_y = 0.0f; + struct glyph *g = 0; + float x0, y0, x1, y1; + + x0 = y0 = FLT_MAX; + x1 = y1 = -FLT_MAX; + + while(*str) { + float px, py; + struct dtx_glyphmap *gmap; + + code = dtx_utf8_char_code(str); + str = dtx_utf8_next_char((char*)str); + + px = pos_x; + py = pos_y; + + if((gmap = dtx_proc_char(code, &pos_x, &pos_y))) { + g = gmap->glyphs + code - gmap->cstart; + + if(px + g->orig_x < x0) { + x0 = px + g->orig_x; + } + if(py - g->orig_y < y0) { + y0 = py - g->orig_y; + } + if(px + g->orig_x + g->width > x1) { + x1 = px + g->orig_x + g->width; + } + if(py - g->orig_y + g->height > y1) { + y1 = py - g->orig_y + g->height; + } + } + } + + box->x = x0; + box->y = y0; + box->width = x1 - x0; + box->height = y1 - y0; +} + +float dtx_string_width(const char *str) +{ + struct dtx_box box; + + dtx_string_box(str, &box); + return box.width; +} + +float dtx_string_height(const char *str) +{ + struct dtx_box box; + + dtx_string_box(str, &box); + return box.height; +} + +float dtx_char_pos(const char *str, int n) +{ + int i; + float pos = 0.0; + struct dtx_glyphmap *gmap; + + for(i=0; iglyphs[i].advance; + } + return pos; +} + +int dtx_char_at_pt(const char *str, float pt) +{ + int i; + float prev_pos = 0.0f, pos = 0.0f; + struct dtx_glyphmap *gmap; + + for(i=0; *str; i++) { + int code = dtx_utf8_char_code(str); + str = dtx_utf8_next_char((char*)str); + + gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code); + pos += gmap->glyphs[i].advance; + + if(fabs(pt - prev_pos) < fabs(pt - pos)) { + break; + } + prev_pos = pos; + } + return i; +} + +struct dtx_glyphmap *dtx_proc_char(int code, float *xpos, float *ypos) +{ + struct dtx_glyphmap *gmap; + gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code); + + switch(code) { + case '\n': + *xpos = 0.0; + if(gmap) { + *ypos -= gmap->line_advance; + } + return 0; + + case '\t': + if(gmap) { + *xpos = (fmod(*xpos, 4.0) + 4.0) * gmap->glyphs[0].advance; + } + return 0; + + case '\r': + *xpos = 0.0; + return 0; + + default: + break; + } + + if(gmap) { + *xpos += gmap->glyphs[code - gmap->cstart].advance; + } + return gmap; +} + +#ifdef USE_FREETYPE +static void calc_best_size(int total_width, int max_gwidth, int max_gheight, int padding, int pow2, int *imgw, int *imgh) +{ + int xsz, ysz, num_rows; + float aspect; + + for(xsz=2; xsz<=MAX_IMG_WIDTH; xsz *= 2) { + num_rows = total_width / xsz + 1; + + /* assume worst case, all last glyphs will float to the next line + * so let's add extra rows for that. */ + num_rows += (padding + (max_gwidth + padding) * num_rows + xsz - 1) / xsz; + + ysz = num_rows * (max_gheight + padding) + padding; + if(pow2) { + ysz = next_pow2(ysz); + } + aspect = (float)xsz / (float)ysz; + + if(aspect >= 1.0) { + break; + } + } + + if(xsz > MAX_IMG_WIDTH) { + xsz = MAX_IMG_WIDTH; + } + + *imgw = xsz; + *imgh = ysz; +} + + +static int next_pow2(int x) +{ + x--; + x = (x >> 1) | x; + x = (x >> 2) | x; + x = (x >> 4) | x; + x = (x >> 8) | x; + x = (x >> 16) | x; + return x + 1; +} +#endif diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/drawtext/utf8.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/drawtext/utf8.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,154 @@ +/* +libdrawtext - a simple library for fast text rendering in OpenGL +Copyright (C) 2011 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#include "drawtext.h" + +#define U8_IS_FIRST(x) (((((x) >> 7) & 1) == 0) || ((((x) >> 6) & 3) == 3)) + +static const char first_mask[] = { + 0, + 0x7f, /* single byte, 7 bits valid */ + 0x1f, /* two-bytes, 5 bits valid */ + 0xf, /* three-bytes, 4 bits valid */ + 0x7 /* four-bytes, 3 bits valid */ +}; +static const char first_shift[] = { 0, 7, 5, 4, 3 }; /* see above */ + +#define CONT_PREFIX 0x80 +#define CONT_MASK 0x3f +#define CONT_SHIFT 6 + +/* last charcodes for 1, 2, 3 or 4-byte utf8 chars */ +static const int utf8_lastcode[] = { 0x7f, 0x7ff, 0xfff, 0x1fffff }; + +#define prefix_mask(x) (~first_mask[x]) +#define prefix(x) ((prefix_mask(x) << 1) & 0xff) + + +char *dtx_utf8_next_char(char *str) +{ + return str + dtx_utf8_nbytes(str); +} + +int dtx_utf8_char_code(const char *str) +{ + int i, nbytes, shift, code = 0; + int mask; + + if(!U8_IS_FIRST(*str)) { + return -1; + } + + nbytes = dtx_utf8_nbytes(str); + mask = first_mask[nbytes]; + shift = 0; + + for(i=0; i> (7 - i)) & 1) == 0) { + break; + } + numset++; + } + + if(!numset) { + return 1; + } + return numset; +} + +int dtx_utf8_char_count(const char *str) +{ + int n = 0; + + while(*str) { + n++; + str = dtx_utf8_next_char((char*)str); + } + return n; +} + +size_t dtx_utf8_from_char_code(int code, char *buf) +{ + size_t nbytes = 0; + int i; + + for(i=0; i<4; i++) { + if(code <= utf8_lastcode[i]) { + nbytes = i + 1; + break; + } + } + + if(!nbytes && buf) { + for(i=0; i<(int)nbytes; i++) { + int idx = nbytes - i - 1; + int mask, shift, prefix; + + if(idx > 0) { + mask = CONT_MASK; + shift = CONT_SHIFT; + prefix = CONT_PREFIX; + } else { + mask = first_mask[nbytes]; + shift = first_shift[nbytes]; + prefix = prefix(nbytes); + } + + buf[idx] = (code & mask) | (prefix & ~mask); + code >>= shift; + } + } + return nbytes; +} + +size_t dtx_utf8_from_string(const wchar_t *str, char *buf) +{ + size_t nbytes = 0; + char *ptr = buf; + + while(*str) { + int cbytes = dtx_utf8_from_char_code(*str++, ptr); + if(ptr) { + ptr += cbytes; + } + nbytes += cbytes; + } + return nbytes; +} diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/goatkit/theme.cc --- a/libs/goatkit/theme.cc Wed Sep 23 05:44:58 2015 +0300 +++ b/libs/goatkit/theme.cc Thu Sep 24 06:49:25 2015 +0300 @@ -103,30 +103,34 @@ { unload(); - std::string fname = std::string(name) + ".gtheme"; - if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) { - for(size_t i=0; iso = dlopen(path.c_str(), RTLD_LAZY))) { - break; - } - } - - // try the fallback paths - if(!impl->so) { - for(int i=0; fallback_paths[i]; i++) { - std::string path = std::string(fallback_paths[i]) + "/" + fname; + if(strcmp(name, "GOATKIT_THEME_BUILTIN") == 0) { + impl->so = RTLD_DEFAULT; + } else { + std::string fname = std::string(name) + ".gtheme"; + if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) { + for(size_t i=0; iso = dlopen(path.c_str(), RTLD_LAZY))) { break; } } - } - if(!impl->so) { - fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name); - return false; + // try the fallback paths + if(!impl->so) { + for(int i=0; fallback_paths[i]; i++) { + std::string path = std::string(fallback_paths[i]) + "/" + fname; + + if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) { + break; + } + } + } + + if(!impl->so) { + fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name); + return false; + } } } @@ -144,7 +148,9 @@ void Theme::unload() { if(impl->so) { - dlclose(impl->so); + if(impl->so != RTLD_DEFAULT) { + dlclose(impl->so); + } impl->so = 0; } impl->func_cache.clear(); @@ -248,6 +254,9 @@ static void *dlsym(void *so, const char *symbol) { + if(so == RTLD_DEFAULT) { + so = GetModuleHandle(0); + } return (void*)GetProcAddress(so, symbol); } #endif diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 libs/goatkit/theme.h --- a/libs/goatkit/theme.h Wed Sep 23 05:44:58 2015 +0300 +++ b/libs/goatkit/theme.h Thu Sep 24 06:49:25 2015 +0300 @@ -18,6 +18,8 @@ #ifndef THEME_H_ #define THEME_H_ +#define GOATKIT_THEME_BUILTIN "GOATKIT_THEME_BUILTIN" + namespace goatkit { class Widget; diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 sdr/font.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdr/font.p.glsl Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,15 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D tex; +uniform vec4 ucolor; + +//varying vec4 vcolor; +varying vec2 vtexcoord; + +void main() +{ + vec4 texel = texture2D(tex, vtexcoord); + gl_FragColor = vec4(ucolor.xyz, texel.a * ucolor.a); +} diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 sdr/ui.p.glsl --- a/sdr/ui.p.glsl Wed Sep 23 05:44:58 2015 +0300 +++ b/sdr/ui.p.glsl Thu Sep 24 06:49:25 2015 +0300 @@ -3,12 +3,13 @@ #endif uniform sampler2D tex; +uniform vec4 ucolor; -varying vec4 vcolor; +//varying vec4 vcolor; varying vec2 vtexcoord; void main() { vec4 texel = texture2D(tex, vtexcoord); - gl_FragColor = vcolor * texel; + gl_FragColor = texel * ucolor; } diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 sdr/ui.v.glsl --- a/sdr/ui.v.glsl Wed Sep 23 05:44:58 2015 +0300 +++ b/sdr/ui.v.glsl Thu Sep 24 06:49:25 2015 +0300 @@ -1,15 +1,15 @@ -attribute vec4 attr_vertex, attr_color; +attribute vec4 attr_vertex;//, attr_color; attribute vec2 attr_texcoord; uniform mat4 matrix_modelview, matrix_projection; -varying vec4 vcolor; +//varying vec4 vcolor; varying vec2 vtexcoord; void main() { mat4 mvp = matrix_projection * matrix_modelview; gl_Position = mvp * attr_vertex; - vcolor = attr_color; + //vcolor = attr_color; vtexcoord = attr_texcoord; } diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/android/assman.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/android/assman.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,63 @@ +#include +#include +#include "assman.h" +#include "native_glue.h" +#include "amain.h" + +ass_file *ass_fopen(const char *fname, const char *mode) +{ + AAsset *ass; + unsigned int flags = 0; + char prev = 0; + + while(*mode) { + switch(*mode) { + case 'r': + flags |= O_RDONLY; + break; + + case 'w': + flags |= O_WRONLY; + break; + + case 'a': + flags |= O_APPEND; + break; + + case '+': + if(prev == 'w' || prev == 'a') { + flags |= O_CREAT; + } + break; + + default: + break; + } + prev = *mode++; + } + + if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) { + return 0; + } + return (ass_file*)ass; +} + +void ass_fclose(ass_file *fp) +{ + AAsset_close((AAsset*)fp); +} + +long ass_fseek(ass_file *fp, long offs, int whence) +{ + return AAsset_seek((AAsset*)fp, offs, whence); +} + +long ass_ftell(ass_file *fp) +{ + return AAsset_seek((AAsset*)fp, 0, SEEK_SET); +} + +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp) +{ + return AAsset_read((AAsset*)fp, buf, size * count) / size; +} diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/assman.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/assman.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,31 @@ +#include +#include "assman.h" + +int ass_fgetc(ass_file *fp) +{ + unsigned char c; + + if(ass_fread(&c, 1, 1, fp) < 1) { + return -1; + } + return (int)c; +} + +char *ass_fgets(char *s, int size, ass_file *fp) +{ + int i, c; + char *ptr = s; + + if(!size) return 0; + + for(i=0; i + +typedef void ass_file; + +#ifdef __cplusplus +extern "C" { +#endif + +ass_file *ass_fopen(const char *fname, const char *mode); +void ass_fclose(ass_file *fp); +long ass_fseek(ass_file *fp, long offs, int whence); +long ass_ftell(ass_file *fp); + +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp); + +/* convenience functions, derived from the above */ +int ass_fgetc(ass_file *fp); +char *ass_fgets(char *s, int size, ass_file *fp); + +#ifdef __cplusplus +} +#endif + +#endif /* ASSMAN_H_ */ diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/config.h --- a/src/config.h Wed Sep 23 05:44:58 2015 +0300 +++ b/src/config.h Thu Sep 24 06:49:25 2015 +0300 @@ -6,6 +6,7 @@ #if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE) #define IPHONE +#define TARGET_IPHONE #endif #endif /* __APPLE__ */ diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/ios/assman.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ios/assman.c Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,28 @@ +#include +#include "assman.h" + +ass_file *ass_fopen(const char *fname, const char *mode) +{ + return (ass_file*)fopen(fname, mode); +} + +void ass_fclose(ass_file *fp) +{ + fclose((FILE*)fp); +} + +long ass_fseek(ass_file *fp, long offs, int whence) +{ + fseek((FILE*)fp, offs, whence); + return ftell((FILE*)fp); +} + +long ass_ftell(ass_file *fp) +{ + return ftell((FILE*)fp); +} + +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp) +{ + return fread(buf, size, count, (FILE*)fp); +} diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/istereo.c --- a/src/istereo.c Wed Sep 23 05:44:58 2015 +0300 +++ b/src/istereo.c Thu Sep 24 06:49:25 2015 +0300 @@ -31,6 +31,7 @@ #include "vmath.h" #include "config.h" #include "ui.h" +#include "drawtext.h" static void render(float t); static void draw_tunnel(float t); @@ -41,8 +42,9 @@ static unsigned int get_shader_program(const char *vfile, const char *pfile); static float get_sec(void); -unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui; +unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui, prog_font; unsigned int tex, tex_stones, tex_normal, tex_text; +struct dtx_font *font; int view_xsz, view_ysz; @@ -80,6 +82,9 @@ if(!(prog_ui = get_shader_program("ui.v.glsl", "ui.p.glsl"))) { return -1; } + if(!(prog_font = get_shader_program("ui.v.glsl", "font.p.glsl"))) { + return -1; + } if(!(tex = load_texture(find_resource("tiles.jpg", 0, 0)))) { return -1; @@ -94,6 +99,13 @@ return -1; } + if(!(font = dtx_open_font_glyphmap(find_resource("linux-libertine_s24.glyphmap", 0, 0)))) { + fprintf(stderr, "failed to load font\n"); + return -1; + } + dtx_vertex_attribs(get_attrib_loc(prog_ui, "attr_vertex"), get_attrib_loc(prog_ui, "attr_texcoord")); + dtx_use_font(font, 24); + glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -114,6 +126,8 @@ free_program(prog_tunnel); free_program(prog_color); free_program(prog_ui); + free_program(prog_font); + dtx_close_font(font); } void redraw(void) @@ -184,6 +198,20 @@ render(tsec); } + /* TEST */ + /*bind_program(prog_ui); + + gl_matrix_mode(GL_PROJECTION); + gl_load_identity(); + gl_ortho(0, view_xsz, 0, view_ysz, -1, 1); + gl_matrix_mode(GL_MODELVIEW); + gl_load_identity(); + gl_apply_xform(prog_ui); + + glDisable(GL_DEPTH_TEST); + dtx_printf("hello world\n"); + glEnable(GL_DEPTH_TEST);*/ + assert(glGetError() == GL_NO_ERROR); } diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/ui.cc --- a/src/ui.cc Wed Sep 23 05:44:58 2015 +0300 +++ b/src/ui.cc Thu Sep 24 06:49:25 2015 +0300 @@ -1,3 +1,4 @@ +#include #include "ui.h" #include "goatkit/goatkit.h" #include "opengl.h" @@ -64,8 +65,11 @@ // load the theme //goatkit::add_theme_path("themes/simple"); - //goatkit::theme = new goatkit::Theme; - //goatkit::theme->load("simple"); + goatkit::theme = new goatkit::Theme; + if(!goatkit::theme->load(GOATKIT_THEME_BUILTIN)) { + fprintf(stderr, "no builitn theme\n"); + return -1; + } return 0; } @@ -91,25 +95,28 @@ gl_load_identity(); gl_scalef(2.0 / aspect, 2.0, 1); gl_translatef(-1, -1, 0); - gl_scalef(1, -1, 1); gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_identity(); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /*gl_begin(GL_QUADS); - gl_color3f(1, 0, 0); + set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5); + + gl_begin(GL_QUADS); + //gl_color4f(0, 0, 0, 0.5); gl_vertex3f(0, 0, 0); - gl_vertex3f(0, 0.5, 0); - gl_vertex3f(0.5 * aspect, 0.5, 0); - gl_vertex3f(0.5 * aspect, 0, 0); + gl_vertex3f(0, 1.0, 0); + gl_vertex3f(1.0 * aspect, 1.0, 0); + gl_vertex3f(1.0 * aspect, 0, 0); gl_end(); - */ scr.draw(); + glDisable(GL_BLEND); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); @@ -122,10 +129,10 @@ void ui_button(int bn, int press, int x, int y) { - scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, 1.0 - (float)y / (float)height); + scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height); } void ui_motion(int x, int y) { - scr.sysev_mouse_motion((float)x / (float)width, 1.0 - (float)y / (float)height); + scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height); } \ No newline at end of file diff -r 3bccfc7d10fe -r a3c4fcc9f8f3 src/uitheme.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/uitheme.cc Thu Sep 24 06:49:25 2015 +0300 @@ -0,0 +1,101 @@ +#include +#include +#include "goatkit/goatkit.h" +#include "opengl.h" +#include "drawtext.h" +#include "sdr.h" + +#define VIS_THRES 0.005 + +using namespace goatkit; + +extern int view_xsz, view_ysz; +extern unsigned int prog_ui, prog_font; +extern struct dtx_font *font; + +static void draw_label(const Widget *w); +static void draw_text(float x, float y, const char *text); + +static struct { + const char *name; + WidgetDrawFunc func; +} widget_funcs[] = { + { "label", draw_label }, + {0, 0} +}; + +static std::map funcmap; + +extern "C" WidgetDrawFunc get_widget_func(const char *name) +{ + static bool initialized; + + if(!initialized) { + for(int i=0; widget_funcs[i].func; i++) { + funcmap[widget_funcs[i].name] = widget_funcs[i].func; + } + initialized = true; + } + return funcmap[name]; +} + +static void begin_drawing(const Widget *w) +{ + Vec2 pos = w->get_position(); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + gl_matrix_mode(GL_MODELVIEW); + gl_push_matrix(); + gl_load_identity(); + gl_translatef(pos.x, pos.y, 0); +} + +static void end_drawing(const Widget *w) +{ + gl_matrix_mode(GL_MODELVIEW); + gl_pop_matrix(); +} + +static void draw_label(const Widget *w) +{ + Vec2 pos = w->get_position(); + float vis = w->get_visibility(); + if(vis < VIS_THRES) return; + + begin_drawing(w); + draw_text(pos.x, pos.y, w->get_text()); + end_drawing(w); +} + +static void draw_text(float x, float y, const char *text) +{ + struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); + dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); + + float aspect = (float)view_xsz / (float)view_ysz; + float virt_xsz = 420.0 * aspect; + float virt_ysz = 420.0; + + gl_matrix_mode(GL_PROJECTION); + gl_push_matrix(); + gl_load_identity(); + gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1); + + gl_matrix_mode(GL_MODELVIEW); + gl_push_matrix(); + gl_load_identity(); + gl_translatef(x * virt_xsz, y * virt_ysz, 0); + + bind_program(prog_font); + set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0); + gl_apply_xform(prog_ui); + + dtx_string(text); + + gl_matrix_mode(GL_PROJECTION); + gl_pop_matrix(); + gl_matrix_mode(GL_MODELVIEW); + gl_pop_matrix(); +} \ No newline at end of file