font trasparente e resize della finestra
This commit is contained in:
parent
e0e89d0f2b
commit
938e2434e4
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 862 B |
@ -1,3 +1,4 @@
|
|||||||
|
#include <SDL2/SDL_events.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#define _POSIX_C_SOURCE 200809l
|
#define _POSIX_C_SOURCE 200809l
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ int vstack_push_quad_c(int x, int y, int w, int h, vec4 color)
|
|||||||
// x1,y1 x2,y2
|
// x1,y1 x2,y2
|
||||||
|
|
||||||
int hw = w_width(ren.w)/2;
|
int hw = w_width(ren.w)/2;
|
||||||
int hh = w_width(ren.w)/2;
|
int hh = w_height(ren.w)/2;
|
||||||
|
|
||||||
float x1, x2, x3, x4;
|
float x1, x2, x3, x4;
|
||||||
float y1, y2, y3, y4;
|
float y1, y2, y3, y4;
|
||||||
@ -152,7 +153,7 @@ int vstack_push_quad_t(int x, int y, int w, int h, int u, int v)
|
|||||||
// x1,y1 x2,y2
|
// x1,y1 x2,y2
|
||||||
|
|
||||||
int hw = w_width(ren.w)/2;
|
int hw = w_width(ren.w)/2;
|
||||||
int hh = w_width(ren.w)/2;
|
int hh = w_height(ren.w)/2;
|
||||||
|
|
||||||
float x1, x2, x3, x4;
|
float x1, x2, x3, x4;
|
||||||
float y1, y2, y3, y4;
|
float y1, y2, y3, y4;
|
||||||
@ -343,6 +344,9 @@ void ren_initshaders()
|
|||||||
void ren_drawvertbuffer()
|
void ren_drawvertbuffer()
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, ren.gl_vertbuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, ren.gl_vertbuffer);
|
||||||
|
// upload vertex data
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vstack.idx*sizeof(struct vertex), vstack.v, GL_DYNAMIC_DRAW);
|
||||||
|
// draw vertex data
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vstack.idx);
|
glDrawArrays(GL_TRIANGLES, 0, vstack.idx);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
@ -437,13 +441,11 @@ int main (void)
|
|||||||
import_font("./charmap.ff");
|
import_font("./charmap.ff");
|
||||||
|
|
||||||
vec4 magenta = {.r=1.0, .g=0.0, .b=1.0, .a=1.0};
|
vec4 magenta = {.r=1.0, .g=0.0, .b=1.0, .a=1.0};
|
||||||
vstack_push_quad_c(0, 0, 100, 100, magenta);
|
|
||||||
vstack_push_quad_c(200, 0, 10, 10, magenta);
|
|
||||||
vstack_push_quad_c(10, 150, 100, 100, magenta);
|
|
||||||
|
|
||||||
push_text(250, 250, "ò Ciao Victoria <3");
|
|
||||||
ren_initvertbuffer();
|
ren_initvertbuffer();
|
||||||
|
|
||||||
|
glClearColor(0.3f, 0.3f, 0.3f, 0.f);
|
||||||
|
|
||||||
// event loop and drawing
|
// event loop and drawing
|
||||||
SDL_Event ev = {0};
|
SDL_Event ev = {0};
|
||||||
int running = 1;
|
int running = 1;
|
||||||
@ -451,22 +453,33 @@ int main (void)
|
|||||||
SDL_WaitEvent(&ev);
|
SDL_WaitEvent(&ev);
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case SDL_QUIT: running = 0; break;
|
case SDL_QUIT: running = 0; break;
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
if(ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||||
|
glViewport(0, 0, w_width(ren.w), w_height(ren.w));
|
||||||
|
glScissor(0, 0, w_width(ren.w), w_height(ren.w));
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(0, 0, w_width(ren.w), w_height(ren.w));
|
vstack_push_quad_c(0, 0, 100, 100, magenta);
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
vstack_push_quad_c(200, 0, 10, 10, magenta);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
vstack_push_quad_c(10, 150, 100, 100, magenta);
|
||||||
|
push_text(250, 250, "ò Ciao Victoria <3");
|
||||||
|
|
||||||
ren_drawvertbuffer();
|
ren_drawvertbuffer();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(ren.w);
|
SDL_GL_SwapWindow(ren.w);
|
||||||
|
|
||||||
|
vstack_clear();
|
||||||
|
|
||||||
} while(running);
|
} while(running);
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glDisableVertexAttribArray(vertindex);
|
glDisableVertexAttribArray(vertindex);
|
||||||
glDisableVertexAttribArray(colindex);
|
glDisableVertexAttribArray(colindex);
|
||||||
|
glDeleteTextures(1, &ren.font_texture);
|
||||||
SDL_GL_DeleteContext(ren.gl);
|
SDL_GL_DeleteContext(ren.gl);
|
||||||
SDL_DestroyWindow(ren.w);
|
SDL_DestroyWindow(ren.w);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
Loading…
Reference in New Issue
Block a user