Skip to content

Commit b92cfd8

Browse files
committed
check SDL anti aliasing line
1 parent 08743e1 commit b92cfd8

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

include/util.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _UTIL_H_
2+
#define _UTIL_H_
3+
4+
class Util;
5+
6+
static inline void swap(int* a, int* b);
7+
8+
// returns absolute value of number
9+
static inline float absolute(float x);
10+
11+
// returns integer part of a floating point number
12+
static inline int iPartOfNumber(float x);
13+
14+
// rounds off a number
15+
static inline int roundNumber(float x);
16+
17+
// returns fractional part of a number
18+
static inline float fPartOfNumber(float x);
19+
20+
// returns 1 - fractional part of number
21+
static inline float rfPartOfNumber(float x);
22+
23+
#endif //_UTIL_H_

src/main.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ float rfPartOfNumber(float x) { return 1 - fPartOfNumber(x); }
7070
// 0<=brightness<=1. We can use your own library
7171
// to draw on screen
7272
void drawPixel(int x, int y, float brightness) {
73+
// 255,192,203
7374
int c = 255 * brightness;
74-
SDL_SetRenderDrawColor(pRenderer, c, c, c, 255);
75+
int r = 255 * brightness;
76+
int g = 192 * brightness;
77+
int b = 203 * brightness;
78+
SDL_SetRenderDrawColor(pRenderer, r, g, b, 255);
7579
SDL_RenderDrawPoint(pRenderer, x, y);
7680
}
7781

@@ -144,7 +148,7 @@ int sdl() {
144148
SDL_RenderClear(pRenderer);
145149

146150
// draws a black AALine
147-
drawAALine(80, 200, 550, 150);
151+
drawAALine(80, 10, 550, 150);
148152

149153
// show the window
150154
SDL_RenderPresent(pRenderer);

src/util.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "util.h"
2+
3+
static inline void swap(int* a, int* b) {
4+
int temp = *a;
5+
*a = *b;
6+
*b = temp;
7+
}
8+
9+
// returns absolute value of number
10+
static inline float absolute(float x) {
11+
if (x < 0)
12+
return -x;
13+
else
14+
return x;
15+
}
16+
17+
// returns integer part of a floating point number
18+
static inline int iPartOfNumber(float x) { return (int)x; }
19+
20+
// rounds off a number
21+
static inline int roundNumber(float x) { return iPartOfNumber(x + 0.5); }
22+
23+
// returns fractional part of a number
24+
static inline float fPartOfNumber(float x) {
25+
if (x > 0)
26+
return x - iPartOfNumber(x);
27+
else
28+
return x - (iPartOfNumber(x) + 1);
29+
}
30+
31+
// returns 1 - fractional part of number
32+
static inline float rfPartOfNumber(float x) { return 1 - fPartOfNumber(x); }

0 commit comments

Comments
 (0)