opengl

Sample code from LearnOpenGL.com
Log | Files | Refs

glm_test.c (1168B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include "glm.h"
      6 #include "err.h"
      7 
      8 int vecAddTest();
      9 int vecEqTest();
     10 
     11 int
     12 main(void)
     13 {
     14 	if (vecEqTest() < 0)
     15 		fprintf(stderr, "vecEqTest: %s\n", errstr);
     16 	if (vecAddTest() < 0)
     17 		fprintf(stderr, "vecAddTest: %s\n", errstr);
     18 	return 0;
     19 }
     20 
     21 int
     22 vecEqTest()
     23 {
     24 	float data0[] = {1.0, 2.0, 3.0, 4.0};
     25 	float data1[] = {1.0, 2.0, 3.0, 4.0};
     26 	vec *v = vecMake(data0, 4);
     27 	vec *w = vecMake(data1, 4);
     28 	char s[2][256];
     29 	if (!vecEq(v, w)) {
     30 		errorf("%s != %s", vecStr(s[0], v), vecStr(s[1], w));
     31 		return -1;
     32 	}
     33 	vecFree(v);
     34 	v = vecMake(data0, 3);
     35 	if (vecEq(v, w)) {
     36 		errorf("%s != %s", vecStr(s[0], v), vecStr(s[1], w));
     37 		return -1;
     38 	}
     39 	return 0;
     40 }
     41 
     42 int
     43 vecAddTest()
     44 {
     45 	float data0[] = {1.0, 2.0, 3.0};
     46 	float data1[] = {2.0, 4.0, 6.0};
     47 	vec *v0 = vecMake(data0, 3);
     48 	vec *v = vecMake(data0, 3);
     49 	vec *w = vecMake(data1, 3);
     50 	vecAdd(v, w);
     51 	for (int i = 0; i < 3; i++) {
     52 		data0[i] += data1[i];
     53 	}
     54 	vec *u = vecMake(data0, 3);
     55 	char s[4][256];
     56 	if (vecEq(v, u))
     57 		return 0;
     58 	else {
     59 		errorf("%s + %s = %s, want: %s",
     60 			vecStr(s[0], v0), vecStr(s[1], w),
     61 			vecStr(s[2], v), vecStr(s[3], u));
     62 		return -1;
     63 	}
     64 }