deepstone

annotate src/texture.c @ 3:0e781cc43178

adding textures
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 21 Nov 2011 10:16:09 +0200
parents
children c3e0bccd673e
rev   line source
nuclear@3 1 /*
nuclear@3 2 256-color 3D graphics hack for real-mode DOS.
nuclear@3 3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
nuclear@3 4
nuclear@3 5 This program is free software: you can redistribute it and/or modify
nuclear@3 6 it under the terms of the GNU General Public License as published by
nuclear@3 7 the Free Software Foundation, either version 3 of the License, or
nuclear@3 8 (at your option) any later version.
nuclear@3 9
nuclear@3 10 This program is distributed in the hope that it will be useful,
nuclear@3 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@3 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@3 13 GNU General Public License for more details.
nuclear@3 14
nuclear@3 15 You should have received a copy of the GNU General Public License
nuclear@3 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@3 17 */
nuclear@3 18
nuclear@3 19 #include <stdlib.h>
nuclear@3 20 #include "texture.h"
nuclear@3 21 #include "palman.h"
nuclear@3 22
nuclear@3 23 struct texture *tex_load(const char *fname)
nuclear@3 24 {
nuclear@3 25 return 0; /* TODO */
nuclear@3 26 }
nuclear@3 27
nuclear@3 28 struct texture *tex_gen_checker(int xsz, int ysz, int ush, int vsh, int c1, int c2)
nuclear@3 29 {
nuclear@3 30 int i, j;
nuclear@3 31 struct texture *tex;
nuclear@3 32 unsigned char *pptr;
nuclear@3 33
nuclear@3 34 if(!(tex = malloc(sizeof *tex))) {
nuclear@3 35 return 0;
nuclear@3 36 }
nuclear@3 37 if(!(tex->pixels = malloc(xsz * ysz))) {
nuclear@3 38 free(tex);
nuclear@3 39 return 0;
nuclear@3 40 }
nuclear@3 41 tex->width = xsz;
nuclear@3 42 tex->height = ysz;
nuclear@3 43
nuclear@3 44 pptr = tex->pixels;
nuclear@3 45 for(i=0; i<ysz; i++) {
nuclear@3 46 for(j=0; j<xsz; j++) {
nuclear@3 47 int c = ((i >> vsh) & 1) == ((j >> ush) & 1) ? c1 : c2;
nuclear@3 48 *pptr++ = c;
nuclear@3 49 }
nuclear@3 50 }
nuclear@3 51 return tex;
nuclear@3 52 }