Browse code

Standardize OpenGL-related #includes and #defines

We use glXGetProcAddress to load glXCreateContextAttribsARB ourselves,
so GLX_GLXEXT_PROTOTYPES is not needed.

Robert Cranston authored on 27/02/2024 02:27:47
Showing 1 changed files
... ...
@@ -16,8 +16,7 @@ COMMON = \
16 16
 	common/$(OS)/$(MICROGLUT)
17 17
 CPPFLAGS += \
18 18
 	-Icommon \
19
-	-Icommon/$(OS) \
20
-	-DGL_GLEXT_PROTOTYPES
19
+	-Icommon/$(OS)
21 20
 CXXFLAGS += \
22 21
 	-g \
23 22
 	-Wall \
Browse code

Add `.PHONY` target

Robert Cranston authored on 10/11/2024 21:32:16
Showing 1 changed files
... ...
@@ -40,8 +40,10 @@ LDLIBS += \
40 40
 $(PROG): $(PROG).cpp $(COMMON)
41 41
 	g++ $(CXXFLAGS) $(CPPFLAGS) $(PROG).cpp $(COMMON) $(LDLIBS) -o $(PROG)
42 42
 
43
+.PHONY: clean
43 44
 clean:
44 45
 	rm $(PROG)
45 46
 
47
+.PHONY: run
46 48
 run: $(PROG)
47 49
 	./$(PROG)
Browse code

Add `run` target

Robert Cranston authored on 10/11/2024 21:29:49
Showing 1 changed files
... ...
@@ -42,3 +42,6 @@ $(PROG): $(PROG).cpp $(COMMON)
42 42
 
43 43
 clean:
44 44
 	rm $(PROG)
45
+
46
+run: $(PROG)
47
+	./$(PROG)
Browse code

Add `PROG` variable

Robert Cranston authored on 10/11/2024 21:34:02
Showing 1 changed files
... ...
@@ -9,6 +9,7 @@ else ifeq ($(shell uname),Darwin)
9 9
         MICROGLUT = MicroGlut.m
10 10
 endif
11 11
 
12
+PROG = tsbk07
12 13
 COMMON = \
13 14
 	common/GL_utilities.c \
14 15
 	common/LoadTGA.c \
... ...
@@ -35,9 +36,9 @@ LDLIBS += \
35 36
 	$(LDLIBS_$(OS))
36 37
 
37 38
 # The below is equivalent to the GNU Make implicit rule for
38
-# tsbk07: $(COMMON)
39
-tsbk07: tsbk07.cpp $(COMMON)
40
-	g++ $(CXXFLAGS) $(CPPFLAGS) tsbk07.cpp $(COMMON) $(LDLIBS) -o tsbk07
39
+# $(PROG): $(COMMON)
40
+$(PROG): $(PROG).cpp $(COMMON)
41
+	g++ $(CXXFLAGS) $(CPPFLAGS) $(PROG).cpp $(COMMON) $(LDLIBS) -o $(PROG)
41 42
 
42 43
 clean:
43
-	rm tsbk07
44
+	rm $(PROG)
Browse code

Compile with debugging information

Robert Cranston authored on 10/11/2024 21:28:43
Showing 1 changed files
... ...
@@ -18,6 +18,7 @@ CPPFLAGS += \
18 18
 	-Icommon/$(OS) \
19 19
 	-DGL_GLEXT_PROTOTYPES
20 20
 CXXFLAGS += \
21
+	-g \
21 22
 	-Wall \
22 23
 	-Wextra \
23 24
 	-Wpedantic \
Browse code

Enable and fix more warnings

Robert Cranston authored on 27/02/2024 02:27:44
Showing 1 changed files
... ...
@@ -18,7 +18,10 @@ CPPFLAGS += \
18 18
 	-Icommon/$(OS) \
19 19
 	-DGL_GLEXT_PROTOTYPES
20 20
 CXXFLAGS += \
21
-	-Wall
21
+	-Wall \
22
+	-Wextra \
23
+	-Wpedantic \
24
+	-Wshadow
22 25
 LDLIBS_Windows += \
23 26
 	-lopengl32
24 27
 LDLIBS_Linux += \
Browse code

Switch Makefile to C++

The main rule is now equivalent to a GNU Make implicit rule which is a
good indication that it follows best practices.

Robert Cranston authored on 27/02/2024 02:27:42
Showing 1 changed files
... ...
@@ -28,12 +28,12 @@ LDLIBS_Mac += \
28 28
 	-framework Cocoa \
29 29
 	-framework OpenGL
30 30
 LDLIBS += \
31
-	$(LDLIBS_$(OS)) \
32
-	-lm \
33
-	-lstdc++
31
+	$(LDLIBS_$(OS))
34 32
 
33
+# The below is equivalent to the GNU Make implicit rule for
34
+# tsbk07: $(COMMON)
35 35
 tsbk07: tsbk07.cpp $(COMMON)
36
-	gcc $(CXXFLAGS) -o tsbk07 $(CPPFLAGS) tsbk07.cpp $(COMMON) $(LDLIBS)
36
+	g++ $(CXXFLAGS) $(CPPFLAGS) tsbk07.cpp $(COMMON) $(LDLIBS) -o tsbk07
37 37
 
38 38
 clean:
39 39
 	rm tsbk07
Browse code

Remove extraneous Xt library on Linux

Robert Cranston authored on 27/02/2024 23:46:20
Showing 1 changed files
... ...
@@ -22,7 +22,6 @@ CXXFLAGS += \
22 22
 LDLIBS_Windows += \
23 23
 	-lopengl32
24 24
 LDLIBS_Linux += \
25
-	-lXt \
26 25
 	-lX11 \
27 26
 	-lGL
28 27
 LDLIBS_Mac += \
Browse code

Add OS support to Makefile

Robert Cranston authored on 27/02/2024 02:27:41
Showing 1 changed files
... ...
@@ -1,17 +1,35 @@
1
+ifeq ($(OS),Windows_NT)
2
+        OS = Windows
3
+        MICROGLUT = MicroGlut.c
4
+else ifeq ($(shell uname),Linux)
5
+        OS = Linux
6
+        MICROGLUT = MicroGlut.c
7
+else ifeq ($(shell uname),Darwin)
8
+        OS = Mac
9
+        MICROGLUT = MicroGlut.m
10
+endif
11
+
1 12
 COMMON = \
2 13
 	common/GL_utilities.c \
3 14
 	common/LoadTGA.c \
4
-	common/Linux/MicroGlut.c
15
+	common/$(OS)/$(MICROGLUT)
5 16
 CPPFLAGS += \
6 17
 	-Icommon \
7
-	-Icommon/Linux \
18
+	-Icommon/$(OS) \
8 19
 	-DGL_GLEXT_PROTOTYPES
9 20
 CXXFLAGS += \
10 21
 	-Wall
11
-LDLIBS += \
22
+LDLIBS_Windows += \
23
+	-lopengl32
24
+LDLIBS_Linux += \
12 25
 	-lXt \
13 26
 	-lX11 \
14
-	-lGL \
27
+	-lGL
28
+LDLIBS_Mac += \
29
+	-framework Cocoa \
30
+	-framework OpenGL
31
+LDLIBS += \
32
+	$(LDLIBS_$(OS)) \
15 33
 	-lm \
16 34
 	-lstdc++
17 35
 
Browse code

Modularize Makefile

Robert Cranston authored on 27/02/2024 02:27:40
Showing 1 changed files
... ...
@@ -1,11 +1,22 @@
1
-# set this variable to the director in which you saved the common files
2
-commondir = common/
1
+COMMON = \
2
+	common/GL_utilities.c \
3
+	common/LoadTGA.c \
4
+	common/Linux/MicroGlut.c
5
+CPPFLAGS += \
6
+	-Icommon \
7
+	-Icommon/Linux \
8
+	-DGL_GLEXT_PROTOTYPES
9
+CXXFLAGS += \
10
+	-Wall
11
+LDLIBS += \
12
+	-lXt \
13
+	-lX11 \
14
+	-lGL \
15
+	-lm \
16
+	-lstdc++
3 17
 
4
-all : tsbk07
18
+tsbk07: tsbk07.cpp $(COMMON)
19
+	gcc $(CXXFLAGS) -o tsbk07 $(CPPFLAGS) tsbk07.cpp $(COMMON) $(LDLIBS)
5 20
 
6
-tsbk07 : tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c
7
-	gcc -Wall -o tsbk07 -I$(commondir) -Icommon/Linux -DGL_GLEXT_PROTOTYPES tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c -lXt -lX11 -lGL -lm -lstdc++
8
-
9
-clean :
21
+clean:
10 22
 	rm tsbk07
11
-
Browse code

Rename makefile to Makefile

This is the most common traditional name.

Robert Cranston authored on 27/02/2024 02:27:39
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+# set this variable to the director in which you saved the common files
2
+commondir = common/
3
+
4
+all : tsbk07
5
+
6
+tsbk07 : tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c
7
+	gcc -Wall -o tsbk07 -I$(commondir) -Icommon/Linux -DGL_GLEXT_PROTOTYPES tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c -lXt -lX11 -lGL -lm -lstdc++
8
+
9
+clean :
10
+	rm tsbk07
11
+