aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a04fb99..ada75e2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,6 +16,7 @@
using namespace amalgine;
using namespace std;
+void glfwErrorHandler(int errorCode, const char *errorDescription);
void initGlfw();
void initGlew();
GLFWwindow *createWindow();
@@ -26,6 +27,7 @@ CompiledPixelShader* createPixelShader();
int main()
{
initGlfw();
+ glfwSetErrorCallback(glfwErrorHandler);
GLFWwindow *window = createWindow();
DeviceFrame frame;
@@ -35,10 +37,9 @@ int main()
Vertex2D(0.5f, -0.5f),
Vertex2D(-0.5f, -0.5f)
);
-
+ DataView<Triangle2D> cpuTriangles(&cpuTriangle, 1);
DeviceMemory *gpuTriangle = frame.alloc();
- DataView<Triangle2D> triangles(&cpuTriangle, 1);
- gpuTriangle->copy(triangles, DeviceMemory::StorageType::STATIC);
+ gpuTriangle->copy(cpuTriangles, DeviceMemory::StorageType::STATIC);
CompiledVertexShader *vertexShader = createVertexShader(*gpuTriangle);
CompiledPixelShader *pixelShader = createPixelShader();
@@ -46,7 +47,13 @@ int main()
ShaderProgram shaderProgram;
shaderProgram.setVertexShader(vertexShader);
shaderProgram.setPixelShader(pixelShader);
+ // Make ShaderProgram.build return an object which we can do things on? since some operations
+ // require the shader to be built to be used
Result<bool> shaderBuildResult = shaderProgram.build();
+
+ ShaderProgramGlobalVec3 triangleColor = shaderProgram.getGlobalVec3("triangleColor");
+ triangleColor.set(1.0f, 0.0f, 0.0f);
+
if(!shaderBuildResult)
{
fprintf(stderr, "Failed to build shader program: %s\n", shaderBuildResult.getErrorMsg().c_str());
@@ -59,6 +66,10 @@ int main()
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
+ // Set color for clearing
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ // Do the actual screen clearing, using the color set using glClearColor
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shaderProgram.use();
frame.draw();
glfwSwapBuffers(window);
@@ -68,6 +79,11 @@ int main()
return 0;
}
+void glfwErrorHandler(int errorCode, const char *errorDescription)
+{
+ printf("GLFW error code: %d, description: %s\n", errorCode, errorDescription);
+}
+
void initGlfw()
{
if(!glfwInit())
@@ -107,6 +123,7 @@ GLFWwindow* createWindow()
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwMakeContextCurrent(window);
+ glfwSwapInterval(0);
initGlew();
return window;
}
@@ -135,11 +152,12 @@ CompiledVertexShader* createVertexShader(const DeviceMemory &inputData)
CompiledPixelShader* createPixelShader()
{
PixelShader pixelShader;
+ ShaderGlobalVec3 triangleColor = pixelShader.defineGlobalVec3("triangleColor");
ShaderOutputVec4 outColor = pixelShader.defineOutputVec4("outColor");
- pixelShader.defineMain([&outColor]()
+ pixelShader.defineMain([&triangleColor, &outColor]()
{
- outColor = ShaderVec4(1.0f, 1.0f, 1.0f, 1.0f);
+ outColor = ShaderVec4(triangleColor, 1.0f);
});
Result<CompiledPixelShader*> compiledPixelShader = pixelShader.compile();