util.h (1445B)
1 /* Copyright 2013 Brian Swetland <swetland@frotz.net> 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _UTIL_H_ 17 #define _UTIL_H_ 18 19 /* file io helpers */ 20 void *load_png_rgba(const char *fn, unsigned *width, unsigned *height, int texture); 21 void *load_png_gray(const char *fn, unsigned *width, unsigned *height, int texture); 22 void *load_file(const char *fn, unsigned *sz); 23 24 int save_png_rgba(const char *fn, void *data, unsigned width, unsigned height); 25 int save_png_gray(const char *fn, void *data, unsigned width, unsigned height); 26 27 /* model helpers */ 28 29 struct model { 30 float *vdata; /* { vertex[3], normal[3], texcoord[2] } * vcount */ 31 unsigned short *idx; 32 unsigned vcount; 33 unsigned icount; 34 }; 35 36 struct model *load_wavefront_obj(const char *fn); 37 38 /* simplex noise */ 39 float snoise(float x); 40 float snoise(float x, float y); 41 float snoise(float x, float y, float z); 42 float snoise(float x, float y, float z, float w); 43 44 #endif 45