one thing that i think that would be extremely helpful to anyone that is starting to try to add new features to the engine was commenting the engine source code. another thing i don't really understand is why is a cross platform engine supporting a broken and non cross platform api such has directx, the way i see it is only slowing down development, has u have to maintain 3 versions of an api that only works for windows it's a wast of time since opengl can do anything dx can and will work on every platform not only that i see ppl asking of dx10 because of geometry shaders... (only vista will benefit from that for windows xp the only way u'll ever get geometry shaders is using opengl) opengl already supports geometry shaders on opengl2.1 besides theres also another problem, the only way a new feature goes mainstream is if it is supported by all drivers, that said irr ill be missing allot of features for a long time since at least 4 implementations of the feature will have to be made (dx7 dx8 dx9 and opengl) we could already have cube mapping or projective shadows or better yet cube shadow mapping if we only needed to do it once (ex: cube mapping is supported in opengl1.3 using fixed functions) i consider a good shadow system more important than bloom o any other high lvl shader and i'd rather have a good and fast shadow system than parallax.
this is a nvidia demo i changed to work with arb instead of ext extensions so it would work on my old radeon 9100 igp
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <GL/glut.h>
/* In case your <GL/gl.h> does not advertise ARB_texture_cube_map... */
#ifndef GL_ARB_texture_cube_map
# define GL_NORMAL_MAP_ARB 0x8511
# define GL_REFLECTION_MAP_ARB 0x8512
# define GL_TEXTURE_CUBE_MAP_ARB 0x8513
# define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
# define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
# define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
# define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
# define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
# define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
# define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A
# define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B
# define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C
#endif
/* constants */
#ifndef M_PI
#define M_PI (3.14159265358979f)
#endif
#define DTOR (M_PI/180.0)
#define RTOD (180.0/M_PI)
#define CUBE_MAP_SIZE 256
#define ZTRANS 4.0F
int exitAfterOneFrame = 0;
enum {CUBE_POS_X, CUBE_NEG_X, CUBE_POS_Y, CUBE_NEG_Y, CUBE_POS_Z, CUBE_NEG_Z};
static unsigned char CubeMap[6][CUBE_MAP_SIZE][CUBE_MAP_SIZE][4];
static void InitGraphics(void);
static void light_state(long, long);
static void DrawSphere(float);
static void vert(float, float);
static void
vert(float theta, float phi)
{
float r = 0.75f;
float x, y, z, nx, ny, nz;
nx = sin(DTOR * theta) * cos(DTOR * phi);
ny = sin(DTOR * phi);
nz = cos(DTOR * theta) * cos(DTOR * phi);
glNormal3f(nx, ny, nz);
x = r * sin(DTOR * theta) * cos(DTOR * phi);
y = r * sin(DTOR * phi);
z = -ZTRANS + r * cos(DTOR * theta) * cos(DTOR * phi);
glVertex4f(x, y, z, 1.0);
}
static void
DrawSphere(float del)
{
float phi, phi2, theta;
glColor4f(1.0, 1.0, 1.0, 1.0);
for (phi = -90.0f; phi < 90.0f; phi += del) {
glBegin(GL_TRIANGLE_STRIP);
phi2 = phi + del;
for (theta = -90.0f; theta <= 90.0f; theta += del) {
vert(theta, phi);
vert(theta, phi2);
}
glEnd();
}
}
static float
Dot3(float *a, float *b)
{
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
static float *
Scale3(float *result, float *a, float scale)
{
result[0] = a[0] * scale;
result[1] = a[1] * scale;
result[2] = a[2] * scale;
return result;
}
static float *
Normalize3(float *result, float *a)
{
float length;
length = (float) sqrt(Dot3(a, a));
return Scale3(result, a, 1 / length);
}
static unsigned char *
CubeFunc(unsigned char resultColor[3], float vec[3])
{
int i;
float faceVec[3];
if (vec[0] == 1.0) {
resultColor[0] = 255;
resultColor[1] = 0;
resultColor[2] = 0;
} else if (vec[1] == 1.0) {
resultColor[0] = 0;
resultColor[1] = 255;
resultColor[2] = 0;
} else if (vec[2] == 1.0) {
resultColor[0] = 0;
resultColor[1] = 0;
resultColor[2] = 255;
} else if (vec[0] == -1.0) {
resultColor[0] = 255;
resultColor[1] = 0;
resultColor[2] = 255;
} else if (vec[1] == -1.0) {
resultColor[0] = 255;
resultColor[1] = 255;
resultColor[2] = 0;
} else if (vec[2] == -1.0) {
resultColor[0] = 0;
resultColor[1] = 255;
resultColor[2] = 255;
}
return resultColor;
Normalize3(faceVec, vec);
for (i = 0; i < 3; i++) {
resultColor[i] = 255 * (sin(6 * (faceVec[i] + faceVec[(i + 1) % 3])) + 1) / 2.0;
}
return resultColor;
}
GLenum cubefaces[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
};
static void
InitGraphics(void)
{
int i, j, k;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -0.75, 0.75, ZTRANS - 1.0, ZTRANS + 1.0); // match
// 640x480
glMatrixMode(GL_MODELVIEW);;
glLoadIdentity();
for (i = 0; i < CUBE_MAP_SIZE; i++) {
float t = 1.0 / (2 * CUBE_MAP_SIZE) + (float) i / CUBE_MAP_SIZE;
t = 2.0 * t - 1.0;
for (j = 0; j < CUBE_MAP_SIZE; j++) {
float s = 1.0 / (2 * CUBE_MAP_SIZE) + (float) j / CUBE_MAP_SIZE;
float pt[3];
s = 2.0 * s - 1.0;
pt[0] = 1;
pt[1] = t;
pt[2] = -s;
CubeFunc(CubeMap[CUBE_POS_X][i][j], pt);
pt[0] = -1;
pt[1] = t;
pt[2] = s;
CubeFunc(CubeMap[CUBE_NEG_X][i][j], pt);
pt[1] = 1;
pt[0] = s;
pt[2] = -t;
CubeFunc(CubeMap[CUBE_POS_Y][i][j], pt);
pt[1] = -1;
pt[0] = s;
pt[2] = t;
CubeFunc(CubeMap[CUBE_NEG_Y][i][j], pt);
pt[2] = 1;
pt[0] = s;
pt[1] = t;
CubeFunc(CubeMap[CUBE_POS_Z][i][j], pt);
pt[2] = -1;
pt[0] = -s;
pt[1] = t;
CubeFunc(CubeMap[CUBE_NEG_Z][i][j], pt);
for (k = CUBE_POS_X; k <= CUBE_NEG_Z; k++) {
CubeMap[k][i][j][3] = 255;
}
}
}
glEnable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
for (i = 0; i < 6; i++) {
glTexImage2D(
cubefaces[i],
0, // level
GL_RGBA8, // internal format
CUBE_MAP_SIZE, // width
CUBE_MAP_SIZE, // height
0, // border
GL_RGBA, // format
GL_UNSIGNED_BYTE, // type
CubeMap[CUBE_POS_X + i]); // pixel data
}
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_NORMALIZE);
}
static void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawSphere(9.0);
glutSwapBuffers();
if (exitAfterOneFrame) {
exit(0);
}
}
static void
keyboard(unsigned char c, int x, int y)
{
switch (c) {
case 27:
exit(0);
break;
case ' ': /* Space bar redraws. */
glutPostRedisplay();
break;
}
}
int
main(int argc, char **argv)
{
int i;
glutInitWindowSize(640, 480);
glutInit(&argc, argv);
for (i = 1; i < argc; i++) {
if (!strcmp("-e", argv[i])) {
exitAfterOneFrame = 1;
}
}
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
glutCreateWindow("cubemap");
/* Run-time extension check. */
if (!glutExtensionSupported("GL_ARB_texture_cube_map")) {
fprintf(stderr,
"cubemap: Requires the ARB_texture_cube_map OpenGL extension to run.\n");
exit(0);
}
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
InitGraphics();
glutMainLoop();
return 0;
}
(i didn't posted the demo with the textures and the reflective pot because u can easily find it on nvidia and the modifications are the same replace all EXT with ARB)
i think it would be great to get this in the engine with this it would be possible to mix blindside's xeffects with his virtual cube map code to get cube shadow mapping, and also get better reflections. the only problem is dx, i have no idea how we could get the same for lets say dx7 or dx8 with fixed functions, neither i know why ppl bother. i never saw anyone complaining about return to castel wolfenstein or unreal tornument 2004 being opengl. i thing dx is like a fashion everybody love it and don't even know why. (i gess it can be easyer on some parts for programmers but at what cost???)