aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2014-04-26 18:21:56 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2014-04-26 18:21:56 +0200
commit4542fdb44ae7525b2806233b1d499b1c0202fbf7 (patch)
treee64b1c39c4f988e0d730c2276c209e2083d18776
parent9410ac0867d560bbe0a475c44e2522dbcb2ac4db (diff)
downloadcodesamples-4542fdb44ae7525b2806233b1d499b1c0202fbf7.tar.gz
codesamples-4542fdb44ae7525b2806233b1d499b1c0202fbf7.tar.bz2
rotateable observer
-rw-r--r--.gitmodules3
m---------extra/linmath.h0
-rw-r--r--samples/OpenGL/frustum/frustum.c23
-rw-r--r--samples/OpenGL/minimal_glsl/minimal_glsl.c2
-rw-r--r--samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c8
5 files changed, 26 insertions, 10 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..d03f608
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "extra/linmath.h"]
+ path = extra/linmath.h
+ url = git@github.com:datenwolf/linmath.h.git
diff --git a/extra/linmath.h b/extra/linmath.h
new file mode 160000
+Subproject f7418faa1bffa56a5754f98dcc628fcfbf8606c
diff --git a/samples/OpenGL/frustum/frustum.c b/samples/OpenGL/frustum/frustum.c
index c5732c8..2728cee 100644
--- a/samples/OpenGL/frustum/frustum.c
+++ b/samples/OpenGL/frustum/frustum.c
@@ -412,6 +412,23 @@ struct {
float near, far;
} frustum = {-1, 1, -1, 1, 1, 4};
+struct {
+ struct {
+ float phi, theta;
+ } rot;
+} observer;
+
+void observer_motion(int x, int y)
+{
+ int const win_width = glutGet(GLUT_WINDOW_WIDTH);
+ int const win_height = glutGet(GLUT_WINDOW_HEIGHT);
+
+ observer.rot.phi = -180.f + 360.f * (float)x / (float)win_width;
+ observer.rot.theta = -90.f + 180.f * (float)y / (float)win_height;
+
+ glutPostRedisplay();
+}
+
void display_observer(float frustum_aspect)
{
int const win_width = glutGet(GLUT_WINDOW_WIDTH);
@@ -434,8 +451,8 @@ void display_observer(float frustum_aspect)
glLoadIdentity();
if(1) {
glTranslatef(0, 0, -10);
- glRotatef(15, 1, 0, 0);
- glRotatef(-15, 0, 1, 0);
+ glRotatef(observer.rot.theta, 1, 0, 0);
+ glRotatef(observer.rot.phi, 0, 1, 0);
glTranslatef(0, 0, 2.5);
} else {
gluLookAt(3, 1, -5, 0, 0, -2.5, 0, 1, 0);
@@ -536,6 +553,8 @@ int main(int argc, char *argv[])
window_observer = glutCreateWindow("Observer");
glutDisplayFunc(display);
+ glutMotionFunc(observer_motion);
+ glutPassiveMotionFunc(observer_motion);
window_view = glutCreateWindow("Frustum View");
glutDisplayFunc(display);
diff --git a/samples/OpenGL/minimal_glsl/minimal_glsl.c b/samples/OpenGL/minimal_glsl/minimal_glsl.c
index 2d1b0fa..72ba3ff 100644
--- a/samples/OpenGL/minimal_glsl/minimal_glsl.c
+++ b/samples/OpenGL/minimal_glsl/minimal_glsl.c
@@ -38,7 +38,7 @@ static const GLchar *fragment_shader_source =
"uniform sampler2D texRGB;"
"void main()"
"{"
-" gl_FragColor = -texture2D(texCMYK, gl_TexCoord[0].st) + texture2D(texRGB, gl_TexCoord[0].st);"
+" gl_FragColor = -texture2D(texCMYK, gl_TexCoord[0].st) + texture2D(texRGB, gl_TexCoord[0].st); "
"}\0";
GLuint shaderFragment = 0;
diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
index 0852cbc..7aae5a8 100644
--- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
+++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
@@ -578,14 +578,8 @@ static void redrawTheWindow(double T)
struct timespec Ta, Tb;
- clock_gettime(CLOCK_MONOTONIC_RAW, &Ta);
glXSwapBuffers(Xdisplay, glX_window_handle);
- glXWaitGL();
- clock_gettime(CLOCK_MONOTONIC_RAW, &Tb);
-
- fprintf(stderr, "glXSwapBuffers + glXWaitGL returned after %f ms\n",
- 1e3*( (double)Tb.tv_sec + 1e-9*(double)Tb.tv_nsec ) -
- 1e3*( (double)Ta.tv_sec + 1e-9*(double)Ta.tv_nsec ) );
+ glXWaitGL();
}
static double getftime(void) {