separate out opengl_texture

This commit is contained in:
Brad Grantham 2018-10-14 12:10:31 -07:00
parent bb30c33d2d
commit f2b28839e4
3 changed files with 25 additions and 23 deletions

View File

@ -126,3 +126,18 @@ bool CheckProgramLink(GLuint program)
return false;
}
opengl_texture initialize_texture(int w, int h, unsigned char *pixels)
{
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
CheckOpenGL(__FILE__, __LINE__);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
CheckOpenGL(__FILE__, __LINE__);
return {w, h, tex};
}

View File

@ -90,4 +90,14 @@ struct render_target
}
};
struct opengl_texture
{
int w;
int h;
GLuint t;
operator GLuint() const { return t; }
};
opengl_texture initialize_texture(int w, int h, unsigned char *pixels = NULL);
#endif /* __GLWIDGET_H__ */

View File

@ -90,29 +90,6 @@ event dequeue_event()
return {NONE, 0};
}
struct opengl_texture
{
int w;
int h;
GLuint t;
operator GLuint() const { return t; }
};
opengl_texture initialize_texture(int w, int h, unsigned char *pixels = NULL)
{
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
CheckOpenGL(__FILE__, __LINE__);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
CheckOpenGL(__FILE__, __LINE__);
return {w, h, tex};
}
opengl_texture font_texture;
const int fonttexture_w = 7;
const int fonttexture_h = 8 * 96;