# HG changeset patch # User John Tsiombikas # Date 1434588905 -10800 # Node ID a460b1e5af4a5a943b99bd8c80bf7aa8b5235501 # Parent ac80210d5fbed34795902b018252bf8d03ae7f62 added GLUT frontend diff -r ac80210d5fbe -r a460b1e5af4a .hgignore --- a/.hgignore Thu Jun 18 03:12:30 2015 +0300 +++ b/.hgignore Thu Jun 18 03:55:05 2015 +0300 @@ -8,7 +8,8 @@ ^android/res/ ^android/gen/ ^android/assets/ -^data/ +^data +^photoshoot3d$ \.properties$ \.apk$ ^android/proguard-project\.txt diff -r ac80210d5fbe -r a460b1e5af4a Makefile --- a/Makefile Thu Jun 18 03:12:30 2015 +0300 +++ b/Makefile Thu Jun 18 03:55:05 2015 +0300 @@ -1,18 +1,18 @@ root = . include $(root)/proj.mk -src += $(wildcard $(root)/src/glut/*.c) +src += $(wildcard $(root)/src/pc/*.c) obj = $(src:.c=.o) $(ccsrc:.cc=.o) ifeq ($(shell uname -s), Darwin) - libgl = -framework OpenGL -framework GLUT + libgl = -framework OpenGL -framework GLUT -lGLEW else - libgl = -lGL -lGLU -lglut + libgl = -lGL -lGLU -lglut -lGLEW endif CXXFLAGS = -pedantic -Wall -g $(defs) -I$(root)/src/glut $(incpaths) CFLAGS = $(CXXFLAGS) -LDFLAGS = $(libpaths) $(libs) $(libgl) +LDFLAGS = $(libpaths) $(libs) $(libgl) -ldl -lpthread $(bin): $(obj) $(CXX) -o $@ $(obj) $(LDFLAGS) diff -r ac80210d5fbe -r a460b1e5af4a src/game.cc --- a/src/game.cc Thu Jun 18 03:12:30 2015 +0300 +++ b/src/game.cc Thu Jun 18 03:55:05 2015 +0300 @@ -164,9 +164,9 @@ gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_mult_matrixf(rmat[0]); - gl_apply_xform(sdr_debug->get_globj()); sdr_debug->bind(); + gl_apply_xform(sdr_debug->get_globj()); mesh->draw(); diff -r ac80210d5fbe -r a460b1e5af4a src/pc/assman.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pc/assman.c Thu Jun 18 03:55:05 2015 +0300 @@ -0,0 +1,28 @@ +#include +#include "assman.h" + +ass_file *ass_fopen(const char *fname, const char *mode) +{ + return (ass_file*)fopen(fname, mode); +} + +void ass_fclose(ass_file *fp) +{ + fclose(fp); +} + +long ass_fseek(ass_file *fp, long offs, int whence) +{ + fseek(fp, offs, whence); + return ftell(fp); +} + +long ass_ftell(ass_file *fp) +{ + return ftell(fp); +} + +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp) +{ + return fread(buf, size, count, fp); +} diff -r ac80210d5fbe -r a460b1e5af4a src/pc/camera.c --- a/src/pc/camera.c Thu Jun 18 03:12:30 2015 +0300 +++ b/src/pc/camera.c Thu Jun 18 03:55:05 2015 +0300 @@ -1,42 +1,117 @@ +#include +#include "opengl.h" #include "camera.h" +static unsigned int tex; +static float tex_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + +#define TESTPAT_WIDTH 256 +#define TESTPAT_HEIGHT 256 + int cam_init(void *platform_data) { + unsigned char pal[2][2][3] = { + {{255, 128, 64}, {64, 128, 255}}, + {{128, 255, 64}, {128, 64, 255}} + }; + + int i, j; + unsigned char pixels[TESTPAT_WIDTH * TESTPAT_HEIGHT * 3]; + unsigned char *pptr = pixels; + + for(i=0; i> 3) & 1) == ((j >> 3) & 1); + float x = 2.0 * (float)j / (float)TESTPAT_WIDTH - 1.0; + float y = 2.0 * (float)i / (float)TESTPAT_HEIGHT - 1.0; + float len = sqrt(x * x + y * y); + float wave = cos(len * 4.0 * M_PI); + int band = wave >= 0 ? 0 : 1; + + *pptr++ = pal[band][chess][0]; + *pptr++ = pal[band][chess][1]; + *pptr++ = pal[band][chess][2]; + } + } + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TESTPAT_WIDTH, TESTPAT_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + return 0; +} + +void cam_shutdown(void) +{ + glDeleteTextures(1, &tex); +} + +unsigned int cam_texture(void) +{ + return tex; +} + +const float *cam_texture_matrix(void) +{ + return tex_matrix; +} + +int cam_start_video(void) +{ + return 0; +} + +int cam_stop_video(void) +{ + return 0; +} + +int cam_update(void) +{ + return 0; +} + +int cam_is_capturing(void) +{ + return 1; +} + +int cam_video_size(int *xsz, int *ysz) +{ + *xsz = TESTPAT_WIDTH; + *ysz = TESTPAT_HEIGHT; + return 0; +} + +int cam_take_picture(void) +{ return -1; } -void cam_shutdown(void) +void cam_draw_preview(void) { + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + glUseProgram(0); + + glBindTexture(GL_TEXTURE_2D, tex); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + glEnd(); + + glPopAttrib(); } - -unsigned int cam_texture(void) -{ -} - -const float *cam_texture_matrix(void) -{ -} - -int cam_start_video(void) -{ -} - -int cam_stop_video(void) -{ -} - -int cam_update(void) -{ -} - -int cam_is_capturing(void) -{ -} - -int cam_video_size(int *xsz, int *ysz) -{ -} - -int cam_take_picture(void) -{ -} diff -r ac80210d5fbe -r a460b1e5af4a src/pc/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pc/main.c Thu Jun 18 03:55:05 2015 +0300 @@ -0,0 +1,113 @@ +#include +#include +#include "opengl.h" +#include +#include "game.h" +#include "camera.h" +#include "timer.h" + +static int init(void); +static void cleanup(void); +static void display(void); +static void idle(void); +static void reshape(int x, int y); +static void keyb(unsigned char key, int x, int y); +static void keyb_release(unsigned char key, int x, int y); +static void mouse(int bn, int state, int x, int y); +static void motion(int x, int y); +static void sball_motion(int x, int y, int z); +static void sball_rotate(int x, int y, int z); + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitWindowSize(800, 600); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + glutCreateWindow("3dphotoshoot (PC)"); + + glutDisplayFunc(display); + glutIdleFunc(idle); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyb); + glutKeyboardUpFunc(keyb_release); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutSpaceballMotionFunc(sball_motion); + glutSpaceballRotateFunc(sball_rotate); + + if(init() == -1) { + return 1; + } + atexit(cleanup); + + glutMainLoop(); + return 0; +} + +static int init(void) +{ + glewInit(); + + if(cam_init(0) == -1) { + return -1; + } + + if(game_init() == -1) { + return -1; + } + return 0; +} + +static void cleanup(void) +{ + game_shutdown(); +} + +static void display(void) +{ + game_display(get_time_msec()); + glutSwapBuffers(); +} + +static void idle(void) +{ + glutPostRedisplay(); +} + +static void reshape(int x, int y) +{ + game_reshape(x, y); +} + +static void keyb(unsigned char key, int x, int y) +{ + switch(key) { + case 27: + exit(0); + } + + game_keyboard(key, 1); +} + +static void keyb_release(unsigned char key, int x, int y) +{ + game_keyboard(key, 0); +} + +static void mouse(int bn, int state, int x, int y) +{ + game_mouse_button(0, bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y); +} + +static void motion(int x, int y) +{ + game_mouse_motion(0, x, y); +} + +static void sball_motion(int x, int y, int z) +{ +} + +static void sball_rotate(int x, int y, int z) +{ +} diff -r ac80210d5fbe -r a460b1e5af4a src/sanegl.c --- a/src/sanegl.c Thu Jun 18 03:12:30 2015 +0300 +++ b/src/sanegl.c Thu Jun 18 03:55:05 2015 +0300 @@ -286,7 +286,7 @@ double ndcy = 2.0 * (winy - viewp[1]) / viewp[3] - 1.0; double ndcz = 2.0 * winz - 1.0; - // calculate modelviewprojection + /* calculate modelviewprojection */ gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_matrixd(proj); @@ -294,10 +294,10 @@ gl_get_doublev(GL_MODELVIEW_MATRIX, mvp); gl_pop_matrix(); - // invert modelviewprojection + /* invert modelviewprojection */ m4_inverse(inv_mvp, mvp); - // transform ndc by modelview -> obj + /* transform ndc by modelview -> obj */ /**objx = inv_mvp[0] * ndcx + inv_mvp[4] * ndcy + inv_mvp[8] * ndcz + inv_mvp[12]; *objy = inv_mvp[1] * ndcx + inv_mvp[5] * ndcy + inv_mvp[9] * ndcz + inv_mvp[13]; *objz = inv_mvp[2] * ndcx + inv_mvp[6] * ndcy + inv_mvp[10] * ndcz + inv_mvp[14];*/