124 lines
3.4 KiB
C++
124 lines
3.4 KiB
C++
/*
|
|
Copyright 2013 Peter Nelson
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
#include <cstdlib>
|
|
#include <cmath>
|
|
#include <pugl/pugl.h>
|
|
#include "pui.h"
|
|
|
|
#include "textures/sliders.c"
|
|
#include "textures/buttons.c"
|
|
|
|
#include "textures/knob.c"
|
|
#include "textures/knob-prelight.c"
|
|
#include "textures/knob-selector.c"
|
|
|
|
#include "font/vera.h"
|
|
|
|
void PTextures::BindTexture(int texture, int width, int height, const unsigned char *data, int format)
|
|
{
|
|
glBindTexture(GL_TEXTURE_2D, tex[texture]);
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
|
|
|
w[texture] = width;
|
|
h[texture] = height;
|
|
}
|
|
|
|
void PTextures::InitTextures()
|
|
{
|
|
if (initialised) return;
|
|
initialised = true;
|
|
|
|
glGenTextures(TEX_END, this->tex);
|
|
|
|
/* Texture buffer for generated textures */
|
|
int size = 128;
|
|
w[TEX_BACKTILE] = h[TEX_BACKTILE] = size;
|
|
uint8_t *buffer = new uint8_t[size * size];
|
|
|
|
/* Create background tile */
|
|
for (int i = 0; i < size * size; i++) {
|
|
/* Normalised noise */
|
|
int r = 0;
|
|
for (int j = 0; j < 4; j++) r += (rand() & 0x1F);
|
|
buffer[i] = (r >> 2) + 0x30;
|
|
}
|
|
BindTexture(TEX_BACKTILE, size, size, buffer, GL_LUMINANCE);
|
|
|
|
/* Create brushed background tile */
|
|
for (int i = 0; i < size * size; i++) {
|
|
buffer[i] = (rand() & 0x3F) + 0x80;
|
|
// buffer[i] += 0x20 * sin(((i + 0 / size) % size) * M_PI / size);
|
|
}
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
uint8_t *row = &buffer[i * size];
|
|
uint8_t tmp[size];
|
|
for (int j = 0; j < size; j++) {
|
|
uint16_t t = 0;
|
|
for (int k = 0; k < 19; k++) {
|
|
t += row[(j + k) % size];
|
|
}
|
|
tmp[j] = t / 19;
|
|
}
|
|
memcpy(row, tmp, size);
|
|
}
|
|
BindTexture(TEX_BACKTILE2, size, size, buffer, GL_LUMINANCE);
|
|
|
|
/* Create glow, focused at 1/3 down the window */
|
|
int cx = size / 2;
|
|
int cy = size / 3;
|
|
for (int y = 0; y < size; y++) {
|
|
for (int x = 0; x < size; x++) {
|
|
float b = 196 - sqrtf((cx - x) * (cx - x) + (cy - y) * (cy - y)) * 256 / size;
|
|
if (b < 0) b = 0;
|
|
buffer[x + y * size] = b;
|
|
}
|
|
}
|
|
BindTexture(TEX_BACKGLOW, size, size, buffer, GL_LUMINANCE);
|
|
|
|
delete[] buffer;
|
|
|
|
BindTexture(TEX_SLIDERS,
|
|
sliders.width,
|
|
sliders.height,
|
|
sliders.pixel_data);
|
|
|
|
BindTexture(TEX_BUTTONS,
|
|
buttons.width,
|
|
buttons.height,
|
|
buttons.pixel_data);
|
|
|
|
BindTexture(TEX_KNOB,
|
|
knob.width,
|
|
knob.height,
|
|
knob.pixel_data);
|
|
BindTexture(TEX_KNOB_PRE,
|
|
knob_prelight.width,
|
|
knob_prelight.height,
|
|
knob_prelight.pixel_data);
|
|
BindTexture(TEX_KNOB_SEL,
|
|
knob_selector.width,
|
|
knob_selector.height,
|
|
knob_selector.pixel_data);
|
|
|
|
this->font = new FTTextureFont(font_Vera_ttf, font_Vera_ttf_len);
|
|
this->font->FaceSize(20);
|
|
}
|