glut -> glfw
This commit is contained in:
parent
c86bab2d8a
commit
0d8fd653a5
4
Makefile
4
Makefile
|
@ -6,7 +6,7 @@
|
|||
# By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2020/12/17 19:47:03 by gbrochar #+# #+# #
|
||||
# Updated: 2020/12/24 12:29:48 by gbrochar ### ########.fr #
|
||||
# Updated: 2020/12/25 14:54:54 by gbrochar ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -38,7 +38,7 @@ SRC = $(addprefix $(SRC_DIR), $(SRC_FILE))
|
|||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
||||
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
||||
|
||||
LIB = -lm -lGL -lglut -lGLEW
|
||||
LIB = -lm -lGL -lglfw -lGLEW
|
||||
|
||||
CC = gcc
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/24 14:32:38 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/25 14:54:37 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
|||
# include <math.h>
|
||||
|
||||
# include <GL/glew.h>
|
||||
# include <GL/freeglut.h>
|
||||
# include <GLFW/glfw3.h>
|
||||
|
||||
# define SUCCESS 0
|
||||
# define FAILURE -1
|
||||
|
@ -117,6 +117,6 @@ void init_camera(t_env *e);
|
|||
void init_object(t_env *e);
|
||||
void init_env(t_env *e);
|
||||
|
||||
void run(t_env *e);
|
||||
int run(t_env *e);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 12:02:14 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/23 20:30:48 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/25 14:58:03 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -19,7 +19,10 @@ int main(int argc, char **argv)
|
|||
|
||||
init_env(&e);
|
||||
if (parse(&e, argc, argv) == SUCCESS)
|
||||
run(&e);
|
||||
{
|
||||
if (run(&e) == FAILURE)
|
||||
printf("Error with glfw initialization\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
free_env(&e);
|
||||
|
|
67
src/run.c
67
src/run.c
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/23 19:38:05 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/24 14:39:39 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/25 14:54:28 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -70,14 +70,14 @@ static void RenderSceneCB()
|
|||
|
||||
glDisableVertexAttribArray(0);
|
||||
|
||||
glutSwapBuffers();
|
||||
// glutSwapBuffers();
|
||||
}
|
||||
|
||||
static void InitializeGlutCallbacks(void)
|
||||
{
|
||||
glutDisplayFunc(RenderSceneCB);
|
||||
glutIdleFunc(RenderSceneCB);
|
||||
}
|
||||
// static void InitializeGlutCallbacks(void)
|
||||
// {
|
||||
// // glutDisplayFunc(RenderSceneCB);
|
||||
// // glutIdleFunc(RenderSceneCB);
|
||||
// }
|
||||
|
||||
static void CreateVertexBuffer(t_env *e)
|
||||
{
|
||||
|
@ -187,22 +187,38 @@ static void CompileShaders()
|
|||
assert(gModelLocation != 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
void run(t_env *e)
|
||||
int run(t_env *e)
|
||||
{
|
||||
int argc = 1;
|
||||
char *argv[1];
|
||||
// int argc = 1;
|
||||
// char *argv[1];
|
||||
|
||||
argv[0] = strdup("scop");
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
|
||||
glutInitWindowSize(e->window.width, e->window.height);
|
||||
glutInitWindowPosition(100, 100);
|
||||
glutCreateWindow("scop");
|
||||
// argv[0] = strdup("scop");
|
||||
// glutInit(&argc, argv);
|
||||
// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
|
||||
// glutInitWindowSize(e->window.width, e->window.height);
|
||||
// glutInitWindowPosition(100, 100);
|
||||
// glutCreateWindow("scop");
|
||||
|
||||
GLFWwindow* window;
|
||||
|
||||
/* Initialize the library */
|
||||
if (!glfwInit())
|
||||
return (FAILURE);
|
||||
|
||||
/* Create a windowed mode window and its OpenGL context */
|
||||
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
return (FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
index_count = e->object.indices.ptr;
|
||||
printf("%ld\n", e->object.indices.ptr);
|
||||
printf("%ld\n", e->object.vertices.ptr);
|
||||
InitializeGlutCallbacks();
|
||||
// InitializeGlutCallbacks();
|
||||
// Must be done after glut is initialized !
|
||||
GLenum res = glewInit();
|
||||
if (res != GLEW_OK)
|
||||
|
@ -214,5 +230,20 @@ void run(t_env *e)
|
|||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
CreateVertexBuffer(e);
|
||||
CompileShaders();
|
||||
glutMainLoop();
|
||||
/* Loop until the user closes the window */
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
/* Render here */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
RenderSceneCB();
|
||||
/* Swap front and back buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
/* Poll for and process events */
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
return (SUCCESS);
|
||||
}
|
Loading…
Reference in New Issue