Browse code

Merge branch 'makefile' into cpp

Robert Cranston authored on 27/02/2024 02:27:46
Showing 4 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,49 @@
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
+
12
+PROG = tsbk07
13
+COMMON = \
14
+	common/GL_utilities.c \
15
+	common/LoadTGA.c \
16
+	common/$(OS)/$(MICROGLUT)
17
+CPPFLAGS += \
18
+	-Icommon \
19
+	-Icommon/$(OS) \
20
+	-DGL_GLEXT_PROTOTYPES
21
+CXXFLAGS += \
22
+	-g \
23
+	-Wall \
24
+	-Wextra \
25
+	-Wpedantic \
26
+	-Wshadow
27
+LDLIBS_Windows += \
28
+	-lopengl32
29
+LDLIBS_Linux += \
30
+	-lX11 \
31
+	-lGL
32
+LDLIBS_Mac += \
33
+	-framework Cocoa \
34
+	-framework OpenGL
35
+LDLIBS += \
36
+	$(LDLIBS_$(OS))
37
+
38
+# The below is equivalent to the GNU Make implicit rule for
39
+# $(PROG): $(COMMON)
40
+$(PROG): $(PROG).cpp $(COMMON)
41
+	g++ $(CXXFLAGS) $(CPPFLAGS) $(PROG).cpp $(COMMON) $(LDLIBS) -o $(PROG)
42
+
43
+.PHONY: clean
44
+clean:
45
+	rm $(PROG)
46
+
47
+.PHONY: run
48
+run: $(PROG)
49
+	./$(PROG)
... ...
@@ -83,6 +83,8 @@ static char gRunning = 1;
83 83
 
84 84
 void glutInit(int *argc, char *argv[])
85 85
 {
86
+	(void)argc;
87
+	(void)argv;
86 88
 	gettimeofday(&timeStart, NULL);
87 89
 	memset(gKeymap, 0, sizeof(gKeymap));
88 90
 }
... ...
@@ -110,16 +112,13 @@ static void checktimers();
110 112
  */
111 113
 
112 114
 static void
113
-make_window( Display *dpy, const char *name,
114
-             int x, int y, int width, int height,
115
-             Window *winRet, GLXContext *ctxRet)
115
+make_window( const char *name,
116
+             int x, int y, int width, int height)
116 117
 {
117 118
    int scrnum;
118 119
    XSetWindowAttributes attr;
119 120
    unsigned long mask;
120 121
    Window root;
121
-   Window win;
122
-   GLXContext ctx;
123 122
    XVisualInfo *visinfo;
124 123
 
125 124
    scrnum = DefaultScreen( dpy );
... ...
@@ -305,9 +304,6 @@ make_window( Display *dpy, const char *name,
305 304
    }
306 305
 
307 306
    XFree(visinfo);
308
-
309
-   *winRet = win;
310
-   *ctxRet = ctx;
311 307
 }
312 308
 
313 309
 void glutCreateWindow(const char *windowTitle)
... ...
@@ -319,7 +315,7 @@ void glutCreateWindow(const char *windowTitle)
319 315
 	     windowTitle ? windowTitle : getenv("DISPLAY"));
320 316
    }
321 317
 
322
-   make_window(dpy, windowTitle, winPosX, winPosY, winWidth, winHeight, &win, &ctx);
318
+   make_window(windowTitle, winPosX, winPosY, winWidth, winHeight);
323 319
    
324 320
    XMapWindow(dpy, win);
325 321
    glXMakeCurrent(dpy, win, ctx);
... ...
@@ -455,6 +451,7 @@ void doKeyboardEvent(XEvent event, void (*keyProc)(unsigned char key, int x, int
455 451
 
456 452
 void internaltimer(int x)
457 453
 {
454
+	(void)x;
458 455
 	glutPostRedisplay();
459 456
 }
460 457
 
... ...
@@ -479,7 +476,7 @@ void glutMainLoop()
479 476
          switch (event.type)
480 477
          {
481 478
          	case ClientMessage:
482
-         		if (event.xclient.data.l[0] == wmDeleteMessage) // quit!
479
+         		if ((Atom)event.xclient.data.l[0] == wmDeleteMessage) // quit!
483 480
          			gRunning = 0;
484 481
 	         	break;
485 482
          	case Expose: 
... ...
@@ -49,7 +49,7 @@ bool LoadTGATextureData(const char *filename, TextureData *texture)	// Loads A T
49 49
 	GLubyte *rowP;
50 50
 	int err;
51 51
 	GLubyte rle;
52
-	int b;
52
+	GLuint b;
53 53
 	long row, rowLimit;
54 54
 	GLubyte pixelData[4];	
55 55
 	
... ...
@@ -199,7 +199,7 @@ bool LoadTGATextureData(const char *filename, TextureData *texture)	// Loads A T
199 199
 	}
200 200
 
201 201
 	if (bytesPerPixel >= 3) // if not monochrome	
202
-	for (i = 0; i < (int)(imageSize); i += bytesPerPixel)	// Loop Through The Image Data
202
+	for (i = 0; i < imageSize; i += bytesPerPixel)	// Loop Through The Image Data
203 203
 	{		// Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
204 204
 		temp = texture->imageData[i];		// Temporarily Store The Value At Image Data 'i'
205 205
 		texture->imageData[i] = texture->imageData[i + 2];	// Set The 1st Byte To The Value Of The 3rd Byte
206 206
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
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
-