mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Got through the requisite amount of invisible pain to get something onto my GL display. But clearly this is factored in entirely the wrong way. Work to do.
This commit is contained in:
parent
31338ef754
commit
5ab47e600a
@ -8,7 +8,31 @@
|
||||
|
||||
#import "Atari2600.h"
|
||||
#import "Atari2600.hpp"
|
||||
#import <OpenGL/gl.h>
|
||||
#import <OpenGL/gl3.h>
|
||||
|
||||
const char *vertexShader =
|
||||
"#version 150\n"
|
||||
"\n"
|
||||
"in vec2 position;\n"
|
||||
"\n"
|
||||
"out vec4 colour;\n"
|
||||
"\n"
|
||||
"void main (void)\n"
|
||||
"{\n"
|
||||
"colour = vec4(position, 0.0, 1.0);\n"
|
||||
"gl_Position = vec4(position, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
const char *fragmentShader =
|
||||
"#version 150\n"
|
||||
"\n"
|
||||
"in vec4 colour;\n"
|
||||
"out vec4 fragColour;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
"fragColour = colour;\n"
|
||||
"}\n";
|
||||
|
||||
@interface CSAtari2600 (Callbacks)
|
||||
- (void)crtDidEndFrame:(Outputs::CRTFrame *)frame;
|
||||
@ -25,6 +49,11 @@ struct Atari2600CRTDelegate: public Outputs::CRT::CRTDelegate {
|
||||
|
||||
dispatch_queue_t _serialDispatchQueue;
|
||||
Outputs::CRTFrame *_queuedFrame;
|
||||
|
||||
GLuint _vertexShader, _fragmentShader;
|
||||
GLuint _shaderProgram;
|
||||
|
||||
GLuint _arrayBuffer, _vertexArray;
|
||||
}
|
||||
|
||||
- (void)crtDidEndFrame:(Outputs::CRTFrame *)frame {
|
||||
@ -41,12 +70,55 @@ struct Atari2600CRTDelegate: public Outputs::CRT::CRTDelegate {
|
||||
});
|
||||
}
|
||||
|
||||
- (GLuint)compileShader:(const char *)source type:(GLenum)type
|
||||
{
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &source, NULL);
|
||||
glCompileShader(shader);
|
||||
return shader;
|
||||
}
|
||||
|
||||
- (void)draw {
|
||||
|
||||
if(!_shaderProgram)
|
||||
{
|
||||
_shaderProgram = glCreateProgram();
|
||||
_vertexShader = [self compileShader:vertexShader type:GL_VERTEX_SHADER];
|
||||
_fragmentShader = [self compileShader:fragmentShader type:GL_FRAGMENT_SHADER];
|
||||
|
||||
glAttachShader(_shaderProgram, _vertexShader);
|
||||
glAttachShader(_shaderProgram, _fragmentShader);
|
||||
glLinkProgram(_shaderProgram);
|
||||
|
||||
glGenVertexArrays(1, &_vertexArray);
|
||||
glBindVertexArray(_vertexArray);
|
||||
glGenBuffers(1, &_arrayBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _arrayBuffer);
|
||||
|
||||
GLfloat vertices[] = {
|
||||
0.0f, 0.0f,
|
||||
0.5f, 0.0f,
|
||||
0.5f, 0.6f,
|
||||
0.0f, 0.5f
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
if(_queuedFrame)
|
||||
{
|
||||
glClearColor(1.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(_shaderProgram);
|
||||
|
||||
GLint position = glGetAttribLocation(_shaderProgram, "position");
|
||||
|
||||
glEnableVertexAttribArray(position);
|
||||
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, (void *)0);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, 4);
|
||||
|
||||
/* printf("\n\n===\n\n");
|
||||
int c = 0;
|
||||
for(int run = 0; run < _queuedFrame->number_of_runs; run++)
|
||||
|
Loading…
Reference in New Issue
Block a user