summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2025-11-27 17:19:02 +0100
committernavewindre <boneyaard@gmail.com>2025-11-27 17:21:48 +0100
commite3de3ba5162f7ddd5005911124d4333e140fd984 (patch)
treeefb2d3851940ba1b70f0105611cddb17344e7e32 /src/render
parent5c8bbc3bc618068af1f7d6f2829c4346570c2ab9 (diff)
bunch o stuff
Diffstat (limited to 'src/render')
-rw-r--r--src/render/gl.cpp17
-rw-r--r--src/render/gl_2d.cpp16
2 files changed, 18 insertions, 15 deletions
diff --git a/src/render/gl.cpp b/src/render/gl.cpp
index 382d81e..e44a165 100644
--- a/src/render/gl.cpp
+++ b/src/render/gl.cpp
@@ -276,7 +276,7 @@ GL_TEX2D* gl_texture_from_file( GL_DATA* gl, const char* name ) {
return tex;
}
-GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32 width, U32 height ) {
+GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32 w, U32 h ) {
GL_TEX2D* tex = gl_texture_create( gl, name );
glBindTexture( GL_TEXTURE_2D, tex->id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
@@ -284,18 +284,13 @@ GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- tex->width = width;
- tex->height = height;
-
- glTexImage2D(
- GL_TEXTURE_2D,
- 0, GL_RGBA,
- (I32)width, (I32)height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, bitmap
- );
-
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap );
+ glGenerateMipmap( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, 0 );
+ tex->width = w;
+ tex->height = h;
+
return tex;
}
diff --git a/src/render/gl_2d.cpp b/src/render/gl_2d.cpp
index 1803eb5..78af1da 100644
--- a/src/render/gl_2d.cpp
+++ b/src/render/gl_2d.cpp
@@ -104,25 +104,33 @@ void gl_2d_textured_frect( GL_SHADER_PROGRAM* gl2d, VEC2 origin, VEC2 dim, GL_TE
glBindBuffer( GL_ARRAY_BUFFER, gl2d->gl->vbuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_DYNAMIC_DRAW );
+
I32 position = glGetAttribLocation( gl2d->id, "in_pos" );
+ I32 color = glGetAttribLocation( gl2d->id, "in_col" );
+ I32 texcoord = glGetAttribLocation( gl2d->id, "in_texcoord" );
+ I32 sampler = glGetAttribLocation( gl2d->id, "in_sampler" );
+
glEnableVertexAttribArray( position );
glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), 0 );
- I32 color = glGetAttribLocation( gl2d->id, "in_col" );
+
glEnableVertexAttribArray( color );
glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr );
- I32 texcoord = glGetAttribLocation( gl2d->id, "in_texcoord" );
+
glEnableVertexAttribArray( texcoord );
glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv );
- I32 sampler = glGetAttribLocation( gl2d->id, "in_sampler" );
+
glEnableVertexAttribArray( sampler );
glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler );
+ glActiveTexture( GL_TEXTURE0 );
+ glBindTexture( GL_TEXTURE_2D, texture->id );
+
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, texture->id );
- glUniform1f( glGetUniformLocation( gl2d->id, "in_time" ), u_time() );
+ // glUniform1f( glGetUniformLocation( gl2d->id, "in_time" ), u_time() );
glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, order );
glBindTexture( GL_TEXTURE_2D, 0 );