Skip to content

Instantly share code, notes, and snippets.

View Shtille's full-sized avatar

Vladimir Shtille

  • Moscow
View GitHub Profile
@Shtille
Shtille / gist:30dff1757f5ab1c82122
Last active January 3, 2016 17:20
Create OpenGL diplay lists for custom Windows font
font = new Font();
const int nBmpSize = Font::GetBmpSize();
const int nCharSize = nBmpSize / 16;
// Read preferences
int iWidth = (bold) ? FW_BOLD : FW_DONTCARE;
DWORD dwItalic = (italic) ? TRUE : FALSE;
DWORD dwUnderline = (underline) ? TRUE : FALSE;
DWORD dwStrikeOut = (strikeout) ? TRUE : FALSE;
@Shtille
Shtille / scope_timer.cpp
Last active January 20, 2016 08:34
Scope time execution measurement class (C++11)
#include <iostream>
#include <chrono>
class ScopeTimer {
typedef std::chrono::high_resolution_clock clock;
typedef std::chrono::duration<float> seconds;
public:
ScopeTimer(const char* message)
: message_(message)
{
#include <iostream>
#include <string>
const double trip_cost = 5000.0; // dollars
int main()
{
// Compute exchange rate deltas (using russian trader BCS for money exchange)
const double e_sell_today = 69.19;
const double e_buy_today = 67.20;
@Shtille
Shtille / window_controller.mm
Created July 9, 2016 14:33
Creating fullscreen window, first way
// Enable fullscreen ability
NSWindowCollectionBehavior behavior = [g_window.object collectionBehavior];
behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
[g_window.object setCollectionBehavior:behavior];
// Enable/disable fullscreen
[g_window.object toggleFullScreen:nil];
@Shtille
Shtille / window_controller.mm
Created July 9, 2016 14:36
Creating fullscreen window, second way
@interface ShtilleEngineWindow : NSWindow
{
ShtilleEngineFullscreenWindow * fullscreenWindow;
}
- (void)goFullscreen;
- (void)goWindow;
@end
@implementation ShtilleEngineWindow
@Shtille
Shtille / number_of_tiles.cpp
Created July 13, 2016 14:41
Test program calculating number of tiles for a selected region
#include <iostream>
#include <cmath>
const int kMaxLod = 20;
const double GetMaxLatitude() { return 90.0; }
const double GetMinLatitude() { return -90.0; }
const double GetMaxLongitude() { return 180.0; }
const double GetMinLongitude() { return -180.0; }
template <typename T>
@echo off
set src_folder=c:\source
set dst_folder=c:\destination
for /F "tokens=*" %%F in (list.txt) DO (
xcopy "%src_folder%\%%~nxF*" "%dst_folder%\" /S /Y
)
@Shtille
Shtille / make_pot_bitmap_from_npot.cpp
Created December 9, 2016 13:37
Make POT bitmap from NPOT bitmap using bilinear interpolation
template <typename T>
static T RoundToPowerOfTwo(T x)
{
T n = 1;
while (n < x)
n <<= 1;
return n;
}
static int InterpolateColor(int c1, int c2, float alpha)
{
static constexpr uint32_t crc_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
// Example program
#include <iostream>
#include <string>
#include <cmath>
struct vec3 {
vec3(float x) : x(x), y(x), z(x) {}
vec3(float x, float y, float z) : x(x), y(y), z(z) {}
vec3 operator +(const vec3& v) const { return vec3(x + v.x, y + v.y, z + v.z); }
vec3 operator -(const vec3& v) const { return vec3(x - v.x, y - v.y, z - v.z); }