libresman
diff examples/imgthumbs/src/thumbs.c @ 12:84f55eab27cb
ok now it sortof works, probably something is failing in the done callback mechanism
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 08 Feb 2014 04:21:08 +0200 |
parents | bebc065a941f |
children | a42888d26839 |
line diff
1.1 --- a/examples/imgthumbs/src/thumbs.c Fri Feb 07 07:50:02 2014 +0200 1.2 +++ b/examples/imgthumbs/src/thumbs.c Sat Feb 08 04:21:08 2014 +0200 1.3 @@ -67,7 +67,7 @@ 1.4 1.5 node->aspect = 1.0;/*(float)xsz / (float)ysz;*/ 1.6 1.7 - resman_lookup(texman, node->fname, 0); 1.8 + resman_lookup(texman, node->fname, node); 1.9 1.10 /*if(!(pixels = img_load_pixels(node->fname, &xsz, &ysz, IMG_FMT_RGBA32))) { 1.11 free(node->fname); 1.12 @@ -131,11 +131,6 @@ 1.13 glMatrixMode(GL_MODELVIEW); 1.14 1.15 while(thumbs) { 1.16 - if(!thumbs->tex) { 1.17 - thumbs = thumbs->next; 1.18 - continue; 1.19 - } 1.20 - 1.21 glPushMatrix(); 1.22 glTranslatef(x, y, 0); 1.23 1.24 @@ -149,28 +144,34 @@ 1.25 glTexCoord2f(0, 1); glVertex2f(0, 1); 1.26 glEnd(); 1.27 1.28 - if(thumbs->aspect >= 1.0) { 1.29 - glTranslatef(0, 0.5 - 0.5 / thumbs->aspect, 0); 1.30 - glScalef(1, 1.0 / thumbs->aspect, 1); 1.31 - } else { 1.32 - glTranslatef(0.5 - thumbs->aspect / 2.0, 0, 0); 1.33 - glScalef(thumbs->aspect, 1, 1); 1.34 + if(thumbs->tex) { 1.35 + if(thumbs->aspect >= 1.0) { 1.36 + glTranslatef(0, 0.5 - 0.5 / thumbs->aspect, 0); 1.37 + glScalef(1, 1.0 / thumbs->aspect, 1); 1.38 + } else { 1.39 + glTranslatef(0.5 - thumbs->aspect / 2.0, 0, 0); 1.40 + glScalef(thumbs->aspect, 1, 1); 1.41 + } 1.42 + 1.43 + if(glIsTexture(thumbs->tex)) { 1.44 + glEnable(GL_TEXTURE_2D); 1.45 + glBindTexture(GL_TEXTURE_2D, thumbs->tex); 1.46 + 1.47 + glBegin(GL_QUADS); 1.48 + glColor3f(1, 1, 1); 1.49 + glTexCoord2f(0, 0); glVertex2f(0, 0); 1.50 + glTexCoord2f(1, 0); glVertex2f(1, 0); 1.51 + glTexCoord2f(1, 1); glVertex2f(1, 1); 1.52 + glTexCoord2f(0, 1); glVertex2f(0, 1); 1.53 + glEnd(); 1.54 + } else { 1.55 + fprintf(stderr, "invalid texture: %u\n", thumbs->tex); 1.56 + } 1.57 + 1.58 + glPopMatrix(); 1.59 + glDisable(GL_TEXTURE_2D); 1.60 } 1.61 1.62 - glEnable(GL_TEXTURE_2D); 1.63 - glBindTexture(GL_TEXTURE_2D, thumbs->tex); 1.64 - 1.65 - glBegin(GL_QUADS); 1.66 - glColor3f(1, 1, 1); 1.67 - glTexCoord2f(0, 0); glVertex2f(0, 0); 1.68 - glTexCoord2f(1, 0); glVertex2f(1, 0); 1.69 - glTexCoord2f(1, 1); glVertex2f(1, 1); 1.70 - glTexCoord2f(0, 1); glVertex2f(0, 1); 1.71 - glEnd(); 1.72 - 1.73 - glPopMatrix(); 1.74 - glDisable(GL_TEXTURE_2D); 1.75 - 1.76 thumbs->layout_pos[0] = x; 1.77 thumbs->layout_pos[1] = y; 1.78 thumbs->layout_size[0] = thumb_sz; 1.79 @@ -192,8 +193,7 @@ 1.80 1.81 static int load_res_texture(const char *fname, int id, void *cls) 1.82 { 1.83 - struct resman *rman = cls; 1.84 - struct thumbnail *rdata = resman_get_res_data(rman, id); 1.85 + struct thumbnail *rdata = resman_get_res_data(texman, id); 1.86 1.87 assert(rdata); 1.88 if(!rdata->img) { 1.89 @@ -202,7 +202,7 @@ 1.90 } 1.91 } 1.92 1.93 - if(!img_load(rdata->img, fname) == -1) { 1.94 + if(img_load(rdata->img, fname) == -1) { 1.95 img_free(rdata->img); 1.96 return -1; 1.97 } 1.98 @@ -210,21 +210,20 @@ 1.99 1.100 /* set the resource's data to the loaded image, so that we can use 1.101 * it in the done callback */ 1.102 - resman_set_res_data(rman, id, rdata); 1.103 + resman_set_res_data(texman, id, rdata); 1.104 return 0; 1.105 } 1.106 1.107 static int done_res_texture(int id, void *cls) 1.108 { 1.109 struct thumbnail *rdata; 1.110 - struct resman *rman = cls; 1.111 1.112 - rdata = resman_get_res_data(rman, id); 1.113 + rdata = resman_get_res_data(texman, id); 1.114 1.115 - if(resman_get_res_result(rman, id) != 0 || !rdata) { 1.116 - fprintf(stderr, "failed to load resource %d (%s)\n", id, resman_get_res_name(rman, id)); 1.117 + if(resman_get_res_result(texman, id) != 0 || !rdata) { 1.118 + fprintf(stderr, "failed to load resource %d (%s)\n", id, resman_get_res_name(texman, id)); 1.119 } else { 1.120 - printf("done loading resource %d (%s)\n", id, resman_get_res_name(rman, id)); 1.121 + printf("done loading resource %d (%s)\n", id, resman_get_res_name(texman, id)); 1.122 } 1.123 1.124 if(!rdata->tex) { 1.125 @@ -241,8 +240,7 @@ 1.126 1.127 static void free_res_texture(int id, void *cls) 1.128 { 1.129 - struct resman *rman = cls; 1.130 - struct thumbnail *rdata = resman_get_res_data(rman, id); 1.131 + struct thumbnail *rdata = resman_get_res_data(texman, id); 1.132 1.133 if(rdata) { 1.134 if(rdata->tex) {