File: quad.c

package info (click to toggle)
gltron 0.61-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,948 kB
  • ctags: 1,175
  • sloc: ansic: 7,580; perl: 168; makefile: 149; sh: 15
file content (79 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "quad.h"

/* see quad.h for more information */

void q_setColor4fv( Quad *q, int index, float color[4]) {
  memcpy(q->vertex[index].color, color, 4 * sizeof(float));
}

void q_setColor4f( Quad *q, int index, float r, float g, float b, float a) {
  q->vertex[index].color[0] = r;
  q->vertex[index].color[1] = g;
  q->vertex[index].color[2] = b;
  q->vertex[index].color[3] = a;
}

void q_setColor3f( Quad *q, int index, float r, float g, float b) {
  q_setColor4f( q, index, r, g, b, 1.0);
}

void q_setTexCoord2f( Quad *q, int index, float u, float v ) {
  q->vertex[index].uv[0] = u;
  q->vertex[index].uv[1] = v;
}

void q_setVertex3f( Quad *q, int index, float x, float y, float z) {
  q->vertex[index].v[0] = x;
  q->vertex[index].v[1] = y;
  q->vertex[index].v[2] = z;
}

QuadBuffer* createQuadBuffer(int size) {
  QuadBuffer *q;
  q = (QuadBuffer*) malloc(sizeof(struct QuadBuffer));
  if(q != NULL) {
    q->quads = (Quad*) malloc(sizeof(struct Quad) * size);
    if(q->quads != 0) {
      q->size = size;
      q->current = 0;
      return q;
    } else free(q);
  }
  fprintf(stderr, "failed to allocate quad buffer\n");
  exit(2);
}

void freeQuadBuffer(QuadBuffer *q) {
  free(q->quads);
  free(q);
}

extern Quad *getNextQuad(QuadBuffer *q) {
  if(q->current < q->size)
    return q->quads + q->current++;
  else {
    fprintf(stderr, "quad buffer overflow!\n");
    return NULL;
  }
}

int getCurrentQuad(QuadBuffer *q) {
  return q->current;
}


int getQuadBufferSize(QuadBuffer *q) {
  return q->size;
}

void q_setType(Quad *q, int type) {
  q->type = type;
}

Quad* getQuadAt(QuadBuffer *q, int index) {
  return q->quads + index;
}

void renderQuadAt(QuadBuffer *q, int* index, int i) {
  renderQuad(q->quads + index[i]);
}