diff options
| author | arngo <[email protected]> | 2024-05-16 21:00:51 -0400 |
|---|---|---|
| committer | arngo <[email protected]> | 2024-05-16 21:00:51 -0400 |
| commit | 0e1c3d42a93f623f60284f7e9acfd014e41ddadc (patch) | |
| tree | 701cd9cef7e0e7210dba9ac77e2bad9a87b8c5e9 | |
| parent | 21ab7c1df0b8a0fcbb1d10ed2e61410d7f7021e0 (diff) | |
| download | tojam2024-textures.tar.gz tojam2024-textures.zip | |
loading and draw textures for skyboxtextures
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | assets/1_32px.png | bin | 0 -> 3123 bytes | |||
| -rw-r--r-- | assets/2_32px.png | bin | 0 -> 6472 bytes | |||
| -rw-r--r-- | assets/3_32px.png | bin | 0 -> 2715 bytes | |||
| -rw-r--r-- | assets/4_32px.png | bin | 0 -> 3302 bytes | |||
| -rw-r--r-- | assets/5_32px.png | bin | 0 -> 3524 bytes | |||
| -rw-r--r-- | assets/6_32px.png | bin | 0 -> 3463 bytes | |||
| -rw-r--r-- | src/main.c | 32 | ||||
| -rw-r--r-- | src/render.c | 76 | ||||
| -rw-r--r-- | src/render.h | 8 |
10 files changed, 119 insertions, 2 deletions
@@ -46,8 +46,9 @@ n64: raylib.z64 filesystem/%.sprite: assets/%.png @mkdir -p $(dir $@) @echo " [SPRITE] $@" - echo @$(N64_MKSPRITE) -v -f RGBA16 --compress -o "$(dir $@)" "$<" - @cp "$<" "$(dir $@)" + @$(N64_MKSPRITE) -v -f RGBA16 --compress -o "$(dir $@)" "$<" + #echo @$(N64_MKSPRITE) -v -f RGBA16 --compress -o "$(dir $@)" "$<" + #@cp "$<" "$(dir $@)" #filesystem/%.m3d: assets/%.m3d # @mkdir -p $(dir $@) diff --git a/assets/1_32px.png b/assets/1_32px.png Binary files differnew file mode 100644 index 0000000..e6251e5 --- /dev/null +++ b/assets/1_32px.png diff --git a/assets/2_32px.png b/assets/2_32px.png Binary files differnew file mode 100644 index 0000000..700f5a9 --- /dev/null +++ b/assets/2_32px.png diff --git a/assets/3_32px.png b/assets/3_32px.png Binary files differnew file mode 100644 index 0000000..c25cf0c --- /dev/null +++ b/assets/3_32px.png diff --git a/assets/4_32px.png b/assets/4_32px.png Binary files differnew file mode 100644 index 0000000..ae1be76 --- /dev/null +++ b/assets/4_32px.png diff --git a/assets/5_32px.png b/assets/5_32px.png Binary files differnew file mode 100644 index 0000000..f407341 --- /dev/null +++ b/assets/5_32px.png diff --git a/assets/6_32px.png b/assets/6_32px.png Binary files differnew file mode 100644 index 0000000..ef759ae --- /dev/null +++ b/assets/6_32px.png @@ -65,6 +65,15 @@ World world = { } }; +char *sprite_paths[] = +{ + "rom:/1_32px.sprite", + "rom:/2_32px.sprite", + "rom:/3_32px.sprite", + "rom:/4_32px.sprite", + "rom:/5_32px.sprite", + "rom:/6_32px.sprite", +}; int main(void) { @@ -86,8 +95,28 @@ int main(void) camera2.fovy = 35.0f; camera2.projection = CAMERA_PERSPECTIVE; + Camera camerax = { 0 }; + camerax.position = (Vector3){ 0.0f, 0.0f, 15.0f }; + camerax.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camerax.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camerax.fovy = 45.0f; + camerax.projection = CAMERA_PERSPECTIVE; + + sprite_t *sprites[6]; + GLuint textures[6]; + glGenTextures(6, textures); + for (int i = 0; i < 6; i++) + { + textures[i] = customLoadTextureN64(sprite_paths[i]); + } + SetTargetFPS(60); + GLuint dl_skybox = glGenLists(1); + glNewList(dl_skybox, GL_COMPILE); + renderSkybox(textures, 2, 3, camera); + glEndList(); + while (!WindowShouldClose()) { updateController(); @@ -138,6 +167,9 @@ int main(void) BeginDrawing(); ClearBackground(BLACK); + BeginMode3D(camerax); + glCallList(dl_skybox); + EndMode3D(); BeginScissorMode(0, 0, 320/2, 240); rlViewport(0, 0, 320/2, 240); renderWorld(&world, camera); diff --git a/src/render.c b/src/render.c index 1501814..ef6383a 100644 --- a/src/render.c +++ b/src/render.c @@ -114,6 +114,82 @@ drawGrid(Vector3 position, int lines, int size, Color color) rlPopMatrix(); } +GLuint customLoadTextureN64(char *spritePath) +{ + sprite_t *sprite = sprite_load(spritePath); + GLuint id; + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + glSpriteTextureN64(GL_TEXTURE_2D, sprite, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + return id; +} + +/*Vector3 vertices[] = { + {0.5f, 0.5f, 0.0f}, + {0.5f, -0.5f, 0.0f}, + {-0.5f, -0.5f, 0.0f}, + {-0.5f, 0.5f, 0.0f}, +}; + +float texcoords[] = { + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f, + 0.0f, 1.0f +};*/ + +Vector2 vertices[] = +{ + {1.0f, 0.0f}, + {1.0f, 1.0f}, + {0.0f, 1.0f}, + {0.0f, 0.0f}, +}; + +float texcoords[] = { + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f, + 0.0f, 1.0f, +}; + +uint8_t indices[] = +{ + 0, 1, 2, 3, +}; + +void +renderSkybox(GLuint *textures, int m, int n, Camera3D camera) +{ + //int len = m*n; + rlPushMatrix(); + rlTranslatef(-6.0f, 3.0f, 0.0f); + glEnable(GL_TEXTURE_2D); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + rlColor4ub(255,255,255,255); + glVertexPointer(2, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + glBindTexture(GL_TEXTURE_2D, textures[i*n+j]); + rlPushMatrix(); + rlTranslatef(j, -i, 0.0f); + glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, indices); + rlPopMatrix(); + } + } + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); + rlPopMatrix(); +} + void renderWorld(World* world, Camera camera) { diff --git a/src/render.h b/src/render.h index 7e066c4..d1fe7ab 100644 --- a/src/render.h +++ b/src/render.h @@ -1,10 +1,18 @@ #ifndef GAME_RENDER_H #define GAME_RENDER_H +#include <GL/gl.h> +#include <GL/glu.h> #include "raylib.h" #include "rlgl.h" #include "world.h" +GLuint +customLoadTextureN64(char *spritePath); + +void +renderSkybox(GLuint *textures, int m, int n, Camera3D camera); + void renderWorld(World* world, Camera camera); |
