Skip to content

Commit 1dc6673

Browse files
royqh1979@gmail.comroyqh1979@gmail.com
royqh1979@gmail.com
authored and
royqh1979@gmail.com
committed
- fix: non-cpp project file will make generated makefile error
- fix: project created by GLUT(freeglut) template won't compile - add: GLFW/GLEW project template
1 parent 93e8225 commit 1dc6673

12 files changed

+267
-640
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ ResEd
7575
PackMaker.exe
7676
MinGW64
7777
/MinGW64.bak
78+
MinGW64_20210820

NEWS.txt

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Version 6.7.5 AUGUST 2021
1212
- fix: newly created projects can't be debugged
1313
- fix: typo error of turtle template
1414
- fix: crash when try to start debugger while the debugger executable dosen't exist
15+
- fix: non-cpp project file will make generated makefile error
16+
- fix: project created by GLUT(freeglut) template won't compile
17+
- add: GLFW/GLEW project template
1518

1619
Version 6.7.4 AUGUST 2021
1720

Source/Compiler.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ procedure TCompiler.WriteMakeDefines(var F: TextFile);
243243

244244
// Only process source files
245245
RelativeName := ExtractRelativePath(fProject.FileName, fProject.Units[i].FileName);
246-
if not (GetFileTyp(RelativeName) in [utcHead, utcppHead, utResSrc]) then begin
246+
if not (GetFileTyp(RelativeName) in [utcHead, utcppHead, utResSrc, utOther]) then begin
247247
if fProject.Options.ObjectOutput <> '' then begin
248248

249249
// ofile = C:\MyProgram\obj\main.o

Templates/CL_GLUT.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ C=CL_GLUT_cpp.txt
1111
UnitCount=1
1212
Type=0
1313
IsCpp=1
14-
linker=-lopengl32 -lm -lfreeglut -lglew32_@@__@@_
14+
linker=-lm -lfreeglut_static -lopengl32 -lwinmm -lgdi32_@@__@@_
1515

1616

1717

Templates/CL_GLUT_cpp.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define FREEGLUT_STATIC
12
#include <stdlib.h>
23
#include <GL/glut.h>
34

Templates/GLFW.ico

4.19 KB
Binary file not shown.

Templates/GLFW.template

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[Template]
2+
ver=2
3+
Name=GLFW
4+
Description=A simple GLFW program
5+
Icon=GLFW.ico
6+
Category=Multimedia
7+
[Unit0]
8+
CppName=main.cpp
9+
Cpp=GLFW_main.cpp.txt
10+
[Unit1]
11+
CppName=shader.h
12+
Cpp=GLFW_shader.h.txt
13+
[Unit2]
14+
CppName=shader.frag
15+
Cpp=GLFW_shader.frag.txt
16+
[Unit3]
17+
CppName=shader.vs
18+
Cpp=GLFW_shader.vs.txt
19+
[Project]
20+
UnitCount=4
21+
Type=1
22+
IsCpp=1
23+
Compiler=
24+
CppCompiler=
25+
Linker=-lglfw3 -lglew32 -lopengl32 -lwinmm -lgdi32_@@__@@_
26+
CompilerSettings=0000000000110000000001000
27+
CompilerSet=1
28+
UseUTF8=0
29+
StaticLink=1
30+
AddCharset=1
31+
IncludeVersionInfo=0
32+
SupportXPThemes=0

Templates/GLFW_main.cpp.txt

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include <iostream>
2+
// GLEW
3+
#define GLEW_STATIC
4+
#include <GL/glew.h>
5+
// GLFW
6+
#include <GLFW/glfw3.h>
7+
// Other includes
8+
#include "shader.h"
9+
10+
// Function prototypes
11+
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
12+
13+
// Window dimensions
14+
const GLuint WIDTH = 800, HEIGHT = 600;
15+
16+
// The MAIN function, from here we start the application and run the game loop
17+
int main()
18+
{
19+
// Init GLFW
20+
glfwInit();
21+
// Set all the required options for GLFW
22+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
23+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
24+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
25+
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
26+
27+
// Create a GLFWwindow object that we can use for GLFW's functions
28+
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
29+
glfwMakeContextCurrent(window);
30+
31+
// Set the required callback functions
32+
glfwSetKeyCallback(window, key_callback);
33+
34+
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
35+
glewExperimental = GL_TRUE;
36+
// Initialize GLEW to setup the OpenGL Function pointers
37+
glewInit();
38+
39+
// Define the viewport dimensions
40+
glViewport(0, 0, WIDTH, HEIGHT);
41+
42+
43+
//��ȡshader�ļ��������룬��shader.h����
44+
Shader ourShader("shader.vs", "shader.frag");
45+
46+
47+
// һά���飬ÿ��������һ���������ԣ�ǰ��������λ�����ԣ�������������ɫ����
48+
GLfloat vertices[] = {
49+
// Positions // Colors
50+
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Right
51+
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // Bottom Left
52+
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // Top
53+
};
54+
GLuint VBO, VAO;//�������㻺�壬���������������ڹ�����������
55+
glGenVertexArrays(1, &VAO);//�����������飬����һ����һ�޶�����������ʶ����
56+
glGenBuffers(1, &VBO);//�������㻺�壬����һ����һ�޶�����������ʶ������
57+
58+
glBindVertexArray(VAO);//�󶨶�������
59+
glBindBuffer(GL_ARRAY_BUFFER, VBO);//�󶨶��㻺��
60+
//ָ���������������ԴΪvertices�����ĸ����������Կ���ι������������ݣ�GL_STATIC_DRWA������������ı�
61+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
62+
63+
// ָ���������ԵĽ�����ʽ��������δӶ��㻺���ȡ��Ӧ�Ķ������Ժ���Ӧ����ɫ���ԡ�����˵��������ɫ�������֪��ȥ�ĸ��������Է�������ɫ��
64+
//��ÿһ��������ԣ�������2�֣�һ��λ�����ԣ�������ɫ���ԣ����ÿ����������������һ�������λ�ú���ɫ
65+
66+
//������ɫ����ʹ��layout(location = 0)������position�������Ե�λ��ֵ(Location)����˵�һ���������������Է���������
67+
//������������λ�����Ե�ά�ȣ��������������������������ͣ�������:�Ƿ��׼���������壬����λ�����Ե����ֽڳ��ȣ����������ڻ��������е�ƫ����������ʼλ��
68+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
69+
glEnableVertexAttribArray(0);//��������0����ΪĬ���ǽ��õ�
70+
71+
// ����һ����Ӧ������ɫ���е�layout (location = 1) in vec3 color;��������˵����ɫ���Ե�ƫ������������������������verticesһ��
72+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
73+
glEnableVertexAttribArray(1);//��������1.
74+
75+
//�����������(Vertex Array Object, VAO)�ĺô����ǣ������ö�������ָ��ʱ����ֻ��Ҫ������Ĵ������ִ��һ�Σ�֮���ٻ��������ʱ��ֻ��Ҫ����Ӧ��VAO�����ˡ�������ѭ���еİ��ٽ��
76+
glBindVertexArray(0); // ��� VAO
77+
// Game loop
78+
while (!glfwWindowShouldClose(window))
79+
{
80+
// ����¼���������Ӧ�Ļص������������ĵ�key_callback����
81+
glfwPollEvents();
82+
83+
// Render
84+
// Clear the colorbuffer
85+
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);//��Ⱦ��ɫ����̨����
86+
glClear(GL_COLOR_BUFFER_BIT);//���ǰ̨����
87+
88+
// Draw the triangle
89+
ourShader.Use();//������ɫ������
90+
glBindVertexArray(VAO);//ÿ��ѭ�������ã��󶨺�����VAO
91+
glDrawArrays(GL_TRIANGLES, 0, 3);
92+
glBindVertexArray(0);//���
93+
94+
// Swap the screen buffers
95+
glfwSwapBuffers(window);
96+
}
97+
// Properly de-allocate all resources once they've outlived their purpose
98+
glDeleteVertexArrays(1, &VAO);
99+
glDeleteBuffers(1, &VBO);
100+
// Terminate GLFW, clearing any resources allocated by GLFW.
101+
glfwTerminate();
102+
return 0;
103+
}
104+
105+
106+
// Is called whenever a key is pressed/released via GLFW
107+
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
108+
{
109+
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
110+
glfwSetWindowShouldClose(window, GL_TRUE);
111+
}

Templates/GLFW_shader.frag.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 330 core
2+
in vec3 ourColor;
3+
out vec4 color;
4+
5+
void main()
6+
{
7+
color = vec4(ourColor, 1.0f);
8+
}

Templates/GLFW_shader.h.txt

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef SHADER_H
2+
#define SHADER_H
3+
4+
#include <string>
5+
#include <fstream>
6+
#include <sstream>
7+
#include <iostream>
8+
9+
#include <GL/glew.h>
10+
11+
class Shader
12+
{
13+
public:
14+
GLuint Program;
15+
// Constructor generates the shader on the fly
16+
Shader(const GLchar* vertexPath, const GLchar* fragmentPath)
17+
{
18+
// 1. Retrieve the vertex/fragment source code from filePath
19+
std::string vertexCode;
20+
std::string fragmentCode;
21+
std::ifstream vShaderFile;
22+
std::ifstream fShaderFile;
23+
// ensures ifstream objects can throw exceptions:
24+
vShaderFile.exceptions(std::ifstream::badbit);
25+
fShaderFile.exceptions(std::ifstream::badbit);
26+
try
27+
{
28+
// Open files
29+
vShaderFile.open(vertexPath);
30+
fShaderFile.open(fragmentPath);
31+
std::stringstream vShaderStream, fShaderStream;
32+
// Read file's buffer contents into streams
33+
vShaderStream << vShaderFile.rdbuf();
34+
fShaderStream << fShaderFile.rdbuf();
35+
// close file handlers
36+
vShaderFile.close();
37+
fShaderFile.close();
38+
// Convert stream into string
39+
vertexCode = vShaderStream.str();
40+
fragmentCode = fShaderStream.str();
41+
}
42+
catch (std::ifstream::failure e)
43+
{
44+
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
45+
}
46+
const GLchar* vShaderCode = vertexCode.c_str();
47+
const GLchar * fShaderCode = fragmentCode.c_str();
48+
// 2. Compile shaders
49+
GLuint vertex, fragment;
50+
GLint success;
51+
GLchar infoLog[512];
52+
// Vertex Shader
53+
vertex = glCreateShader(GL_VERTEX_SHADER);//����������ɫ��
54+
glShaderSource(vertex, 1, &vShaderCode, NULL);//ָ��Դ����
55+
glCompileShader(vertex);//������ɫ��
56+
// Print compile errors if any
57+
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);//�鿴�Ƿ����ɹ�
58+
if (!success)
59+
{
60+
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
61+
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
62+
}
63+
// Fragment Shader
64+
fragment = glCreateShader(GL_FRAGMENT_SHADER);//����Ƭ����ɫ��
65+
glShaderSource(fragment, 1, &fShaderCode, NULL);
66+
glCompileShader(fragment);
67+
// Print compile errors if any
68+
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
69+
if (!success)
70+
{
71+
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
72+
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
73+
}
74+
// Shader Program
75+
this->Program = glCreateProgram();//������ɫ����
76+
glAttachShader(this->Program, vertex);//����������ɫ��
77+
glAttachShader(this->Program, fragment);//����Ƭ����ɫ��
78+
glLinkProgram(this->Program);//���ӱ�����
79+
// Print linking errors if any
80+
glGetProgramiv(this->Program, GL_LINK_STATUS, &success);
81+
if (!success)
82+
{
83+
glGetProgramInfoLog(this->Program, 512, NULL, infoLog);
84+
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
85+
}
86+
// Delete the shaders as they're linked into our program now and no longer necessery
87+
glDeleteShader(vertex);
88+
glDeleteShader(fragment);
89+
90+
}
91+
// Uses the current shader
92+
void Use()
93+
{
94+
glUseProgram(this->Program);
95+
}
96+
};
97+
98+
#endif

Templates/GLFW_shader.vs.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#version 330 core
2+
layout (location = 0) in vec3 position;//in �������������� location��������Ķ������������йء�
3+
layout (location = 1) in vec3 color;
4+
5+
out vec3 ourColor;//out �������3ά��������ΪƬ����ɫ�������룬������
6+
7+
void main()
8+
{
9+
gl_Position = vec4(position, 1.0f);
10+
ourColor = color;
11+
}

0 commit comments

Comments
 (0)