76 lines
1.7 KiB
C++
76 lines
1.7 KiB
C++
#include <GL/glut.h>
|
|
#include <string>
|
|
|
|
#include "textures.h"
|
|
|
|
int render_7_seg_img;
|
|
|
|
void render_7_seg_part(int id, double size)
|
|
{
|
|
// Start drawing
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2d((id+0)/11.0, 0); glVertex2d(0 ,0 );
|
|
glTexCoord2d((id+1)/11.0, 0); glVertex2d(size,0 );
|
|
glTexCoord2d((id+1)/11.0, 1); glVertex2d(size,size);
|
|
glTexCoord2d((id+0)/11.0, 1); glVertex2d(0 ,size);
|
|
|
|
// Stop drawing
|
|
glEnd();
|
|
}
|
|
|
|
void render_7_seg(unsigned long n, double size, int places)
|
|
{
|
|
// Bind the texture
|
|
glBindTexture(GL_TEXTURE_2D, render_7_seg_img);
|
|
|
|
// Convert the number to a string
|
|
std::string str = std::to_string(n);
|
|
|
|
// Is the place count negative, by default
|
|
if(places == -1)
|
|
{
|
|
// Set the places to display as the string size
|
|
places = str.size();
|
|
}
|
|
|
|
// Loop over the places
|
|
for(int i=0;i<places;i++)
|
|
{
|
|
// Is the iterator too large
|
|
if(i >= str.size())
|
|
{
|
|
// Render a blank pane
|
|
render_7_seg_part(10, size);
|
|
}
|
|
|
|
else
|
|
{
|
|
// Get part of the number to view
|
|
char item = str[str.size()-i];
|
|
|
|
// Render the item
|
|
if(item=='0') render_7_seg_part(0, size);
|
|
if(item=='1') render_7_seg_part(1, size);
|
|
if(item=='2') render_7_seg_part(2, size);
|
|
if(item=='3') render_7_seg_part(3, size);
|
|
if(item=='4') render_7_seg_part(4, size);
|
|
if(item=='5') render_7_seg_part(5, size);
|
|
if(item=='6') render_7_seg_part(6, size);
|
|
if(item=='7') render_7_seg_part(7, size);
|
|
if(item=='8') render_7_seg_part(8, size);
|
|
if(item=='9') render_7_seg_part(9, size);
|
|
}
|
|
}
|
|
|
|
// Unbind the image
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
|
|
void text_init()
|
|
{
|
|
// Load the 7 segment display
|
|
int w, h;
|
|
render_7_seg_img = loadArchiveImageGL("textures/7-seg.rimg", 'L', w, h);
|
|
}
|