window := glfwCreateWindow(cWindowWidth, cWindowHeight, 'Hello World', nil, nil);
if window = nil then
begin
glfwTerminate();
ExitCode := -1;
end;
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, @FramebufferSizeCallback);
//must be called after glfwMakeContextCurrent
if Load_GL_version_3_3 then
else ;
InitScene;
while glfwWindowShouldClose(window) = 0 do begin
ProcessInput(window);
glClearColor(0.2, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Texture1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, Texture2);
Vec1.Create(1, 1, 1);
Vec1:= Vec1.Normalize;
Model.CreateRotate(glfwGetTime*2, Vec3.Create(Vec1.x,Vec1.y,Vec1.z));
View.CreateTranslation(0, 0, -80);
// Cam control
View.CreateLookAt(
Vec3.Create(0, 0, 150), // camera pos
Vec3.Create(0.4*sin(glfwGetTime*2), 0.8*cos(glfwGetTime*2), 0), // look camera points x,y,z
Vec3.Create(0, 2, 0) // x,Y,z
);
Projection.CreatePerspective(DegToRad(45), 800.0 / 600.0, 0.1, 300);
Sh.Use;
glUniformMatrix4fv(glGetUniformLocation(Sh.ID, 'model'), 1, GL_FALSE, @Model.m00);
glUniformMatrix4fv(glGetUniformLocation(Sh.ID, 'view'), 1, GL_FALSE, @View.m00);
glUniformMatrix4fv(glGetUniformLocation(Sh.ID, 'projection'), 1, GL_FALSE, @Projection.m00);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
{
glBegin(GL_TRIANGLES);
glColor3d(1,0,0);
glVertex2f(-1, -1);
glColor3d(1,1,0);
glVertex2f(1, -1);
glColor3d(1,0,1);
glVertex2f(0, 1);
glEnd;
}
glfwSwapBuffers(window);
glfwPollEvents();
end;