Draw a checkerboard pattern behind the image.
This commit is contained in:
parent
6073317591
commit
4021acd3f8
3 changed files with 79 additions and 25 deletions
|
@ -89,6 +89,8 @@ CGEDebugger::CGEDebugger(HINSTANCE _hInstance, HWND _hParent)
|
||||||
breakCmds.resize(256, false);
|
breakCmds.resize(256, false);
|
||||||
// TODO: Could be scrollable in case the framebuf is larger? Also should be better positioned.
|
// TODO: Could be scrollable in case the framebuf is larger? Also should be better positioned.
|
||||||
frameWindow = new SimpleGLWindow(m_hInstance, m_hDlg, (750 - 512) / 2, 40, 512, 272);
|
frameWindow = new SimpleGLWindow(m_hInstance, m_hDlg, (750 - 512) / 2, 40, 512, 272);
|
||||||
|
// TODO: Why doesn't this work?
|
||||||
|
frameWindow->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CGEDebugger::~CGEDebugger() {
|
CGEDebugger::~CGEDebugger() {
|
||||||
|
|
|
@ -53,8 +53,19 @@ SimpleGLWindow::SimpleGLWindow(HINSTANCE hInstance, HWND hParent, int x, int y,
|
||||||
SetupGL();
|
SetupGL();
|
||||||
ResizeGL(w, h);
|
ResizeGL(w, h);
|
||||||
CreateProgram();
|
CreateProgram();
|
||||||
|
GenerateChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleGLWindow::~SimpleGLWindow() {
|
||||||
|
if (drawProgram_ != NULL) {
|
||||||
|
glsl_destroy(drawProgram_);
|
||||||
|
}
|
||||||
|
if (tex_) {
|
||||||
|
glDeleteTextures(1, &tex_);
|
||||||
|
glDeleteTextures(1, &checker_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void SimpleGLWindow::RegisterWindowClass() {
|
void SimpleGLWindow::RegisterWindowClass() {
|
||||||
if (windowClassExists_) {
|
if (windowClassExists_) {
|
||||||
return;
|
return;
|
||||||
|
@ -115,6 +126,7 @@ void SimpleGLWindow::ResizeGL(int w, int h) {
|
||||||
wglMakeCurrent(hDC_, hGLRC_);
|
wglMakeCurrent(hDC_, hGLRC_);
|
||||||
|
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
|
glScissor(0, 0, w, h);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);
|
glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);
|
||||||
|
@ -134,18 +146,68 @@ void SimpleGLWindow::CreateProgram() {
|
||||||
|
|
||||||
drawProgram_ = glsl_create_source(basic_vs, tex_fs);
|
drawProgram_ = glsl_create_source(basic_vs, tex_fs);
|
||||||
glGenTextures(1, &tex_);
|
glGenTextures(1, &tex_);
|
||||||
|
glGenTextures(1, &checker_);
|
||||||
|
|
||||||
glsl_bind(drawProgram_);
|
glsl_bind(drawProgram_);
|
||||||
glUniform1i(drawProgram_->sampler0, 0);
|
glUniform1i(drawProgram_->sampler0, 0);
|
||||||
glsl_unbind();
|
glsl_unbind();
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(drawProgram_->a_position);
|
||||||
|
glEnableVertexAttribArray(drawProgram_->a_texcoord0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
|
void SimpleGLWindow::GenerateChecker() {
|
||||||
|
if (!valid_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const static u8 checkerboard[] = {
|
||||||
|
255,255,255,255, 195,195,195,255,
|
||||||
|
195,195,195,255, 255,255,255,255,
|
||||||
|
};
|
||||||
|
|
||||||
|
wglMakeCurrent(hDC_, hGLRC_);
|
||||||
|
|
||||||
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, checker_);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkerboard);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleGLWindow::DrawChecker() {
|
||||||
wglMakeCurrent(hDC_, hGLRC_);
|
wglMakeCurrent(hDC_, hGLRC_);
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, checker_);
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glViewport(0, 0, w_, h_);
|
||||||
|
glScissor(0, 0, w_, h_);
|
||||||
|
|
||||||
|
glsl_bind(drawProgram_);
|
||||||
|
|
||||||
|
float fw = (float)w_, fh = (float)h_;
|
||||||
|
const float pos[12] = {0,0,0, fw,0,0, fw,fh,0, 0,fh,0};
|
||||||
|
const float texCoords[8] = {0,fh/22, fw/22,fh/22, fw/22,0, 0,0};
|
||||||
|
const GLubyte indices[4] = {0,1,3,2};
|
||||||
|
|
||||||
|
Matrix4x4 ortho;
|
||||||
|
ortho.setOrtho(0, (float)w_, (float)h_, 0, -1, 1);
|
||||||
|
glUniformMatrix4fv(drawProgram_->u_viewproj, 1, GL_FALSE, ortho.getReadPtr());
|
||||||
|
glVertexAttribPointer(drawProgram_->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
|
||||||
|
glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, texCoords);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
|
||||||
|
DrawChecker();
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
@ -156,6 +218,8 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
glsl_bind(drawProgram_);
|
glsl_bind(drawProgram_);
|
||||||
|
|
||||||
|
@ -181,22 +245,13 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
|
||||||
glUniformMatrix4fv(drawProgram_->u_viewproj, 1, GL_FALSE, ortho.getReadPtr());
|
glUniformMatrix4fv(drawProgram_->u_viewproj, 1, GL_FALSE, ortho.getReadPtr());
|
||||||
glVertexAttribPointer(drawProgram_->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
|
glVertexAttribPointer(drawProgram_->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
|
||||||
glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, texCoords);
|
glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, texCoords);
|
||||||
glEnableVertexAttribArray(drawProgram_->a_position);
|
|
||||||
glEnableVertexAttribArray(drawProgram_->a_texcoord0);
|
|
||||||
glUniform1i(drawProgram_->sampler0, 0);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||||
glDisableVertexAttribArray(drawProgram_->a_position);
|
|
||||||
glDisableVertexAttribArray(drawProgram_->a_texcoord0);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
Swap();
|
Swap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleGLWindow::Clear() {
|
void SimpleGLWindow::Clear() {
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
DrawChecker();
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
Swap();
|
Swap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,20 +30,7 @@ struct SimpleGLWindow {
|
||||||
};
|
};
|
||||||
|
|
||||||
SimpleGLWindow(HINSTANCE hInstance, HWND hParent, int x, int y, int w, int h);
|
SimpleGLWindow(HINSTANCE hInstance, HWND hParent, int x, int y, int w, int h);
|
||||||
~SimpleGLWindow() {
|
~SimpleGLWindow();
|
||||||
if (drawProgram_ != NULL) {
|
|
||||||
glsl_destroy(drawProgram_);
|
|
||||||
}
|
|
||||||
if (tex_) {
|
|
||||||
glDeleteTextures(1, &tex_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterWindowClass();
|
|
||||||
void Create(int x, int y, int w, int h);
|
|
||||||
void SetupGL();
|
|
||||||
void ResizeGL(int w, int h);
|
|
||||||
void CreateProgram();
|
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void Draw(u8 *data, int w, int h, ResizeType resize = RESIZE_NONE);
|
void Draw(u8 *data, int w, int h, ResizeType resize = RESIZE_NONE);
|
||||||
|
@ -52,6 +39,15 @@ struct SimpleGLWindow {
|
||||||
SwapBuffers(hDC_);
|
SwapBuffers(hDC_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void RegisterWindowClass();
|
||||||
|
void Create(int x, int y, int w, int h);
|
||||||
|
void SetupGL();
|
||||||
|
void ResizeGL(int w, int h);
|
||||||
|
void CreateProgram();
|
||||||
|
void GenerateChecker();
|
||||||
|
void DrawChecker();
|
||||||
|
|
||||||
static bool windowClassExists_;
|
static bool windowClassExists_;
|
||||||
|
|
||||||
HINSTANCE hInstance_;
|
HINSTANCE hInstance_;
|
||||||
|
@ -64,5 +60,6 @@ struct SimpleGLWindow {
|
||||||
int h_;
|
int h_;
|
||||||
|
|
||||||
GLSLProgram *drawProgram_;
|
GLSLProgram *drawProgram_;
|
||||||
|
GLuint checker_;
|
||||||
GLuint tex_;
|
GLuint tex_;
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue