src/primitives.c

changeset 115
e5f8c99b0987
parent 114
5b91bbab1ac0
child 116
bfb2a7d62047
equal deleted inserted replaced
114:5b91bbab1ac0 115:e5f8c99b0987
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * Copyright 2023 Mike Becker. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "ascension/primitives.h"
29 #include "ascension/error.h"
30
31 #include <GL/glew.h>
32
33 void asc_primitives_init_plane(AscMesh *mesh) {
34 if (mesh->vbo == 0) {
35 if (mesh->vao > 0) {
36 asc_dprintf("!!! Mesh with VAO %u has no VBO - this is most likely a programming error !!!", mesh->vao);
37 }
38 asc_mesh_allocate_buffers(mesh, 1);
39 }
40 asc_dprintf("Create plane in VBO %u and VAO %u", mesh->vbo, mesh->vao);
41 mesh->vertices = 4;
42 float data[8] = {
43 0.0f, 0.0f, // bottom left
44 0.0f, 1.0f, // top left
45 1.0f, 0.0f, // bottom right
46 1.0f, 1.0f // top right
47 };
48 glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
49 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
50 glBindVertexArray(mesh->vao);
51 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
52 glEnableVertexAttribArray(0);
53 }

mercurial