15 load(GLenum target
, const char *filename
,
16 GLboolean flipTB
, GLboolean flipLR
)
20 GLubyte
*img
= LoadRGBImage( filename
, &w
, &h
, &format
);
22 printf("Error: couldn't load texture image %s\n", filename
);
25 assert(format
== GL_RGB
);
27 printf("Load cube face 0x%x: %s %d x %d\n", target
, filename
, w
, h
);
29 /* <sigh> the way the texture cube mapping works, we have to flip
30 * images to make things look right.
33 const int stride
= 3 * w
;
36 for (i
= 0; i
< h
/ 2; i
++) {
37 memcpy(temp
, img
+ i
* stride
, stride
);
38 memcpy(img
+ i
* stride
, img
+ (h
- i
- 1) * stride
, stride
);
39 memcpy(img
+ (h
- i
- 1) * stride
, temp
, stride
);
43 const int stride
= 3 * w
;
47 for (i
= 0; i
< h
; i
++) {
48 row
= img
+ i
* stride
;
49 for (j
= 0; j
< w
/ 2; j
++) {
54 row
[j
*3+0] = row
[k
*3+0];
55 row
[j
*3+1] = row
[k
*3+1];
56 row
[j
*3+2] = row
[k
*3+2];
64 gluBuild2DMipmaps(target
, GL_RGB
, w
, h
, format
, GL_UNSIGNED_BYTE
, img
);
71 LoadSkyBoxCubeTexture(const char *filePosX
,
80 glGenTextures(1, &tex
);
81 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
83 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
84 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MIN_FILTER
,
85 GL_LINEAR_MIPMAP_NEAREST
);
87 if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_X
, filePosX
, GL_TRUE
, GL_TRUE
))
89 if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_X
, fileNegX
, GL_TRUE
, GL_TRUE
))
91 if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, filePosY
, GL_TRUE
, GL_TRUE
))
93 if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
, fileNegY
, GL_TRUE
, GL_TRUE
))
95 if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, filePosZ
, GL_TRUE
, GL_TRUE
))
97 if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, fileNegZ
, GL_TRUE
, GL_TRUE
))
105 #define br 20.0 /* box radius */
108 DrawSkyBoxCubeTexture(GLuint tex
)
111 float x
, y
, z
, s
, t
, r
;
114 static const struct vertex verts
[24] = {
116 { br
, -br
, -br
, 1.0, -eps1
, -eps1
},
117 { br
, -br
, br
, 1.0, -eps1
, eps1
},
118 { br
, br
, br
, 1.0, eps1
, eps1
},
119 { br
, br
, -br
, 1.0, eps1
, -eps1
},
122 { -br
, br
, -br
, -1.0, eps1
, -eps1
},
123 { -br
, br
, br
, -1.0, eps1
, eps1
},
124 { -br
, -br
, br
, -1.0, -eps1
, eps1
},
125 { -br
, -br
, -br
, -1.0, -eps1
, -eps1
},
128 { br
, br
, -br
, eps1
, 1.0, -eps1
},
129 { br
, br
, br
, eps1
, 1.0, eps1
},
130 { -br
, br
, br
, -eps1
, 1.0, eps1
},
131 { -br
, br
, -br
, -eps1
, 1.0, -eps1
},
134 { -br
, -br
, -br
, -eps1
, -1.0, -eps1
},
135 { -br
, -br
, br
, -eps1
, -1.0, eps1
},
136 { br
, -br
, br
, eps1
, -1.0, eps1
},
137 { br
, -br
, -br
, eps1
, -1.0, -eps1
},
140 { br
, -br
, br
, eps1
, -eps1
, 1.0 },
141 { -br
, -br
, br
, -eps1
, -eps1
, 1.0 },
142 { -br
, br
, br
, -eps1
, eps1
, 1.0 },
143 { br
, br
, br
, eps1
, eps1
, 1.0 },
146 { br
, br
, -br
, eps1
, eps1
, -1.0 },
147 { -br
, br
, -br
, -eps1
, eps1
, -1.0 },
148 { -br
, -br
, -br
, -eps1
, -eps1
, -1.0 },
149 { br
, -br
, -br
, eps1
, -eps1
, -1.0 },
152 static GLuint vbo
= 0;
155 glGenBuffersARB(1, &vbo
);
156 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vbo
);
157 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
161 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vbo
);
164 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
166 glVertexPointer(3, GL_FLOAT
, sizeof(struct vertex
),
167 (void *) offsetof(struct vertex
, x
));
168 glTexCoordPointer(3, GL_FLOAT
, sizeof(struct vertex
),
169 (void *) offsetof(struct vertex
, s
));
170 glEnableClientState(GL_VERTEX_ARRAY
);
171 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
173 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
174 glEnable(GL_TEXTURE_CUBE_MAP
);
178 glDrawArrays(GL_QUADS
, 0, 24);
180 glDisable(GL_TEXTURE_CUBE_MAP
);
182 glDisableClientState(GL_VERTEX_ARRAY
);
183 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
185 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, 0);