patterncMinor
OpenGL text rendering library for Lua built on freetype-gl
Viewed 0 times
builtfreetypetextforlibraryopenglrenderinglua
Problem
FTGL wasn't making me happy, so I decided to try something else. This isn't completely finished; I plan to work more on layouts and alignment, and add a few other things. It should be far enough along to review, though.
I realize there is some inconsistent whitespace, especially around argument lists. I don't care enough to fix it right now. I'd love to get feedback on anything else.
./gltext.h (716 bytes in 42 lines)
./gltext.c (4009 bytes in 131 lines)
```
#include "gltext.h"
#include "shaders/v3f-c4f.vert.h"
#include "shaders/v3f-c4f.frag.h"
static GLuint shader;
static int initted = 0;
static void checkinit(void)
{
if (initted == 1) return;
#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
fprintf(stderr, "freetype not compiled with subpixel rendering.\n");
exit( EXIT_FAILURE) ;
#endif
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
exit( EXIT_FAILURE );
}
fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
shader = shader_load_resource(
shader_resource_v3f_c4f_vert,
shader_resource_v3f_c4f_frag);
initted = 1;
}
gltext_t *gltext_new(void)
{
checkinit();
gltext_t self = (gltext_t ) malloc
I realize there is some inconsistent whitespace, especially around argument lists. I don't care enough to fix it right now. I'd love to get feedback on anything else.
./gltext.h (716 bytes in 42 lines)
#ifndef __GLTEXT_H__
#define __GLTEXT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include
#include FT_CONFIG_OPTIONS_H
#include
#include
#include
#include "vertex-buffer.h"
#include "text-buffer.h"
#include "mat4.h"
typedef struct {
vec2 *pen;
markup_t *markup;
text_buffer_t *text;
vertex_buffer_t *vert;
mat4 *model;
mat4 *view;
mat4 *projection;
} gltext_t;
gltext_t *gltext_new(void);
void gltext_delete(gltext_t *self);
void gltext_write(gltext_t *self, wchar_t *text);
void gltext_render(gltext_t *self);
void gltext_reshape(gltext_t *self, int width, int height);
#ifdef __cplusplus
}
#endif
#endif /* #define __GLTEXT_H__ */./gltext.c (4009 bytes in 131 lines)
```
#include "gltext.h"
#include "shaders/v3f-c4f.vert.h"
#include "shaders/v3f-c4f.frag.h"
static GLuint shader;
static int initted = 0;
static void checkinit(void)
{
if (initted == 1) return;
#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
fprintf(stderr, "freetype not compiled with subpixel rendering.\n");
exit( EXIT_FAILURE) ;
#endif
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
exit( EXIT_FAILURE );
}
fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
shader = shader_load_resource(
shader_resource_v3f_c4f_vert,
shader_resource_v3f_c4f_frag);
initted = 1;
}
gltext_t *gltext_new(void)
{
checkinit();
gltext_t self = (gltext_t ) malloc
Solution
A few general comments, as I know nothing of
-
Why make
-
-
When you do allocate structures using
-
Your
-
your multi-line macros should be wrapped in a
opengl or lua.-
Why make
gltext_t contain pointers to structure that must be allocated individually, rather than just containing the structs (i.e. omit the '*')? -
Gltext is an alternative type name that avoids using the reserved _t suffix.-
When you do allocate structures using
malloc you should omit the casts.-
Your
void casts on assignments to gltext_t pointers is odd, why not cast using gltext_t* if it is needed?-
your multi-line macros should be wrapped in a
do {....} while(0) (no semicolon) or replaced by functions if at all possible.Context
StackExchange Code Review Q#63380, answer score: 6
Revisions (0)
No revisions yet.