1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#include <stdio.h>
#include "util.h"
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include "glfww.h"
int w,h;
GLFWwindow* glfw_init(){
GLFWwindow* window;
if(!glfwInit())
err("failed to init glfw",pexit);
window = glfwCreateWindow(800,500,"nya",NULL,NULL);
if(!window){
glfwTerminate();
err("failed to create window",pexit);
}
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_COLOR_ARRAY);
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwMakeContextCurrent(window);
int w,h;
glfwGetFramebufferSize(window,&w,&h);
glViewport(0,0,w,h);
info("yay:D i made a window uwu");
return window;
/*
while(!glfwWindowShouldClose(window)){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POINTS);
for(float x = 0.0; x!=200.0;x+=1.0){
ab_to_vp(ax,ay,w,h,x,x);
glVertex2f(ax,ay);
}
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
*/
}
void refresh_size(GLFWwindow*wi){
glfwGetFramebufferSize(wi,&w,&h);
//printf("%i,%i\n",w,h);
}
int get_w(){
return w;
}
int get_h(){
return h;
}
#define glfw_load(w) glfwSwapBuffers(w);
void glfw_loop(GLFWwindow*window){
while(!glfwWindowShouldClose(window)){
//glfw_load(window);
glfwPollEvents();
}
glfwTerminate();
}
void glfw_pixel_partial(GLFWwindow*wi,int x, int y){
ab_to_vp(ax,ay,w,h,x,y);
glVertex2f(ax,ay);
}
void glfw_clear(GLFWwindow*w){
glClear(GL_COLOR_BUFFER_BIT);
}
void glfw_circle(GLFWwindow* wi,int x, int y, int r){
//SDL_SetRenderDrawColor(w.r,255,255,0,0);
glfwGetFramebufferSize(wi,&w,&h);
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
for(int i = 1; i!=360; i++){
float cf = cosf(i)*r;
float sf = sinf(i)*r;
//for(int z = 1; z<=r; z++){
//int x2 = x + z * cf;
//int y2 = y + z * sf;
glfw_pixel_partial(wi,x+cf,y+sf);
//}
}
glEnd();
}
void glfw_circle_partial(GLFWwindow* wi,int x, int y, int r){
//SDL_SetRenderDrawColor(w.r,255,255,0,0);
if(r==0){
glfw_pixel_partial(wi,x,y);
return;
}
for(int i = 1; i!=360; i++){
float cf = cosf(i)*r;
float sf = sinf(i)*r;
//for(int z = 1; z<=r; z++){
//int x2 = x + z * cf;
//int y2 = y + z * sf;
glfw_pixel_partial(wi,x+cf,y+sf);
//}
}
}
void glfw_square(GLFWwindow* wi,int x, int y, int r){
//SDL_SetRenderDrawColor(w.r,255,255,0,0);
glfwGetFramebufferSize(wi,&w,&h);
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
for(int i = 0; i<=r; i++){
for(int j = 0; j<=r; j++){
glfw_pixel_partial(wi,i-r/2+x,j-r/2+y);
}
}
glEnd();
}
int __glw_main(){
GLFWwindow* w = glfw_init();
glfw_circle(w,50,50,20);
glfw_load(w);
sleep(5);
glfwTerminate();
//glfw_loop(w);
return 0;
}
|