render a file's contents
This commit is contained in:
1 parent
5da9cde758
commit
d8fcbcd428
3 files changed
+32
-11
No files matched your search
+21
-9
@@ -65,7 +65,7 @@ static bool Initialize_OpenGL()
|
||||
* @retval true The Window was created successfully.
|
||||
* @retval false There was an error while creating the Window.
|
||||
*/
|
||||
bool Window::create()
|
||||
bool Window::create(std::shared_ptr<Buffer> buffer)
|
||||
{
|
||||
if (!Initialize_SDL())
|
||||
{
|
||||
@@ -110,6 +110,8 @@ bool Window::create()
|
||||
m_programs.text->set_texture(0);
|
||||
m_programs.text->set_color(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
m_buffer = buffer;
|
||||
|
||||
resize();
|
||||
|
||||
return true;
|
||||
@@ -179,16 +181,26 @@ void Window::redraw()
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
m_programs.text->use();
|
||||
static const char msg[] = "Welcome to " APPNAME " pre-pre-pre-alpha!!";
|
||||
|
||||
int advance = m_font.get_advance();
|
||||
int x = 0;
|
||||
int y = m_height - FONT_SIZE;
|
||||
for (int i = 0, len = strlen(msg); i < len; i++)
|
||||
int line_height = m_font.get_line_height();
|
||||
int y = m_height - line_height;
|
||||
for (auto line = m_buffer->cbegin(); line != m_buffer->cend(); line++)
|
||||
{
|
||||
m_programs.text->set_position(x, y);
|
||||
auto g = m_font.get_glyph(msg[i]);
|
||||
g->render();
|
||||
x += advance;
|
||||
int x = 0;
|
||||
for (int i = 0, len = (*line)->size(); i < len; i++)
|
||||
{
|
||||
uint8_t c = (**line)[i];
|
||||
auto g = m_font.get_glyph(c);
|
||||
m_programs.text->set_position(x, y);
|
||||
g->render();
|
||||
x += advance;
|
||||
}
|
||||
y -= line_height;
|
||||
if (y + line_height < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
|
||||
+4
-1
@@ -4,11 +4,12 @@
|
||||
#include <SDL.h>
|
||||
#include "TextProgram.h"
|
||||
#include "Font.h"
|
||||
#include "Buffer.h"
|
||||
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
bool create();
|
||||
bool create(std::shared_ptr<Buffer> buffer);
|
||||
void run_event_loop();
|
||||
|
||||
protected:
|
||||
@@ -26,6 +27,8 @@ protected:
|
||||
} m_programs;
|
||||
|
||||
Font m_font;
|
||||
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user