void main()
{
vec3 texel = texture2D(tex, gl_TexCoord[0].st).xyz;
- vec3 color = pow(texel * grid_color, vec3(0.75)) * 2.0;
+ vec3 color = pow(texel * grid_color, vec3(0.76)) * 5.0;
float dist = abs(vpos.z);
- float fog = 1.0 - exp(-dist * 0.11);
+ float fog = 1.0 - exp(-dist * 0.12);
float t = clamp(fog, 0.0, 1.0);
gl_FragColor.xyz = mix(color, fog_color, t);
{
gl_Position = ftransform();
vpos = (gl_ModelViewMatrix * gl_Vertex).xyz;
- gl_TexCoord[0].xy = gl_Vertex.xz * 500.0;
+ gl_TexCoord[0].xy = gl_Vertex.xz * 330.0;
}
int win_width, win_height;
float win_aspect;
long time_msec;
+Mat4 view_matrix;
static bool use_vr;
static bool should_swap;
glGetIntegerv(GL_SAMPLES, &aasamples);
printf("got %d samples per pixel\n", aasamples);
+ printf("Max anisotropy: %d\n", glcaps.max_aniso);
+
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(goatvr_projection_matrix(i, 0.5, 1000.0));
- Mat4 view_mat = goatvr_view_matrix(i);
- view_mat.pre_rotate_x(deg_to_rad(cam_phi));
- view_mat.pre_rotate_y(deg_to_rad(cam_theta));
- view_mat.pre_translate(0, -cam_height, 0);
+ view_matrix = goatvr_view_matrix(i);
+ view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
+ view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
+ view_matrix.pre_translate(0, -cam_height, 0);
glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(view_mat[0]);
+ glLoadMatrixf(view_matrix[0]);
draw_backdrop();
}
// regular monoscopic mode
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- Mat4 view_mat;
- view_mat.pre_rotate_x(deg_to_rad(cam_phi));
- view_mat.pre_rotate_y(deg_to_rad(cam_theta));
- view_mat.pre_translate(0, -cam_height, 0);
+ view_matrix = Mat4::identity;
+ view_matrix.pre_rotate_x(deg_to_rad(cam_phi));
+ view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
+ view_matrix.pre_translate(0, -cam_height, 0);
glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(view_mat[0]);
+ glLoadMatrixf(view_matrix[0]);
draw_backdrop();
#ifndef APP_H_
#define APP_H_
+#include "gmath/gmath.h"
+
extern int win_width, win_height;
extern float win_aspect;
extern long time_msec;
+extern Mat4 view_matrix;
+
+
bool app_init(int argc, char **argv);
void app_cleanup();
#include "mesh.h"
#include "meshgen.h"
#include "backdrop.h"
+#include "app.h"
static unsigned int sdr_grid;
static Texture *tex_grid;
static Mesh *mesh_skydome;
static unsigned int sdr_skydome;
-static const Vec3 grid_color = Vec3(1.0, 0.3, 1.0);
-static const Vec3 mid_color = Vec3(0.4, 0.1, 0.8);
-static const Vec3 horiz_color = Vec3(0.8, 0.1, 1.0);
-static const Vec3 zenith_color = Vec3(0.2, 0.2, 0.2);
-static const Vec3 fog_color = Vec3(0.12, 0.12, 0.12);
+static const Vec3 grid_color = Vec3(1.0, 0.07, 1.0);
+static const Vec3 mid_color = Vec3(0.133, 0.006, 0.612);
+static const Vec3 horiz_color = Vec3(0.612, 0.006, 1.0);
+static const Vec3 zenith_color = Vec3(0.029, 0.029, 0.029);
+static const Vec3 fog_color = Vec3(0.01, 0.01, 0.01);
bool init_backdrop()
{
delete tex_grid;
return false;
}
+ tex_grid->set_anisotropy(glcaps.max_aniso);
mesh_skydome = new Mesh;
gen_sphere(mesh_skydome, 500.0, 32, 16, 1, 0.5);
mesh_skydome->flip();
+ glClearColor(fog_color.x, fog_color.y, fog_color.z, 1.0);
+
return true;
}
void draw_backdrop()
{
// draw sky
+ Mat4 view_mat_inf = view_matrix.upper3x3();
+ glPushMatrix();
+ glLoadMatrixf(view_mat_inf[0]);
+
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(0);
+
bind_program(sdr_skydome);
mesh_skydome->draw();
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(1);
+
+ glPopMatrix();
+
// draw grid
Mat4 xform;
xform.scaling(500.0);
+#include <string.h>
#include "opengl.h"
+struct GLCaps glcaps;
+
int init_opengl(void)
{
#ifdef __glew_h__
glewInit();
#endif
+
+ memset(&glcaps, 0, sizeof glcaps);
+ glcaps.shaders = GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader;
+ glcaps.fsaa = GLEW_ARB_multisample;
+ glcaps.fbo = GLEW_ARB_framebuffer_object;
+ glcaps.shadow = GLEW_ARB_shadow || GLEW_SGIX_shadow;
+ if(GLEW_EXT_texture_filter_anisotropic) {
+ glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glcaps.max_aniso);
+ }
+
return 0;
}
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#endif
+struct GLCaps {
+ int shaders;
+ int fsaa;
+ int fbo;
+ int shadow;
+ int max_aniso;
+};
+extern struct GLCaps glcaps;
+
+
#ifdef __cplusplus
extern "C" {
#endif
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filt);
}
+void Texture::set_anisotropy(int aniso)
+{
+ if(GLEW_EXT_texture_filter_anisotropic) {
+ glBindTexture(target, id);
+ glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
+ }
+}
+
unsigned int Texture::get_format() const
{
return texfmt;
switch(ifmt) {
case GL_LUMINANCE16F:
case GL_LUMINANCE32F:
+ case GL_SLUMINANCE:
return GL_LUMINANCE;
case GL_RGB16F:
case GL_RGB32F:
+ case GL_SRGB:
return GL_RGB;
case GL_RGBA16F:
case GL_RGBA32F:
+ case GL_SRGB_ALPHA:
return GL_RGBA;
default:
{
switch(fmt) {
case Image::FMT_GREY:
- return GL_LUMINANCE;
+ return GLEW_EXT_texture_sRGB ? GL_SLUMINANCE : GL_LUMINANCE;
+
case Image::FMT_GREY_FLOAT:
return GL_LUMINANCE16F;
+
case Image::FMT_RGB:
- return GL_RGB;
+ return GLEW_EXT_texture_sRGB ? GL_SRGB : GL_RGB;
+
case Image::FMT_RGB_FLOAT:
return GL_RGB16F;
+
case Image::FMT_RGBA:
- return GL_RGBA;
+ return GLEW_EXT_texture_sRGB ? GL_SRGB_ALPHA : GL_RGBA;
+
case Image::FMT_RGBA_FLOAT:
return GL_RGBA16F;
+
default:
break;
}
{
switch(ifmt) {
case GL_LUMINANCE:
+ case GL_SLUMINANCE:
return Image::FMT_GREY;
case GL_LUMINANCE16F:
return Image::FMT_GREY_FLOAT;
case GL_RGB:
+ case GL_SRGB:
return Image::FMT_RGB;
case GL_RGB16F:
return Image::FMT_RGB_FLOAT;
case GL_RGBA:
+ case GL_SRGB_ALPHA:
return Image::FMT_RGBA;
case GL_RGBA16F:
return Image::FMT_RGBA_FLOAT;
void set_wrapping(unsigned int wrap);
void set_filtering(unsigned int filt);
void set_filtering(unsigned int min_filt, unsigned int mag_filt);
+ void set_anisotropy(int aniso);
unsigned int get_format() const;