commit 68f5dde29344d90b5b80309112882e9d1d4a380e
parent f4c87b5a1ae882272b28946a3b3723d90ef7cb94
Author: bsandro <email@bsandro.tech>
Date: Thu, 20 Nov 2025 21:57:52 +0200
kept only astc support for (future) cube
Diffstat:
| M | cube.c | | | 36 | +++++++----------------------------- |
1 file changed, 7 insertions(+), 29 deletions(-)
diff --git a/cube.c b/cube.c
@@ -90,29 +90,6 @@ static GLuint linkProgram(GLuint vertex, GLuint fragment) {
return shaderProgram;
}
-static GLuint mkTexture(const char *filename) {
- GLuint tex;
- glGenTextures(1, &tex);
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- int w, h, numchan;
- //stbi_set_flip_vertically_on_load(1);
- uint8_t *data = stbi_load(filename, &w, &h, &numchan, 3);
- if (data) {
- printf("texture %dx%d %dbpp\n", w, h, numchan*8);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
- glGenerateMipmap(GL_TEXTURE_2D);
- glEnable(GL_TEXTURE_2D);
- stbi_image_free(data);
- } else {
- printf("Failed to load texture %s: %s\n", filename, stbi_failure_reason());
- }
- return tex;
-}
-
void __attribute__((constructor)) start() {
printf("start()\n");
@@ -141,17 +118,18 @@ void __attribute((destructor)) end() {
int main(int argc, char *argv[]) {
const char *tex_fname;
- bool is_astc = false;
if (argc>1) {
tex_fname = argv[1];
int len = strlen(tex_fname);
// ".astc" extension = 5 bytes
- is_astc = (len>ASTC_LEN&&strncmp(tex_fname+len-ASTC_LEN, ASTC_EXT, ASTC_LEN)==0);
+ if (len<ASTC_LEN || strncmp(tex_fname+len-ASTC_LEN, ASTC_EXT, ASTC_LEN)!=0) {
+ printf("only .astc textures are supported\n");
+ exit(-1);
+ }
} else {
tex_fname = "hina.astc";
- is_astc = true;
}
- printf("texture file: %s (%s)\n", tex_fname, is_astc ? "astc" : "plain");
+ printf("texture file: %s\n", tex_fname);
Display *dpy = XOpenDisplay(NULL);
XSetWindowAttributes swa;
@@ -196,7 +174,7 @@ int main(int argc, char *argv[]) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
- // @todo geh
+ // @todo geh some astc stuff I haven't figured out
const GLfloat c = 0; //0.099f;
// x,y,tx,ty
@@ -230,7 +208,7 @@ int main(int argc, char *argv[]) {
printf("shader link status: %s\n", prgStatus == GL_TRUE ? "ok" : "error");
// texture
- GLuint tex = is_astc ? mkTextureAstc(tex_fname) : mkTexture(tex_fname);
+ GLuint tex = mkTextureAstc(tex_fname);
GLint position = glGetAttribLocation(shaderPrg, "position");
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void *)0);
glEnableVertexAttribArray(position);