first commit

This commit is contained in:
Your Name
2022-10-20 20:29:11 +08:00
commit 4d531f8044
3238 changed files with 1387862 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
This is a collection of ancient testing code.
+318
View File
@@ -0,0 +1,318 @@
/* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
* vi:set ts=8:
*
* alcinfo.x
*
* alcinfo display info about a ALC extension and OpenAL renderer
*
* This file is in the Public Domain and comes with no warranty.
* Erik Hofman <erik@ehofman.com>
*
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef __APPLE__
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
#else
# include <AL/al.h>
# include <AL/alc.h>
# include <AL/alext.h>
#endif
#ifndef AL_VERSION_1_1
# ifdef __APPLE__
# include <OpenAL/altypes.h>
# include <OpenAL/alctypes.h>
#else
# include <AL/altypes.h>
# include <AL/alctypes.h>
# endif
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
using std::string;
#ifndef ALC_ALL_DEVICES_SPECIFIER
# define ALC_ALL_DEVICES_SPECIFIER 0x1013
#endif
#define MAX_DATA 16
static const int indentation = 4;
static const int maxmimumWidth = 79;
void printExtensions (const char *, char, const char *);
void displayDevices(const char *, const char *);
char *getDeviceName(int, char **);
void testForError(void *, const string&);
void testForALCError(ALCdevice *);
int main(int argc, char **argv)
{
ALCint data[MAX_DATA];
ALCdevice *device = NULL;
ALCcontext *context = NULL;
ALenum error;
char *s;
if (alcIsExtensionPresent(NULL, "ALC_enumeration_EXT") == AL_TRUE)
{
if (alcIsExtensionPresent(NULL, "ALC_enumerate_all_EXT") == AL_FALSE)
s = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
else
s = (char *)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
displayDevices("output", s);
s = (char *)alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
displayDevices("input", s);
}
s = getDeviceName(argc, argv);
device = alcOpenDevice(s);
testForError(device, "Audio device not available.");
context = alcCreateContext(device, NULL);
testForError(context, "Unable to create a valid context.");
alcMakeContextCurrent(context);
testForALCError(device);
s = (char *)alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER);
printf("default output device: %s\n", s);
testForALCError(device);
error = alcIsExtensionPresent(device, "ALC_EXT_capture");
if (error)
{
s = (char *)alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
printf("default input device: %s\n", s);
testForALCError(device);
}
printf("capture support: %s\n", (error) ? "yes" : "no");
alcGetIntegerv(device, ALC_FREQUENCY, 1, data);
printf("mixer frequency: %u hz\n", data[0]);
testForALCError(device);
alcGetIntegerv(device, ALC_REFRESH, 1, data+1);
printf("refresh rate : %u hz\n", data[0]/data[1]);
testForALCError(device);
data[0] = 0;
alcGetIntegerv(device, ALC_MONO_SOURCES, 1, data);
error = alcGetError(device);
if (error == AL_NONE) {
printf("supported sources; mono: %u, ", data[0]);
data[0] = 0;
alcGetIntegerv(device, ALC_STEREO_SOURCES, 1, data);
printf("stereo: %u\n", data[0]);
testForALCError(device);
}
printf("ALC version: ");
alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, data);
printf("%i.", *data);
alcGetIntegerv(device, ALC_MINOR_VERSION, 1, data);
printf("%i\n", *data);
testForALCError(device);
s = (char *)alcGetString(device, ALC_EXTENSIONS);
printExtensions ("ALC extensions", ' ', s);
testForALCError(device);
s = (char *)alGetString(AL_VENDOR);
error = alGetError();
if ((error = alGetError()) != AL_NO_ERROR)
printf("Error #%x: %s\n", error, alGetString(error));
else
printf("OpenAL vendor string: %s\n", s);
s = (char *)alGetString(AL_RENDERER);
if ((error = alGetError()) != AL_NO_ERROR)
printf("Error #%x: %s\n", error, alGetString(error));
else
printf("OpenAL renderer string: %s\n", s);
s = (char *)alGetString(AL_VERSION);
if ((error = alGetError()) != AL_NO_ERROR)
printf("Error #%x: %s\n", error, alGetString(error));
else if (!s)
printf("Querying AL_VERSION returned NULL pointer!\n");
else
printf("OpenAL version string: %s\n", s);
s = (char *)alGetString(AL_EXTENSIONS);
printExtensions ("OpenAL extensions", ' ', s);
testForALCError(device);
if (alcMakeContextCurrent(NULL) == 0)
printf("alcMakeContextCurrent failed.\n");
device = alcGetContextsDevice(context);
alcDestroyContext(context);
testForALCError(device);
if (alcCloseDevice(device) == 0)
printf("alcCloseDevice failed.\n");
return 0;
}
/* -------------------------------------------------------------------------- */
void
printChar (int c, int *width)
{
putchar (c);
*width = (c == '\n') ? 0 : (*width + 1);
}
void
indent (int *width)
{
int i;
for (i = 0; i < indentation; i++)
{
printChar (' ', width);
}
}
void
printExtensions (const char *header, char separator, const char *extensions)
{
int width = 0, start = 0, end = 0;
printf ("%s:\n", header);
if (extensions == NULL || extensions[0] == '\0')
{
return;
}
indent (&width);
while (1)
{
if (extensions[end] == separator || extensions[end] == '\0')
{
if (width + end - start + 2 > maxmimumWidth)
{
printChar ('\n', &width);
indent (&width);
}
while (start < end)
{
printChar (extensions[start], &width);
start++;
}
if (extensions[end] == '\0')
{
break;
}
start++;
end++;
if (extensions[end] == '\0')
{
break;
}
printChar (',', &width);
printChar (' ', &width);
}
end++;
}
printChar ('\n', &width);
}
char *
getCommandLineOption(int argc, char **argv, const string& option)
{
int slen = option.size();
char *rv = 0;
int i;
for (i=0; i<argc; i++)
{
if (strncmp(argv[i], option.c_str(), slen) == 0)
{
i++;
if (i<argc) rv = argv[i];
}
}
return rv;
}
char *
getDeviceName(int argc, char **argv)
{
static char devname[255];
int len = 255;
char *s;
s = getCommandLineOption(argc, argv, "-d");
if (s)
{
strncpy((char *)&devname, s, len);
len -= strlen(s);
s = getCommandLineOption(argc, argv, "-r");
if (s)
{
strncat((char *)&devname, " on ", len);
len -= 4;
strncat((char *)&devname, s, len);
}
s = (char *)&devname;
}
return s;
}
void
displayDevices(const char *type, const char *list)
{
ALCchar *ptr, *nptr;
ptr = (ALCchar *)list;
printf("list of all available %s devices:\n", type);
if (!list)
{
printf("none\n");
}
else
{
nptr = ptr;
while (*(nptr += strlen(ptr)+1) != 0)
{
printf(" %s\n", ptr);
ptr = nptr;
}
printf(" %s\n", ptr);
}
}
void
testForError(void *p, const string& s)
{
if (p == NULL)
{
printf("\nError: %s\n\n", s.c_str());
exit(-1);
}
}
void
testForALCError(ALCdevice *device)
{
ALenum error;
error = alcGetError(device);
if (error != ALC_NO_ERROR)
printf("\nALC Error %x occurred: %s\n", error, alcGetString(device, error));
}
+34
View File
@@ -0,0 +1,34 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <stdio.h>
#include <simgear/compiler.h>
#if defined( __APPLE__)
# include <OpenGL/OpenGL.h>
#else
# include <GL/gl.h>
#endif
int main() {
GLfloat a, t;
a = 1.0;
do {
printf("a = %.10f\n", a);
a = a / 2.0;
t = 1.0 + a;
} while ( t > 1.0 );
a = a + a;
printf("Estimated GLfloat epsilon = %.10f\n", a);
return(0);
}
+123
View File
@@ -0,0 +1,123 @@
/*
From: Steve Baker <sbaker@link.com>
Sender: root@fatcity.com
To: OPENGL-GAMEDEV-L <OPENGL-GAMEDEV-L@fatcity.com>
Subject: Re: Win32 OpenGL Resource Page
Date: Fri, 24 Apr 1998 07:33:51 -0800
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <simgear/compiler.h>
#if defined( __APPLE__)
# include <OpenGL/OpenGL.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# ifdef HAVE_GLUT_H
# include <GL/glut.h>
# endif
#endif
void getPrints ( GLenum token, char *string )
{
printf ( "%s = \"%s\"\n", string, glGetString ( token ) ) ;
}
void getPrint2f ( GLenum token, char *string )
{
GLfloat f[2] ;
glGetFloatv ( token, f ) ;
printf ( "%s = %g,%g\n", string, f[0],f[1] ) ;
}
void getPrintf ( GLenum token, char *string )
{
GLfloat f ;
glGetFloatv ( token, &f ) ;
printf ( "%s = %g\n", string, f ) ;
}
void getPrint2i ( GLenum token, char *string )
{
GLint i[2] ;
glGetIntegerv ( token, i ) ;
printf ( "%s = %d,%d\n", string, i[0],i[1] ) ;
}
void getPrinti ( GLenum token, char *string )
{
GLint i ;
glGetIntegerv ( token, &i ) ;
printf ( "%s = %d\n", string, i ) ;
}
int main ( int argc, char **argv )
{
#ifdef HAVE_GLUT_H
glutInit ( &argc, argv ) ;
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ;
glutCreateWindow ( "You should never see this window!" ) ;
getPrints ( GL_VENDOR , "GL_VENDOR" ) ;
getPrints ( GL_RENDERER , "GL_RENDERER" ) ;
getPrints ( GL_VERSION , "GL_VERSION" ) ;
getPrints ( GL_EXTENSIONS , "GL_EXTENSIONS" ) ;
getPrinti ( GL_RED_BITS , "GL_RED_BITS" ) ;
getPrinti ( GL_GREEN_BITS , "GL_GREEN_BITS" ) ;
getPrinti ( GL_BLUE_BITS , "GL_BLUE_BITS" ) ;
getPrinti ( GL_ALPHA_BITS , "GL_ALPHA_BITS" ) ;
getPrinti ( GL_DEPTH_BITS , "GL_DEPTH_BITS" ) ;
getPrinti ( GL_INDEX_BITS , "GL_INDEX_BITS" ) ;
getPrinti ( GL_STENCIL_BITS, "GL_STENCIL_BITS" ) ;
getPrinti ( GL_ACCUM_RED_BITS , "GL_ACCUM_RED_BITS" ) ;
getPrinti ( GL_ACCUM_GREEN_BITS, "GL_ACCUM_GREEN_BITS" ) ;
getPrinti ( GL_ACCUM_BLUE_BITS , "GL_ACCUM_BLUE_BITS" ) ;
getPrinti ( GL_ACCUM_ALPHA_BITS, "GL_ACCUM_ALPHA_BITS" ) ;
getPrinti ( GL_AUX_BUFFERS, "GL_AUX_BUFFERS" ) ;
getPrinti ( GL_MAX_ATTRIB_STACK_DEPTH , "GL_MAX_ATTRIB_STACK_DEPTH" ) ;
getPrinti ( GL_MAX_NAME_STACK_DEPTH , "GL_MAX_NAME_STACK_DEPTH" ) ;
getPrinti ( GL_MAX_TEXTURE_STACK_DEPTH , "GL_MAX_TEXTURE_STACK_DEPTH" ) ;
getPrinti ( GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" ) ;
getPrinti ( GL_MAX_MODELVIEW_STACK_DEPTH , "GL_MAX_MODELVIEW_STACK_DEPTH" ) ;
getPrinti ( GL_MAX_CLIP_PLANES , "GL_MAX_CLIP_PLANES" ) ;
getPrinti ( GL_MAX_EVAL_ORDER , "GL_MAX_EVAL_ORDER" ) ;
getPrinti ( GL_MAX_LIGHTS , "GL_MAX_LIGHTS" ) ;
getPrinti ( GL_MAX_LIST_NESTING , "GL_MAX_LIST_NESTING" ) ;
getPrinti ( GL_MAX_TEXTURE_SIZE , "GL_MAX_TEXTURE_SIZE" ) ;
getPrint2i( GL_MAX_VIEWPORT_DIMS , "GL_MAX_VIEWPORT_DIMS" ) ;
getPrintf ( GL_POINT_SIZE_GRANULARITY, "GL_POINT_SIZE_GRANULARITY" ) ;
getPrint2f( GL_POINT_SIZE_RANGE , "GL_POINT_SIZE_RANGE" ) ;
printf("Default values:\n\n");
getPrinti( GL_UNPACK_ALIGNMENT , "GL_UNPACK_ALIGNMENT" ) ;
getPrinti( GL_UNPACK_ROW_LENGTH , "GL_UNPACK_ROW_LENGTH" ) ;
getPrinti( GL_UNPACK_SKIP_PIXELS , "GL_UNPACK_SKIP_PIXELS" ) ;
getPrinti( GL_UNPACK_SKIP_ROWS , "GL_UNPACK_SKIP_ROWS" ) ;
getPrinti( GL_BLEND_SRC , "GL_BLEND_SRC" ) ;
getPrinti( GL_BLEND_DST , "GL_BLEND_DST" ) ;
#else
printf("GL Utility Toolkit (glut) was not found on this system.\n");
#endif
return 0 ;
}
+61
View File
@@ -0,0 +1,61 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <iostream>
#include <simgear/compiler.h>
#include <osg/GL>
#include <plib/pw.h>
#include <plib/pu.h>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include "layout.hxx"
// Takes a property file on the command line, lays it out, and writes
// the resulting tree back to stdout. Requires that the
// "Helvetica.txf" font file from the base package be in the current
// directory.
// g++ -Wall -g -o layout layout.cxx layout-props.cxx layout-test.cxx
// -I/fg/include -L/fg/lib -I.. -lsgprops -lsgdebug -lsgstructure
// -lsgmisc -lsgxml -lplibpw -lplibpu -lplibfnt -lplibul -lGL
// We can't load a plib fntTexFont without a GL context, so we use the
// PW library to initialize things. The callbacks are required, but
// just stubs.
void exitCB(){ pwCleanup(); exit(0); }
void resizeCB(int w, int h){ }
void mouseMotionCB(int x, int y){ puMouse(x, y); }
void mouseButtonCB(int button, int updn, int x, int y){ puMouse(button, updn, x, y); }
void keyboardCB(int key, int updn, int x, int y){ puKeyboard(key, updn, x, y); }
const char* FONT_FILE = "Helvetica.txf";
int main(int argc, char** argv)
{
FILE* tmp;
if(!(tmp = fopen(FONT_FILE, "r"))) {
fprintf(stderr, "Could not open %s for reading.\n", FONT_FILE);
exit(1);
}
fclose(tmp);
pwInit(0, 0, 600, 400, 0, const_cast<char*>("Layout Test"), true, 0);
pwSetCallbacks(keyboardCB, mouseButtonCB, mouseMotionCB,
resizeCB, exitCB);
fntTexFont helv;
helv.load(FONT_FILE);
puFont puhelv(&helv);
LayoutWidget::setDefaultFont(&puhelv, 15);
SGPropertyNode props;
readProperties(argv[1], &props);
LayoutWidget w(&props);
int pw=0, ph=0;
w.calcPrefSize(&pw, &ph);
w.layout(0, 0, pw, ph);
writeProperties(std::cout, &props, true);
}
+274
View File
@@ -0,0 +1,274 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <simgear/compiler.h>
#if defined( __APPLE__)
# include <OpenGL/OpenGL.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# ifdef HAVE_GLUT_H
# include <GL/glut.h>
# endif
#endif
#define TEXRES_X 256
#define TEXRES_Y 256
#ifdef HAVE_GLUT_H
unsigned char env_map[TEXRES_X][TEXRES_Y][4];
GLuint texName;
int window_x = 640, window_y = 480;
float alpha = 0.0, beta = 0.0;
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
void setColor(float x, float y, float z, float angular_size, float r, float g, float b, float a)
{
//normalize
float inv_length = 1.0 / sqrt(x*x + y*y + z*z);
x *= inv_length; y *= inv_length; z *= inv_length;
printf("x = %f, y = %f, z = %f\n", x, y, z);
float cos_angular_size = cos(angular_size*3.1415/180.0);
printf("cos_angular_size = %f\n", cos_angular_size);
for(float tz_sign = -1.0; tz_sign < 3.0; tz_sign += 2.0)
{
for(float tx = -1.0; tx <= 1.0; tx += 0.01)
{
for(float ty = -1.0; ty <= 1.0; ty += 0.01)
{
if ((1.0 - tx*tx - ty*ty)<0.0)
continue;
float tz = tz_sign * sqrt(1.0 - tx*tx - ty*ty);
float cos_phi = x*tx + y*ty + z*tz;
if (cos_angular_size < cos_phi)
{
float rx = tx; //mirroring on the z=0 plane
float ry = ty;
float rz = -tz;
float inv_m = 1.0 / (2.0 * sqrt(rx*rx + ry*ry + (rz + 1)*(rz + 1)));
int s = (int)(TEXRES_X * (rx * inv_m + 0.5));
int t = (int)(TEXRES_Y * (ry * inv_m + 0.5));
//seg_fault protection:
if (s<0) s=0;
if (s>=TEXRES_X) s=TEXRES_X-1;
if (t<0) t=0;
if (t>=TEXRES_Y) t=TEXRES_Y-1;
env_map[s][t][0] = (unsigned char)(r * 255);
env_map[s][t][1] = (unsigned char)(g * 255);
env_map[s][t][2] = (unsigned char)(b * 255);
env_map[s][t][3] = (unsigned char)(a * 255);
}
}
}
}
}
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
for(int x=0; x<TEXRES_X; x++)
{
for(int y=0; y<TEXRES_Y; y++)
{
env_map[x][y][0] = x; //a few colors
env_map[x][y][1] = y;
env_map[x][y][2] = 128;
env_map[x][y][3] = 128;
}
}
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
// x y z ang r g b a
setColor(0.0, 0.0, -1.0 , 23.0, 1.0, 1.0, 1.0, 1.0);
setColor(0.7071067, 0.0, -0.7071067, 23.0, 1.0, 0.0, 0.0, 1.0);
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
}
void reshape(int w, int h)
{
window_x = w; window_y = h;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective((GLdouble) 60.0, ((GLdouble)w)/((GLdouble)h), (GLdouble) 10.0, (GLdouble) 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -20.0);
}
void display()
{
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
//show light
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective((GLdouble) 60.0, (float)window_x/window_y, (GLdouble) 1.0, (GLdouble) 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(alpha, 1.0, 0.0, 0.0);
glRotatef(beta, 0.0, 1.0, 0.0);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd();
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texName);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(-1.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 0.0);
glVertex3f(1.0, -1.0, 0.0);
glEnd();
/*
glPointSize(48.0);
glBegin(GL_POINTS);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
*/
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
/*****************************************************************/
/*****************************************************************/
/*****************************************************************/
//show how the map looks like
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(0.0 -10.0, 1.0 +10.0, -(float)window_x/window_y -10.0,0.0 +10.0);
//glOrtho(0.0, 5.0, -5.0, 0.0, -10.0, 10.0);
glOrtho(0.0, 5.0*((float)window_x/window_y), -5.0, 0.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texName);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(0.0, -1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 0.0, 0.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
glutPostRedisplay () ;
glutSwapBuffers () ;
}
void keyboard (unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
case '8':
alpha += 1.0;
if (alpha >= 360.0) alpha -= 360.0;
break;
case '2':
alpha -= 1.0;
if (alpha < 0.0) alpha += 360.0;
break;
case '4':
beta -= 1.0;
if (beta <= -90.0) beta = -90.0;
break;
case '6':
beta += 1.0;
if (beta >= 90.0) beta = 90.0;
break;
case '5':
alpha = 0.0; beta = 0.0;
break;
}
}
#endif /* HAVE_GLUT_H */
int main(int argc, char** argv)
{
#ifdef HAVE_GLUT_H
glutInitWindowSize(window_x, window_y);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
#else
printf("GL Utility Toolkit (glut) was not found on this system.\n");
#endif
return 0;
}
+18
View File
@@ -0,0 +1,18 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if defined( unix ) || defined( __CYGWIN__ )
# include <unistd.h> // for gethostname()
#endif
#include <stdio.h>
int main() {
#if defined( unix ) || defined( __CYGWIN__ )
char name[256];
gethostname( name, 256 );
printf("hostname = %s\n", name);
#endif
return 0;
}
+116
View File
@@ -0,0 +1,116 @@
// do some non-destructive read tests relating text files
#include <stdio.h>
#include <string.h>
static void readchars( FILE *fd ) {
int c;
while ( (c = fgetc(fd)) != EOF ) {
printf("c = %d", c);
if ( c == 10 ) {
printf(" LF \\n");
}
if ( c == 13 ) {
printf(" CR \\r");
}
printf("\n");
}
}
static void readlines( FILE *fd ) {
char line[256];
while ( fgets(line, 255, fd) != NULL ) {
int len = strlen(line);
printf("line = %s", line);
if ( len >= 2 ) {
printf(" char[n - 1] = %d char[n] = %d\n",
line[len-2], line[len-1]);
} else if ( len >= 1 ) {
printf(" char[n] = %d\n",line[len-1]);
} else {
printf("empty string\n");
}
}
}
int main( int argc, char **argv ) {
// check usage
if ( argc != 2 ) {
printf("usage: %s file\n", argv[0]);
return -1;
}
char file[256];
strcpy( file, argv[1] );
FILE *fd;
// open a file in (default) text mode
printf("TEXT MODE (DEFAULT) by character\n\n");
fd = fopen( file, "r" );
if ( fd != NULL ) {
readchars( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
// open a file in (explicit) text mode
printf("TEXT MODE (EXPLICIT) by character\n\n");
fd = fopen( file, "rt" );
if ( fd != NULL ) {
readchars( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
// open a file in (explicit) binary mode
printf("BINARY MODE (EXPLICIT) by character\n\n");
fd = fopen( file, "rb" );
if ( fd != NULL ) {
readchars( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
// open a file in (default) text mode
printf("TEXT MODE (DEFAULT) by line\n\n");
fd = fopen( file, "r" );
if ( fd != NULL ) {
readlines( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
// open a file in (explicit) text mode
printf("TEXT MODE (EXPLICIT) by line\n\n");
fd = fopen( file, "rt" );
if ( fd != NULL ) {
readlines( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
// open a file in (explicit) binary mode
printf("BINARY MODE (EXPLICIT) by line\n\n");
fd = fopen( file, "rb" );
if ( fd != NULL ) {
readlines( fd );
fclose(fd);
} else {
printf("Cannot open %s\n", file);
}
printf("\n");
return 0;
}