* Edited tests so they use emscripten_main_loop.
* Got triangle test about to work. * Implemented misc functions.
This commit is contained in:
Родитель
94b3f0a692
Коммит
0d05320324
|
@ -2,54 +2,55 @@
|
|||
# Makefile for GLFW example programs on X11 (generated by compile.sh)
|
||||
##########################################################################
|
||||
CC = emcc
|
||||
CFLAGS = -I../include
|
||||
CFLAGS = -I../include -DEMSCRIPTEN
|
||||
|
||||
LIB = -lglfw
|
||||
SOLIB =
|
||||
LFLAGS = $(LIB)
|
||||
SO_LFLAGS = $(SOLIB)
|
||||
EXT = html
|
||||
|
||||
BINARIES = triangle.js listmodes.js mthello.js pong3d.js mtbench.js particles.js splitview.js \
|
||||
mipmaps.js gears.js boing.js heightmap.js
|
||||
BINARIES = triangle listmodes mthello pong3d mtbench particles splitview \
|
||||
mipmaps gears boing heightmap
|
||||
## wave
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
triangle.js: triangle.c
|
||||
$(CC) $(CFLAGS) triangle.c $(LFLAGS) -o $@
|
||||
triangle: triangle.c
|
||||
$(CC) $(CFLAGS) triangle.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
listmodes.js: listmodes.c
|
||||
$(CC) $(CFLAGS) listmodes.c $(LFLAGS) -o $@
|
||||
listmodes: listmodes.c
|
||||
$(CC) $(CFLAGS) listmodes.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
mthello.js: mthello.c
|
||||
$(CC) $(CFLAGS) mthello.c $(LFLAGS) -o $@
|
||||
mthello: mthello.c
|
||||
$(CC) $(CFLAGS) mthello.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
pong3d.js: pong3d.c
|
||||
$(CC) $(CFLAGS) pong3d.c $(LFLAGS) -o $@
|
||||
pong3d: pong3d.c
|
||||
$(CC) $(CFLAGS) pong3d.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
mtbench.js: mtbench.c
|
||||
$(CC) $(CFLAGS) mtbench.c $(LFLAGS) -o $@
|
||||
mtbench: mtbench.c
|
||||
$(CC) $(CFLAGS) mtbench.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
particles.js: particles.c
|
||||
$(CC) $(CFLAGS) particles.c $(LFLAGS) -o $@
|
||||
particles: particles.c
|
||||
$(CC) $(CFLAGS) particles.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
splitview.js: splitview.c
|
||||
$(CC) $(CFLAGS) splitview.c $(LFLAGS) -o $@
|
||||
splitview: splitview.c
|
||||
$(CC) $(CFLAGS) splitview.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
mipmaps.js: mipmaps.c
|
||||
$(CC) $(CFLAGS) mipmaps.c $(LFLAGS) -o $@
|
||||
mipmaps: mipmaps.c
|
||||
$(CC) $(CFLAGS) mipmaps.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
gears.js: gears.c
|
||||
$(CC) $(CFLAGS) gears.c $(LFLAGS) -o $@
|
||||
gears: gears.c
|
||||
$(CC) $(CFLAGS) gears.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
boing.js: boing.c
|
||||
$(CC) $(CFLAGS) boing.c $(LFLAGS) -o $@
|
||||
boing: boing.c
|
||||
$(CC) $(CFLAGS) boing.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
wave.js: wave.c
|
||||
$(CC) $(CFLAGS) wave.c $(LFLAGS) -o $@
|
||||
wave: wave.c
|
||||
$(CC) $(CFLAGS) wave.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
heightmap.js: heightmap.c
|
||||
$(CC) $(CFLAGS) heightmap.c $(LFLAGS) -o $@
|
||||
heightmap: heightmap.c
|
||||
$(CC) $(CFLAGS) heightmap.c $(LFLAGS) -o $@.$(EXT)
|
||||
|
||||
clean:
|
||||
rm -f $(BINARIES)
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
#include <math.h>
|
||||
#include <GL/glfw.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Various declarations and macros
|
||||
|
@ -563,6 +567,19 @@ void DrawGrid( void )
|
|||
* main()
|
||||
*======================================================================*/
|
||||
|
||||
void iteration(){
|
||||
/* Timing */
|
||||
t = glfwGetTime();
|
||||
dt = t - t_old;
|
||||
t_old = t;
|
||||
|
||||
/* Draw one frame */
|
||||
display();
|
||||
|
||||
/* Swap buffers */
|
||||
glfwSwapBuffers();
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int running;
|
||||
|
@ -590,25 +607,18 @@ int main( void )
|
|||
init();
|
||||
|
||||
/* Main loop */
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
do
|
||||
{
|
||||
/* Timing */
|
||||
t = glfwGetTime();
|
||||
dt = t - t_old;
|
||||
t_old = t;
|
||||
|
||||
/* Draw one frame */
|
||||
display();
|
||||
|
||||
/* Swap buffers */
|
||||
glfwSwapBuffers();
|
||||
|
||||
iteration();
|
||||
/* Check if we are still running */
|
||||
running = !glfwGetKey( GLFW_KEY_ESC ) &&
|
||||
glfwGetWindowParam( GLFW_OPENED );
|
||||
}
|
||||
while( running );
|
||||
|
||||
#endif
|
||||
glfwTerminate();
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
#define M_PI 3.141592654
|
||||
#endif
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
/* The program exits when this is zero.
|
||||
*/
|
||||
static int running = 1;
|
||||
|
@ -317,6 +321,22 @@ static void init(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
void iteration(){
|
||||
// Draw gears
|
||||
draw();
|
||||
|
||||
// Update animation
|
||||
animate();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Was the window closed?
|
||||
if( !glfwGetWindowParam( GLFW_OPENED ) )
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* program entry */
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -345,25 +365,15 @@ int main(int argc, char *argv[])
|
|||
glfwSetWindowSizeCallback( reshape );
|
||||
glfwSetKeyCallback( key );
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
while( running )
|
||||
{
|
||||
// Draw gears
|
||||
draw();
|
||||
|
||||
// Update animation
|
||||
animate();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Was the window closed?
|
||||
if( !glfwGetWindowParam( GLFW_OPENED ) )
|
||||
{
|
||||
running = 0;
|
||||
iteration();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
// Terminate GLFW
|
||||
glfwTerminate();
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
#include <stddef.h>
|
||||
#include "getopt.h"
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define GLFW_NO_GLU 1
|
||||
#include <GL/glfw.h>
|
||||
|
@ -674,12 +677,16 @@ static void usage(void)
|
|||
printf(" heightmap [-h]\n");
|
||||
}
|
||||
|
||||
void iteration();
|
||||
|
||||
double dt;
|
||||
int frame;
|
||||
int iter;
|
||||
double last_update_time;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, iter;
|
||||
double dt;
|
||||
double last_update_time;
|
||||
int frame;
|
||||
int ch;
|
||||
float f;
|
||||
GLint uloc_modelview;
|
||||
GLint uloc_project;
|
||||
|
@ -820,8 +827,20 @@ int main(int argc, char** argv)
|
|||
iter = 0;
|
||||
dt = last_update_time = glfwGetTime();
|
||||
|
||||
while (running)
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
while( running )
|
||||
{
|
||||
iteration();
|
||||
}
|
||||
#endif
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void iteration(){
|
||||
++frame;
|
||||
/* render the next frame */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -843,8 +862,5 @@ int main(int argc, char** argv)
|
|||
last_update_time = dt;
|
||||
frame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,66 @@
|
|||
|
||||
#include <GL/glfw.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
int width, height, x;
|
||||
double time;
|
||||
GLboolean running;
|
||||
|
||||
void iteration(){
|
||||
// Get time and mouse position
|
||||
time = glfwGetTime();
|
||||
glfwGetMousePos( &x, NULL );
|
||||
|
||||
// Get window size (may be different than the requested size)
|
||||
glfwGetWindowSize( &width, &height );
|
||||
height = height > 0 ? height : 1;
|
||||
|
||||
// Set viewport
|
||||
glViewport( 0, 0, width, height );
|
||||
|
||||
// Clear color buffer
|
||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
// Select and setup the projection matrix
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( 65.0f, (GLfloat)width / (GLfloat)height, 1.0f,
|
||||
50.0f );
|
||||
|
||||
// Select and setup the modelview matrix
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
gluLookAt( 0.0f, 3.0f, -20.0f, // Eye-position
|
||||
0.0f, -4.0f, -11.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
||||
|
||||
// Draw a textured quad
|
||||
glRotatef( 0.05f * (GLfloat)x + (GLfloat)time * 5.0f, 0.0f, 1.0f, 0.0f );
|
||||
glBegin( GL_QUADS );
|
||||
glTexCoord2f( -20.0f, 20.0f );
|
||||
glVertex3f( -50.0f, 0.0f, -50.0f );
|
||||
glTexCoord2f( 20.0f, 20.0f );
|
||||
glVertex3f( 50.0f, 0.0f, -50.0f );
|
||||
glTexCoord2f( 20.0f, -20.0f );
|
||||
glVertex3f( 50.0f, 0.0f, 50.0f );
|
||||
glTexCoord2f( -20.0f, -20.0f );
|
||||
glVertex3f( -50.0f, 0.0f, 50.0f );
|
||||
glEnd();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Check if the ESC key was pressed or the window was closed
|
||||
running = !glfwGetKey( GLFW_KEY_ESC ) &&
|
||||
glfwGetWindowParam( GLFW_OPENED );
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int width, height, x;
|
||||
double time;
|
||||
GLboolean running;
|
||||
GLuint textureID;
|
||||
char* texturePath = "mipmaps.tga";
|
||||
|
||||
|
@ -63,56 +118,15 @@ int main( void )
|
|||
glEnable( GL_TEXTURE_2D );
|
||||
|
||||
running = GL_TRUE;
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
while( running )
|
||||
{
|
||||
// Get time and mouse position
|
||||
time = glfwGetTime();
|
||||
glfwGetMousePos( &x, NULL );
|
||||
|
||||
// Get window size (may be different than the requested size)
|
||||
glfwGetWindowSize( &width, &height );
|
||||
height = height > 0 ? height : 1;
|
||||
|
||||
// Set viewport
|
||||
glViewport( 0, 0, width, height );
|
||||
|
||||
// Clear color buffer
|
||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
// Select and setup the projection matrix
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( 65.0f, (GLfloat)width / (GLfloat)height, 1.0f,
|
||||
50.0f );
|
||||
|
||||
// Select and setup the modelview matrix
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
gluLookAt( 0.0f, 3.0f, -20.0f, // Eye-position
|
||||
0.0f, -4.0f, -11.0f, // View-point
|
||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
||||
|
||||
// Draw a textured quad
|
||||
glRotatef( 0.05f * (GLfloat)x + (GLfloat)time * 5.0f, 0.0f, 1.0f, 0.0f );
|
||||
glBegin( GL_QUADS );
|
||||
glTexCoord2f( -20.0f, 20.0f );
|
||||
glVertex3f( -50.0f, 0.0f, -50.0f );
|
||||
glTexCoord2f( 20.0f, 20.0f );
|
||||
glVertex3f( 50.0f, 0.0f, -50.0f );
|
||||
glTexCoord2f( 20.0f, -20.0f );
|
||||
glVertex3f( 50.0f, 0.0f, 50.0f );
|
||||
glTexCoord2f( -20.0f, -20.0f );
|
||||
glVertex3f( -50.0f, 0.0f, 50.0f );
|
||||
glEnd();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Check if the ESC key was pressed or the window was closed
|
||||
running = !glfwGetKey( GLFW_KEY_ESC ) &&
|
||||
glfwGetWindowParam( GLFW_OPENED );
|
||||
iteration();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
#include <math.h>
|
||||
#include <GL/glfw.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
// Define tokens for GL_EXT_separate_specular_color if not already defined
|
||||
#ifndef GL_EXT_separate_specular_color
|
||||
#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8
|
||||
|
@ -970,10 +974,34 @@ void GLFWCALL PhysicsThreadFun( void *arg )
|
|||
// main()
|
||||
//========================================================================
|
||||
|
||||
double t0, t;
|
||||
int frames, benchmark;
|
||||
void iteration(){
|
||||
// Get frame time
|
||||
t = glfwGetTime() - t0;
|
||||
|
||||
// Draw...
|
||||
Draw( t );
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Check if window was closed
|
||||
running = running && glfwGetWindowParam( GLFW_OPENED );
|
||||
|
||||
// Increase frame count
|
||||
frames ++;
|
||||
|
||||
// End of benchmark?
|
||||
if( benchmark && t >= 60.0 )
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int i, frames, benchmark;
|
||||
double t0, t;
|
||||
int i;
|
||||
GLFWthread physics_thread = 0;
|
||||
|
||||
// Use multithreading by default, but don't benchmark
|
||||
|
@ -1108,29 +1136,15 @@ int main( int argc, char **argv )
|
|||
// Main loop
|
||||
t0 = glfwGetTime();
|
||||
frames = 0;
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
while( running )
|
||||
{
|
||||
// Get frame time
|
||||
t = glfwGetTime() - t0;
|
||||
|
||||
// Draw...
|
||||
Draw( t );
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
// Check if window was closed
|
||||
running = running && glfwGetWindowParam( GLFW_OPENED );
|
||||
|
||||
// Increase frame count
|
||||
frames ++;
|
||||
|
||||
// End of benchmark?
|
||||
if( benchmark && t >= 60.0 )
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
iteration();
|
||||
}
|
||||
#endif
|
||||
t = glfwGetTime() - t0;
|
||||
|
||||
// Wait for particle physics thread to die
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//========================================================================
|
||||
// Constants
|
||||
|
@ -719,20 +722,9 @@ void GameOver( void )
|
|||
// GameLoop() - Game loop
|
||||
//========================================================================
|
||||
|
||||
void GameLoop( void )
|
||||
{
|
||||
int playing, event;
|
||||
int playing, event;
|
||||
|
||||
// Initialize a new game
|
||||
NewGame();
|
||||
|
||||
// Enable sticky keys
|
||||
glfwEnable( GLFW_STICKY_KEYS );
|
||||
|
||||
// Loop until the game ends
|
||||
playing = GL_TRUE;
|
||||
while( playing && glfwGetWindowParam( GLFW_OPENED ) )
|
||||
{
|
||||
void iteration(){
|
||||
// Frame timer
|
||||
oldtime = thistime;
|
||||
thistime = glfwGetTime();
|
||||
|
@ -784,7 +776,36 @@ void GameLoop( void )
|
|||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
}
|
||||
|
||||
void GameLoop( void )
|
||||
{
|
||||
int menuoption;
|
||||
|
||||
// Initialize a new game
|
||||
NewGame();
|
||||
|
||||
// Enable sticky keys
|
||||
glfwEnable( GLFW_STICKY_KEYS );
|
||||
|
||||
// Loop until the game ends
|
||||
playing = GL_TRUE;
|
||||
|
||||
menuoption = GameMenu();
|
||||
|
||||
// If the user wants to play, let him...
|
||||
if( menuoption != MENU_PLAY)
|
||||
playing = GL_FALSE;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
while( playing && glfwGetWindowParam( GLFW_OPENED ) )
|
||||
{
|
||||
iteration();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Disable sticky keys
|
||||
glfwDisable( GLFW_STICKY_KEYS );
|
||||
|
@ -800,7 +821,6 @@ void GameLoop( void )
|
|||
|
||||
int main( void )
|
||||
{
|
||||
int menuoption;
|
||||
|
||||
// Initialize GLFW
|
||||
if( !glfwInit() )
|
||||
|
@ -826,19 +846,7 @@ int main( void )
|
|||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
// Main loop
|
||||
do
|
||||
{
|
||||
// Get menu option
|
||||
menuoption = GameMenu();
|
||||
|
||||
// If the user wants to play, let him...
|
||||
if( menuoption == MENU_PLAY )
|
||||
{
|
||||
GameLoop();
|
||||
}
|
||||
}
|
||||
while( menuoption != MENU_QUIT );
|
||||
|
||||
// Unload all textures
|
||||
if( glfwGetWindowParam( GLFW_OPENED ) )
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
@ -446,6 +450,23 @@ static void GLFWCALL mouseButtonFun( int button, int action )
|
|||
// main()
|
||||
//========================================================================
|
||||
|
||||
void iteration(){
|
||||
// Only redraw if we need to
|
||||
if( do_redraw )
|
||||
{
|
||||
// Draw all views
|
||||
drawAllViews();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
do_redraw = 0;
|
||||
}
|
||||
|
||||
// Wait for new events
|
||||
glfwWaitEvents();
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
// Initialise GLFW
|
||||
|
@ -484,27 +505,17 @@ int main( void )
|
|||
glfwSetMousePosCallback( mousePosFun );
|
||||
glfwSetMouseButtonCallback( mouseButtonFun );
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
// Main loop
|
||||
do
|
||||
{
|
||||
// Only redraw if we need to
|
||||
if( do_redraw )
|
||||
{
|
||||
// Draw all views
|
||||
drawAllViews();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
|
||||
do_redraw = 0;
|
||||
}
|
||||
|
||||
// Wait for new events
|
||||
glfwWaitEvents();
|
||||
|
||||
iteration();
|
||||
} // Check if the ESC key was pressed or the window was closed
|
||||
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
|
||||
glfwGetWindowParam( GLFW_OPENED ) );
|
||||
#endif
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
|
|
@ -8,87 +8,101 @@
|
|||
#include <stdlib.h>
|
||||
#include <GL/glfw.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
int main( void )
|
||||
void
|
||||
iteration ()
|
||||
{
|
||||
int width, height, x;
|
||||
double t;
|
||||
|
||||
// Initialise GLFW
|
||||
if( !glfwInit() )
|
||||
{
|
||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
// Open a window and create its OpenGL context
|
||||
if( !glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW ) )
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
|
||||
glfwTerminate();
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
glfwSetWindowTitle( "Spinning Triangle" );
|
||||
|
||||
// Ensure we can capture the escape key being pressed below
|
||||
glfwEnable( GLFW_STICKY_KEYS );
|
||||
|
||||
// Enable vertical sync (on cards that support it)
|
||||
glfwSwapInterval( 1 );
|
||||
|
||||
do
|
||||
{
|
||||
t = glfwGetTime();
|
||||
glfwGetMousePos( &x, NULL );
|
||||
t = glfwGetTime ();
|
||||
glfwGetMousePos (&x, NULL);
|
||||
|
||||
// Get window size (may be different than the requested size)
|
||||
glfwGetWindowSize( &width, &height );
|
||||
glfwGetWindowSize (&width, &height);
|
||||
|
||||
// Special case: avoid division by zero below
|
||||
height = height > 0 ? height : 1;
|
||||
|
||||
glViewport( 0, 0, width, height );
|
||||
glViewport (0, 0, width, height);
|
||||
|
||||
// Clear color buffer to black
|
||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear (GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Select and setup the projection matrix
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
gluPerspective (65.0f, (GLfloat) width / (GLfloat) height, 1.0f, 100.0f);
|
||||
|
||||
// Select and setup the modelview matrix
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
gluLookAt( 0.0f, 1.0f, 0.0f, // Eye-position
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
gluLookAt (0.0f, 1.0f, 0.0f, // Eye-position
|
||||
0.0f, 20.0f, 0.0f, // View-point
|
||||
0.0f, 0.0f, 1.0f ); // Up-vector
|
||||
0.0f, 0.0f, 1.0f); // Up-vector
|
||||
|
||||
// Draw a rotating colorful triangle
|
||||
glTranslatef( 0.0f, 14.0f, 0.0f );
|
||||
glRotatef( 0.3f*(GLfloat)x + (GLfloat)t*100.0f, 0.0f, 0.0f, 1.0f );
|
||||
glBegin( GL_TRIANGLES );
|
||||
glColor3f( 1.0f, 0.0f, 0.0f );
|
||||
glVertex3f( -5.0f, 0.0f, -4.0f );
|
||||
glColor3f( 0.0f, 1.0f, 0.0f );
|
||||
glVertex3f( 5.0f, 0.0f, -4.0f );
|
||||
glColor3f( 0.0f, 0.0f, 1.0f );
|
||||
glVertex3f( 0.0f, 0.0f, 6.0f );
|
||||
glEnd();
|
||||
//glTranslatef (0.0f, 14.0f, 0.0f);
|
||||
glTranslatef (0.0f, 1.0f, 0.0f);
|
||||
glRotatef (0.3f * (GLfloat) x + (GLfloat) t * 100.0f, 0.0f, 0.0f, 1.0f);
|
||||
glBegin (GL_TRIANGLES);
|
||||
glColor3f (1.0f, 0.0f, 0.0f);
|
||||
glVertex3f (-5.0f, 0.0f, -4.0f);
|
||||
glColor3f (0.0f, 1.0f, 0.0f);
|
||||
glVertex3f (5.0f, 0.0f, -4.0f);
|
||||
glColor3f (0.0f, 0.0f, 1.0f);
|
||||
glVertex3f (0.0f, 0.0f, 6.0f);
|
||||
glEnd ();
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers();
|
||||
glfwSwapBuffers ();
|
||||
|
||||
} // Check if the ESC key was pressed or the window was closed
|
||||
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
|
||||
glfwGetWindowParam( GLFW_OPENED ) );
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
// Initialise GLFW
|
||||
if (!glfwInit ())
|
||||
{
|
||||
fprintf (stderr, "Failed to initialize GLFW\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Open a window and create its OpenGL context
|
||||
if (!glfwOpenWindow (640, 480, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
||||
{
|
||||
fprintf (stderr, "Failed to open GLFW window\n");
|
||||
|
||||
glfwTerminate ();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetWindowTitle ("Spinning Triangle");
|
||||
|
||||
// Ensure we can capture the escape key being pressed below
|
||||
glfwEnable (GLFW_STICKY_KEYS);
|
||||
|
||||
// Enable vertical sync (on cards that support it)
|
||||
glfwSwapInterval (1);
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop (iteration, 0, 1);
|
||||
#else
|
||||
do
|
||||
{
|
||||
iteration ();
|
||||
} // Check if the ESC key was pressed or the window was closed
|
||||
while (glfwGetKey (GLFW_KEY_ESC) != GLFW_PRESS &&
|
||||
glfwGetWindowParam (GLFW_OPENED));
|
||||
#endif
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate ();
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче