Sat, 19 Apr 2025 15:06:24 +0200
make asset paths configurable
3 | 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 | ||
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
28 | #include "ascension/primitives.h" |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
29 | #include "ascension/error.h" |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
30 | #include "ascension/context.h" |
3 | 31 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
32 | #include <GL/glew.h> |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
33 | |
81
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
34 | void asc_primitives_init_plane(AscMesh *mesh) { |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
35 | if (mesh->vbo == 0) { |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
36 | if (mesh->vao > 0) { |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
37 | asc_dprintf("!!! Mesh with VAO %u has no VBO - this is most likely a programming error !!!", mesh->vao); |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
38 | } |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
39 | asc_mesh_allocate_buffers(mesh, 1); |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
40 | } |
84a546e282b7
create catch-all util for GL errors + refactors mesh creation
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
41 | asc_dprintf("Create plane in VBO %u and VAO %u", mesh->vbo, mesh->vao); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
42 | mesh->vertices = 4; |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
43 | float data[8] = { |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
44 | 0.0f, 0.0f, // bottom left |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
45 | 0.0f, 1.0f, // top left |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
46 | 1.0f, 0.0f, // bottom right |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
47 | 1.0f, 1.0f // top right |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
48 | }; |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
49 | glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
50 | glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
51 | glBindVertexArray(mesh->vao); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
52 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
53 | glEnableVertexAttribArray(0); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
54 | } |