GL3D GWIN window + demo

This commit is contained in:
inmarket 2014-08-20 01:36:33 +10:00
parent 301f134b90
commit 3b21507274
72 changed files with 12309 additions and 3 deletions

205
3rdparty/tinygl-0.4-ugfx/BeOS/GLView.cpp vendored Normal file
View File

@ -0,0 +1,205 @@
#include "GLView.h"
#include <stdio.h>
#include <interface/Bitmap.h>
BLocker BGLView::locker;
BGLView::BGLView(BRect rect, char *name,
ulong resizingMode, ulong mode,
ulong options)
: BView(rect, name, resizingMode, mode|B_FRAME_EVENTS|B_WILL_DRAW)
{
#ifdef __INTEL__
color_space cs = B_RGB16_LITTLE;
#else
color_space cs = B_RGB16_BIG;
#endif
this->bitmaps[0] = new BBitmap(rect, cs, false, true);
this->bitmaps[1] = new BBitmap(rect, cs, false, true);
this->currBitmap = 0;
int w = this->bitmaps[0]->BytesPerRow() / 2;
int h = rect.Height() + 1;
void *buffers[2];
buffers[0] = this->bitmaps[0]->Bits();
buffers[1] = this->bitmaps[1]->Bits();
this->context = ostgl_create_context(w, h, 16, buffers, 2);
ostgl_make_current(this->context, 0);
}
BGLView::~BGLView()
{
ostgl_delete_context(this->context);
delete this->bitmaps[0];
delete this->bitmaps[1];
}
void
BGLView::LockGL()
{
BGLView::locker.Lock();
ostgl_make_current(this->context, this->currBitmap);
}
void
BGLView::UnlockGL()
{
BGLView::locker.Unlock();
}
void
BGLView::SwapBuffers()
{
if (Window()->Lock()) {
DrawBitmap(this->bitmaps[this->currBitmap]);
Window()->Unlock();
this->currBitmap ^= 1;
}
}
/*
BView *
BGLView::EmbeddedView()
{
return NULL;
}
status_t
BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
{
assert(0);
return 0;
}
status_t
BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
{
assert(0);
return 0;
}
*/
void
BGLView::ErrorCallback(GLenum /*errorCode*/)
{
}
void
BGLView::Draw(BRect rect)
{
//fprintf(stderr, "GLView::Draw()");
DrawBitmap(this->bitmaps[this->currBitmap^1], rect, rect);
}
void
BGLView::AttachedToWindow()
{
}
void
BGLView::AllAttached()
{
}
void
BGLView::DetachedFromWindow()
{
}
void
BGLView::AllDetached()
{
}
void
BGLView::FrameResized(float w, float h)
{
delete this->bitmaps[0];
delete this->bitmaps[1];
#ifdef __INTEL__
color_space cs = B_RGB16_LITTLE;
#else
color_space cs = B_RGB16_BIG;
#endif
this->bitmaps[0] = new BBitmap(BRect(0,0, w-1, h-1),
cs, false, true);
this->bitmaps[1] = new BBitmap(BRect(0,0, w-1, h-1),
cs, false, true);
int w2 = this->bitmaps[0]->BytesPerRow() / 2;
void *buffers[2];
buffers[0] = this->bitmaps[0]->Bits();
buffers[1] = this->bitmaps[1]->Bits();
ostgl_resize(this->context, w2, h, buffers);
}
/*
status_t
BGLView::Perform(perform_code d, void *arg)
{
}
*/
//
// the rest are pass-through functions
//
status_t
BGLView::Archive(BMessage *data, bool deep) const
{
return BView::Archive(data, deep);
}
void
BGLView::MessageReceived(BMessage *msg)
{
BView::MessageReceived(msg);
}
void
BGLView::SetResizingMode(uint32 mode)
{
BView::SetResizingMode(mode);
}
void
BGLView::Show()
{
BView::Show();
}
void
BGLView::Hide()
{
BView::Hide();
}
BHandler *
BGLView::ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property)
{
return BView::ResolveSpecifier(msg, index, specifier, form, property);
}
status_t
BGLView::GetSupportedSuites(BMessage *data)
{
return BView::GetSupportedSuites(data);
}
/*
void
BGLView::DirectConnected( direct_buffer_info *info )
{
BView::DirectConnected(info);
}
*/
/*
void
BGLView::EnableDirectMode( bool enabled )
{
BView::EnableDirectMode(enabled);
}
*/

72
3rdparty/tinygl-0.4-ugfx/BeOS/GLView.h vendored Normal file
View File

@ -0,0 +1,72 @@
#ifndef _glview_h_
#define _glview_h_
#define BGL_RGB 0
#define BGL_INDEX 1
#define BGL_SINGLE 0
#define BGL_DOUBLE 2
#define BGL_DIRECT 0
#define BGL_INDIRECT 4
#define BGL_ACCUM 8
#define BGL_ALPHA 16
#define BGL_DEPTH 32
#define BGL_OVERLAY 64
#define BGL_UNDERLAY 128
#define BGL_STENCIL 512
#include <interface/View.h>
#include <support/Locker.h>
#include <GL/gl.h>
#include <GL/oscontext.h>
#include <game/WindowScreen.h>
#include <game/DirectWindow.h>
class BGLView : public BView {
public:
BGLView(BRect rect, char *name,
ulong resizingMode, ulong mode,
ulong options);
virtual ~BGLView();
void LockGL();
void UnlockGL();
void SwapBuffers();
// BView *EmbeddedView();
// status_t CopyPixelsOut(BPoint source, BBitmap *dest);
// status_t CopyPixelsIn(BBitmap *source, BPoint dest);
virtual void ErrorCallback(GLenum errorCode);
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void AllAttached();
virtual void DetachedFromWindow();
virtual void AllDetached();
virtual void FrameResized(float width, float height);
// virtual status_t Perform(perform_code d, void *arg);
//
// Methods below are pass-throughs to BView for the moment.
//
virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual void MessageReceived(BMessage *msg);
virtual void SetResizingMode(uint32 mode);
virtual void Show();
virtual void Hide();
virtual BHandler *ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
//void DirectConnected( direct_buffer_info *info );
//void EnableDirectMode( bool enabled );
private:
ostgl_context *context;
BBitmap *bitmaps[2];
int currBitmap;
static BLocker locker;
};
#endif // _glview_h_

16
3rdparty/tinygl-0.4-ugfx/BeOS/Makefile vendored Normal file
View File

@ -0,0 +1,16 @@
OBJS=GLView.o
INCLUDES = -I../include
LIB = libGLView.a
all: $(LIB)
$(LIB): $(OBJS)
rm -f $(LIB)
ar rcs $(LIB) $(OBJS)
cp $(LIB) ../lib
clean:
rm -f *~ *.o *.a
GLView.o: GLView.cpp GLView.h
$(CC) $(CFLAGS) $(INCLUDES) -c GLView.cpp

38
3rdparty/tinygl-0.4-ugfx/Changelog vendored Normal file
View File

@ -0,0 +1,38 @@
version 0.4:
- added 24/32 bit rendering support (Olivier Landemarre - F. Bellard)
- fixed GL_TRIANGLE_STRIP (Olivier Landemarre)
- added gl_malloc, gl_free, gl_zalloc wrappers (Olivier Landemarre)
version 0.3:
- added NanoX API (nglx) (F. Bellard)
- added gears example and unified GUI in examples (F. Bellard)
- added TGL_FEATURE_RENDER_BITS so that it will be possible to render
natively in 15/16/24 or 32 bits. (F. Bellard)
- interpolated lines (Olivier Landemarre)
- fast no shading case (Olivier Landemarre)
- fast no projection case (Olivier Landemarre)
version 0.2: Fabrice Bellard
- added 24/32 bpp support. Added some features.h ifdefs.
- fixed some error reporting cases in the examples
- endianness is deduced from the glibc (BYTE_ORDER macro)
version 0.19: Peder Blekken
- new files BeOS/* src/msghandling.*, src/arrays.*, src/oscontext.c
include/GL/oscontext.h src/features.h
- added support for BeOS, see README.BEOS
- added support for drawing convex polygons with unlimited # of vertices
- added support for GL_LIGHT_MODEL_TWO_SIDE
- added generic rotation code for glopRotate
- added support for opengl 1.1 arrays
- added support for glPolygonOffset, not implemented.
- added glGetFloatv, limited support.
- added some pnames for glGetIntegerv
- added some empty functions in include/GL/gl.h to compile VRMLView
- added GL_VERSION_1_1 define in include/GL/gl.h
- fixed "bug" when context->gl_resize_viewport is not set.
- fixed bug in glBindTexture (didn't accept texture object 0)
version 0.1:
- Initial revision, Fabrice Bellard

10
3rdparty/tinygl-0.4-ugfx/INSTALL vendored Normal file
View File

@ -0,0 +1,10 @@
Installation:
- Edit config.mk and change what is needed. You can also look at
src/zfeatures.h to change very specific details (only useful to tune
TinyGL to your needs). You can link the examples with either OpenGL,
Mesa or TinyGL.
- Type 'make'. The library 'libTinyGL.a' is copied into './lib'. The
examples are build in './examples'. Only the directories './lib' and
'./include' are needed to use TinyGL from another program.

22
3rdparty/tinygl-0.4-ugfx/LICENCE vendored Normal file
View File

@ -0,0 +1,22 @@
Copyright notice:
(C) 1997-1998 Fabrice Bellard
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product and its documentation
*is* required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
If you redistribute modified sources, I would appreciate that you
include in the files history information documenting your changes.

206
3rdparty/tinygl-0.4-ugfx/LIMITATIONS vendored Normal file
View File

@ -0,0 +1,206 @@
Here are listed the functions that TinyGL understands with the known
limitations. The non mentionned functions are *not* implemented and
must not be used.
************ glEnable / glDisable
- The following flags are handled:
GL_CULL_FACE, GL_LIGHTING, GL_COLOR_MATERIAL, GL_TEXTURE_2D, GL_NORMALIZE,
GL_LIGHTx, GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_POINT,
GL_POLYGON_OFFSET_LINE
- GL_DEPTH_TEST is accepted, but it is only used for lines. For all
other primitives, Z buffer use is assumed. The DepthMode is
hardcoded as GL_LESS (OpenGL default).
************ glShadeModel
OK.
************ glCullFace
OK.
************ glPolygonMode
OK.
************ glBegin
No tests are performed to prevent some functions of being executed
between glBegin/glEnd.
************ glEnd
OK.
************ glVertex
Some prototypes are not implemented.
************ glColor
Some prototypes are not implemented.
************ glNormal
Some prototypes are not implemented.
************ glTexCoord
- Some prototypes are not implemented.
- The Matrix transformation is not applied yet.
************ glEdgeFlag
OK. The edge handling has to be tested, although it is not much useful
in TinyGL.
************ glMatrixMode / glLoadMatrixf / glLoadIdentity / glMultMatrixf /
glPushMatrix / glPopMatrix / glRotatef / glTranslatef / glScalef /
glFrustum
- The prototypes with doubles are not implemented.
************ glViewport
GlViewport calls a function pointers to tell glx (or another display
system) to resize the Z buffer and the ximage. Made optional in
version 0.2.
************ glGenLists / glIsList / glNewList / glEndList / glCallList
OK.
************ glClear / glClearColor / glClearDepth
The whole zbuffer and the colors are cleared in any case. The clear color
can be redefined, by *not* the initial z value.
************ glRenderMode
Only the modes GL_RENDER and GL_SELECT are implemented.
************ glSelectBuffer / glInitNames / glPushName / glPopName / glLoadName
OK.
************ glGenTextures / glDeleteTextures / glBindTexture
OK. These functions should be used to get the maximum performance with
TinyGL.
************ glTexImage2D
The function accepts only RGB UNSIGNED_BYTES bitmaps. They are
internally resized to 256x256 so you'd better use that size. No
mipmapping is implemented although it will come if asked. No borders
are implemented.
************ glTexEnvi
The only supported mode is GL_DECAL, although others are planned if
asked.
************ glTexParameteri
The other prototypes are not implemented. Only the follwing mode are
implemented:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
************ glPixelStorei
The pixels are alware byte aligned.
************ glMaterialfv / glMaterialf / glColorMaterial
OK.
************ glLightfv / glLightf / glLightModeli / glLightModelfv
OK. The OpenGL lightening is implemented but not optimized.
************ glFlush
Ignored.
************ glHint
Ignored.
************ glGetIntegerv
- only GL_VIEWPORT, GL_MAX_MODELVIEW_STACK_DEPTH,
GL_MAX_PROJECTION_STACK_DEPTH, GL_MAX_LIGHTS, GL_MAX_TEXTURE_SIZE,
GL_MAX_TEXTURE_STACK_DEPTH
************ glGetIntegerv
- only GL_TEXTURE_MATRIX, GL_PROJECTION_MATRIX, GL_MODELVIEW_MATRIX,
GL_LINE_WIDTH, GL_LINE_WIDTH_RANGE, GL_POINT_SIZE, GL_POINT_SIZE_RANGE
************ glPolygonOffset
- only API implemented.
************ glEnableClientState, glDisableClientState,
- No support for GL_INDEX_ARRAY_POINTER or GL_EDGE_FLAG_ARRAY_POINTER
************ glVertexPointer, glNormalPointer,
glColorPointer, glTexureCoordPointer
- OK
------------------------------------------------------------------------------
TinyGL GLX emulation:
************ glXQueryExtension
Returns always True
************ glXChooseVisual
Only 8 bit Pseudocolor or 16 bit Truecolor Visual are accepted. The
attribute list is ignored.
************ glXCreateContext
The sharing is not implemented although the code could handle it.
************ glXDestroyContext
OK.
************ glXMakeCurrent
Not all the syntax is supported yet, in particular with the 'NULL' or
'None' parameters.
************ glXSwapBuffers
OK.
************ glXWaitGL / glXWaitX
Ignored.
See README.BEOS for BeOS limitations.

15
3rdparty/tinygl-0.4-ugfx/Makefile vendored Normal file
View File

@ -0,0 +1,15 @@
include config.mk
all:
( for f in $(DIRS); do ( cd $$f ; make all ) || exit 1 ; done )
clean:
rm -f *~ lib/libTinyGL.a include/GL/*~ TAGS
( for f in $(DIRS); do ( cd $$f ; make clean ; ) done )
install:
( for f in $(DIRS); do ( cd $$f ; make install ; ) done )
tar:
( cd .. ; tar zcvf TinyGL-0.4.tar.gz TinyGL --exclude CVS --exclude TAGS )

150
3rdparty/tinygl-0.4-ugfx/README vendored Normal file
View File

@ -0,0 +1,150 @@
TinyGL 0.4 (c) 1997-2002 Fabrice Bellard.
General Description:
--------------------
TinyGL is intended to be a very small implementation of a subset of
OpenGL* for embedded systems or games. It is a software only
implementation. Only the main OpenGL calls are implemented. All the
calls I considered not important are simply *not implemented*.
The main strength of TinyGL is that it is fast and simple because it
has not to be exactly compatible with OpenGL. In particular, the
texture mapping and the geometrical transformations are very fast.
The main features of TinyGL are:
- Header compatible with OpenGL (the headers are adapted from the very good
Mesa by Brian Paul et al.)
- Zlib-like licence for easy integration in commercial designs (read
the LICENCE file).
- Subset of GLX for easy testing with X Window.
- GLX like API (NGLX) to use it with NanoX in MicroWindows/NanoX.
- Subset of BGLView under BeOS.
- OpenGL like lightening.
- Complete OpenGL selection mode handling for object picking.
- 16 bit Z buffer. 16/24/32 bit RGB rendering. High speed dithering to
paletted 8 bits if needed. High speed conversion to 24 bit packed
pixel or 32 bit RGBA if needed.
- Fast Gouraud shadding optimized for 16 bit RGB.
- Fast texture mapping capabilities, with perspective correction and
texture objects.
- 32 bit float only arithmetic.
- Very small: compiled code size of about 40 kB on x86. The file
src/zfeatures.h can be used to remove some unused features from
TinyGL.
- C sources for GCC on 32/64 bit architectures. It has been tested
succesfully on x86-Linux and sparc-Solaris.
Examples:
---------
I took three simple examples from the Mesa package to test the main
functions of TinyGL. You can link them to either TinyGL, Mesa or any
other OpenGL/GLX implementation. You can also compile them with
Microwindows.
- texobj illustrates the use of texture objects. Its shows the speed
of TinyGL in this case.
- glutmech comes from the GLUT packages. It is much bigger and slower
because it uses the lightening. I have just included some GLU
functions and suppressed the GLUT related code to make it work. It
shows the display list handling of TinyGL in particular. You can look
at the source code to learn the keys to move the robot. The key 't'
toggles between shaded rendering and wire frame.
- You can download and compile the VReng project to see that TinyGL
has been successfully used in a big project
(http://www-inf.enst.fr/vreng).
Architecture:
-------------
TinyGL is made up four main modules:
- Mathematical routines (zmath).
- OpenGL-like emulation (zgl).
- Z buffer and rasterisation (zbuffer).
- GLX interface (zglx).
To use TinyGL in an embedded system, you should look at the GLX layer
and modify it to suit your need. Adding a more user friendly
developper layer (as in Mesa) may be useful.
Notes - limitations:
--------------------
- See the file 'LIMITATIONS' to see the current functions supported by the API.
- The multithreading could be easily implemented since no global state
is maintainted. The library gets the current context with a function
which can be modified.
- The lightening is not very fast. I supposed that in most games the
lightening is computed by the 3D engine.
- Some changes are needed for 64 bit pointers for the handling of
arrays of float with the GLParam union.
- List sharing is partialy supported in the source, but not by the
current TinyGLX implementation (is it really useful ?).
- No user clipping planes are supported.
- No color index mode (no longer useful !)
- The mipmapping is not implemented.
- The perspecture correction in the mapping code does not use W but
1/Z. In any 'normal scene' it should work.
- The resizing of the viewport in TinyGLX ensures that the width and
the height are multiples of 4. This is not optimal because some pixels
of the window may not be refreshed.
Why ?
-----
TinyGL was developped as a student project for a Virtual Reality
network system called VReng (see the VReng home page at
http://www-inf.enst.fr/vreng).
At that time (January 1997), my initial project was to write my own 3D
rasterizer based on some old sources I wrote. But I realized that it
would be better to use OpenGL to work on any platform. My problem was
that I wanted to use texture mapping which was (and is still) quite
slower on many software OpenGL implementation. I could have modified
Mesa to suit my needs, but I really wanted to use my old sources for
that project.
I finally decided to use the same syntax as OpenGL but with my own
libraries, thinking that later it could ease the porting of VReng to
OpenGL.
Now VReng is at last compatible with OpenGL, and I managed to patch
TinyGL so that VReng can still work with it without any modifications.
Since TinyGL may be useful for some people, especially in the world of
embedded designs, I decided to release it 'as is', otherwise, it would
have been lost on my hard disk !
------------------------------------------------------------------------------
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
------------------------------------------------------------------------------
Fabrice Bellard.

20
3rdparty/tinygl-0.4-ugfx/README.BEOS vendored Normal file
View File

@ -0,0 +1,20 @@
BeOS support for TinyGL, 1998 Peder Blekken
I implemented (a limited version of) the BGLView class. There is
no DirectWindow support, and some other funtions are missing too,
but it should work ok for most uses. Feel free to use and modify
GLView.cpp and GLView.h in any way you desire.
You will need to take a look in Makefile to compile the library
under BeOS. For those of you not familiar with using makefiles: too bad :)
Also, you will probably need to remove /boot/develop/headers/be/opengl
from the BEINCLUDES environment variable. Unfortunately, this means
editing the /boot/beos/system/boot/SetupEnvironment. It might be possible
to just make sure the TinyGL path is before Be's OpenGL in the include-paths
though. But I prefer to remove /boot/develop/headers/be/opengl, since I
often use Mesa as well. It is a better to add the OpenGL include path in your
makefile; or BeIDE project if that is what you use.
Contact me for any reason: <pederb@sim.no>

4
3rdparty/tinygl-0.4-ugfx/README.uGFX vendored Normal file
View File

@ -0,0 +1,4 @@
uGFX support for TinyGL, 2014 Andrew Hannam
Some files have been modified to remove references to non-embedded
functions such as fprintf, exit and assert.

82
3rdparty/tinygl-0.4-ugfx/config.mk vendored Normal file
View File

@ -0,0 +1,82 @@
#####################################################################
# C compiler
# linux
CC= gcc
CFLAGS= -g -Wall -O2
LFLAGS=
# for BeOS PPC
#CC= mwcc
#CFLAGS= -I. -i-
#LFLAGS=
#####################################################################
# TinyGL configuration
#####################################################################
# Select window API for TinyGL:
# standard X11 GLX like API
TINYGL_USE_GLX=y
# BEOS API
#TINYGL_USE_BEOS=y
# Micro Windows NanoX API
#TINYGL_USE_NANOX=y
#####################################################################
# X11 configuration (for the examples only)
ifdef TINYGL_USE_GLX
# Linux
UI_LIBS= -L/usr/X11R6/lib -lX11 -lXext
UI_INCLUDES=
# Solaris
#UI_LIBS= -L/usr/X11/lib -lX11 -lXext -lsocket -lnsl
#UI_INCLUDES=
UI_OBJS=x11.o
endif
#####################################################################
# Micro windowX11 configuration (for the examples only)
ifdef TINYGL_USE_NANOX
UI_LIBS= -lnano-X -lmwengine -lmwdrivers -lmwfonts
UI_INCLUDES=
# X11 target for nanoX
UI_LIBS+= -L/usr/X11R6/lib -lX11 -lXext
UI_OBJS=nanox.o
endif
#####################################################################
# OpenGL configuration (for the examples only)
# use TinyGL
GL_LIBS= -L../lib -lTinyGL
GL_INCLUDES= -I../include
GL_DEPS= ../lib/libTinyGL.a
# use Mesa
#GL_LIBS= -lMesaGL
#GL_INCLUDES=
#GL_DEPS=
# use OpenGL
#GL_LIBS= -lGL
#GL_INCLUDES=
#GL_DEPS=
####################################################################
# Compile and link control
# UNIX systems
DIRS= src examples
# BeOS
# DIRS= src BeOS

View File

@ -0,0 +1,29 @@
include ../config.mk
PROGS = mech texobj gears spin
all: $(PROGS)
clean:
rm -f core *.o *~ $(PROGS)
mech: mech.o glu.o $(UI_OBJS) $(GL_DEPS)
$(CC) $(LFLAGS) $^ -o $@ $(GL_LIBS) $(UI_LIBS) -lm
texobj: texobj.o $(UI_OBJS) $(GL_DEPS)
$(CC) $(LFLAGS) $^ -o $@ $(GL_LIBS) $(UI_LIBS) -lm
gears: gears.o $(UI_OBJS) $(GL_DEPS)
$(CC) $(LFLAGS) $^ -o $@ $(GL_LIBS) $(UI_LIBS) -lm
spin: spin.o $(UI_OBJS) $(GL_DEPS)
$(CC) $(LFLAGS) $^ -o $@ $(GL_LIBS) $(UI_LIBS) -lm
.c.o:
$(CC) $(CFLAGS) $(GL_INCLUDES) $(UI_INCLUDES) -c $*.c
mech.o: glu.h
glu.o: glu.h
ui.o: ui.h

View File

@ -0,0 +1,300 @@
/* gears.c */
/*
* 3-D gear wheels. This program is in the public domain.
*
* Brian Paul
*/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include "ui.h"
#ifndef M_PI
# define M_PI 3.14159265
#endif
/*
* Draw a gear wheel. You'll probably want to call this function when
* building a display list since we do a lot of trig here.
*
* Input: inner_radius - radius of hole at center
* outer_radius - radius at center of teeth
* width - width of gear
* teeth - number of teeth
* tooth_depth - depth of tooth
*/
static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
GLint teeth, GLfloat tooth_depth )
{
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
GLfloat u, v, len;
r0 = inner_radius;
r1 = outer_radius - tooth_depth/2.0;
r2 = outer_radius + tooth_depth/2.0;
da = 2.0*M_PI / teeth / 4.0;
glShadeModel( GL_FLAT );
glNormal3f( 0.0, 0.0, 1.0 );
/* draw front face */
glBegin( GL_QUAD_STRIP );
for (i=0;i<=teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
}
glEnd();
/* draw front sides of teeth */
glBegin( GL_QUADS );
da = 2.0*M_PI / teeth / 4.0;
for (i=0;i<teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
}
glEnd();
glNormal3f( 0.0, 0.0, -1.0 );
/* draw back face */
glBegin( GL_QUAD_STRIP );
for (i=0;i<=teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
}
glEnd();
/* draw back sides of teeth */
glBegin( GL_QUADS );
da = 2.0*M_PI / teeth / 4.0;
for (i=0;i<teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
}
glEnd();
/* draw outward faces of teeth */
glBegin( GL_QUAD_STRIP );
for (i=0;i<teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
u = r2*cos(angle+da) - r1*cos(angle);
v = r2*sin(angle+da) - r1*sin(angle);
len = sqrt( u*u + v*v );
u /= len;
v /= len;
glNormal3f( v, -u, 0.0 );
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
glNormal3f( cos(angle), sin(angle), 0.0 );
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
glNormal3f( v, -u, 0.0 );
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
glNormal3f( cos(angle), sin(angle), 0.0 );
}
glVertex3f( r1*cos(0), r1*sin(0), width*0.5 );
glVertex3f( r1*cos(0), r1*sin(0), -width*0.5 );
glEnd();
glShadeModel( GL_SMOOTH );
/* draw inside radius cylinder */
glBegin( GL_QUAD_STRIP );
for (i=0;i<=teeth;i++) {
angle = i * 2.0*M_PI / teeth;
glNormal3f( -cos(angle), -sin(angle), 0.0 );
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
}
glEnd();
}
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
static GLuint limit;
static GLuint count = 1;
void draw( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef( view_rotx, 1.0, 0.0, 0.0 );
glRotatef( view_roty, 0.0, 1.0, 0.0 );
glRotatef( view_rotz, 0.0, 0.0, 1.0 );
glPushMatrix();
glTranslatef( -3.0, -2.0, 0.0 );
glRotatef( angle, 0.0, 0.0, 1.0 );
glCallList(gear1);
glPopMatrix();
glPushMatrix();
glTranslatef( 3.1, -2.0, 0.0 );
glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 );
glCallList(gear2);
glPopMatrix();
glPushMatrix();
glTranslatef( -3.1, 4.2, 0.0 );
glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 );
glCallList(gear3);
glPopMatrix();
glPopMatrix();
tkSwapBuffers();
count++;
if (count==limit) {
exit(0);
}
}
void idle( void )
{
angle += 2.0;
draw();
}
/* change view angle, exit upon ESC */
GLenum key(int k, GLenum mask)
{
switch (k) {
case KEY_UP:
view_rotx += 5.0;
return GL_TRUE;
case KEY_DOWN:
view_rotx -= 5.0;
return GL_TRUE;
case KEY_LEFT:
view_roty += 5.0;
return GL_TRUE;
case KEY_RIGHT:
view_roty -= 5.0;
return GL_TRUE;
case 'z':
view_rotz += 5.0;
return GL_TRUE;
case 'Z':
view_rotz -= 5.0;
return GL_TRUE;
case KEY_ESCAPE:
exit(0);
}
return GL_FALSE;
}
/* new window size or exposure */
void reshape( int width, int height )
{
GLfloat h = (GLfloat) height / (GLfloat) width;
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef( 0.0, 0.0, -40.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
void init( void )
{
static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
glLightfv( GL_LIGHT0, GL_POSITION, pos );
glEnable( GL_CULL_FACE );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_DEPTH_TEST );
/* make the gears */
gear1 = glGenLists(1);
glNewList(gear1, GL_COMPILE);
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red );
gear( 1.0, 4.0, 1.0, 20, 0.7 );
glEndList();
gear2 = glGenLists(1);
glNewList(gear2, GL_COMPILE);
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
gear( 0.5, 2.0, 2.0, 10, 0.7 );
glEndList();
gear3 = glGenLists(1);
glNewList(gear3, GL_COMPILE);
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue );
gear( 1.3, 2.0, 0.5, 10, 0.7 );
glEndList();
glEnable( GL_NORMALIZE );
}
int main(int argc, char **argv)
{
if (argc>1) {
/* do 'n' frames then exit */
limit = atoi( argv[1] ) + 1;
}
else {
limit = 0;
}
return ui_loop(argc, argv, "gears");
}

261
3rdparty/tinygl-0.4-ugfx/examples/glu.c vendored Normal file
View File

@ -0,0 +1,261 @@
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include "glu.h"
void drawTorus(float rc, int numc, float rt, int numt)
{
int i, j, k;
double s, t;
double x, y, z;
double pi, twopi;
pi = 3.14159265358979323846;
twopi = 2 * pi;
for (i = 0; i < numc; i++) {
glBegin(GL_QUAD_STRIP);
for (j = 0; j <= numt; j++) {
for (k = 1; k >= 0; k--) {
s = (i + k) % numc + 0.5;
t = j % numt;
x = cos(t*twopi/numt) * cos(s*twopi/numc);
y = sin(t*twopi/numt) * cos(s*twopi/numc);
z = sin(s*twopi/numc);
glNormal3f(x, y, z);
x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt);
y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt);
z = rc * sin(s*twopi/numc);
glVertex3f(x, y, z);
}
}
glEnd();
}
}
static void normal3f( GLfloat x, GLfloat y, GLfloat z )
{
GLdouble mag;
mag = sqrt( x*x + y*y + z*z );
if (mag>0.00001F) {
x /= mag;
y /= mag;
z /= mag;
}
glNormal3f( x, y, z );
}
void gluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar )
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
GLUquadricObj *gluNewQuadric(void)
{
return NULL;
}
void gluQuadricDrawStyle(GLUquadricObj *obj, int style)
{
}
void gluCylinder( GLUquadricObj *qobj,
GLdouble baseRadius, GLdouble topRadius, GLdouble height,
GLint slices, GLint stacks )
{
GLdouble da, r, dr, dz;
GLfloat z, nz, nsign;
GLint i, j;
GLfloat du = 1.0 / slices;
GLfloat dv = 1.0 / stacks;
GLfloat tcx = 0.0, tcy = 0.0;
nsign = 1.0;
da = 2.0*M_PI / slices;
dr = (topRadius-baseRadius) / stacks;
dz = height / stacks;
nz = (baseRadius-topRadius) / height; /* Z component of normal vectors */
for (i=0;i<slices;i++) {
GLfloat x1 = -sin(i*da);
GLfloat y1 = cos(i*da);
GLfloat x2 = -sin((i+1)*da);
GLfloat y2 = cos((i+1)*da);
z = 0.0;
r = baseRadius;
tcy = 0.0;
glBegin( GL_QUAD_STRIP );
for (j=0;j<=stacks;j++) {
if (nsign==1.0) {
normal3f( x1*nsign, y1*nsign, nz*nsign );
glTexCoord2f(tcx, tcy);
glVertex3f( x1*r, y1*r, z );
normal3f( x2*nsign, y2*nsign, nz*nsign );
glTexCoord2f(tcx+du, tcy);
glVertex3f( x2*r, y2*r, z );
}
else {
normal3f( x2*nsign, y2*nsign, nz*nsign );
glTexCoord2f(tcx, tcy);
glVertex3f( x2*r, y2*r, z );
normal3f( x1*nsign, y1*nsign, nz*nsign );
glTexCoord2f(tcx+du, tcy);
glVertex3f( x1*r, y1*r, z );
}
z += dz;
r += dr;
tcy += dv;
}
glEnd();
tcx += du;
}
}
/* Disk (adapted from Mesa) */
void gluDisk( GLUquadricObj *qobj,
GLdouble innerRadius, GLdouble outerRadius,
GLint slices, GLint loops )
{
GLdouble a, da;
GLfloat dr;
GLfloat r1, r2, dtc;
GLint s, l;
GLfloat sa,ca;
/* Normal vectors */
glNormal3f( 0.0, 0.0, +1.0 );
da = 2.0*M_PI / slices;
dr = (outerRadius-innerRadius) / (GLfloat) loops;
/* texture of a gluDisk is a cut out of the texture unit square */
/* x, y in [-outerRadius, +outerRadius]; s, t in [0, 1] (linear mapping) */
dtc = 2.0f * outerRadius;
r1 = innerRadius;
for (l=0;l<loops;l++) {
r2 = r1 + dr;
glBegin( GL_QUAD_STRIP );
for (s=0;s<=slices;s++) {
if (s==slices) a = 0.0;
else a = s * da;
sa = sin(a); ca = cos(a);
glTexCoord2f(0.5+sa*r2/dtc,0.5+ca*r2/dtc);
glVertex2f( r2*sa, r2*ca );
glTexCoord2f(0.5+sa*r1/dtc,0.5+ca*r1/dtc);
glVertex2f( r1*sa, r1*ca );
}
glEnd();
r1 = r2;
}
}
/*
* Sphère (adapted from Mesa)
*/
void gluSphere(GLUquadricObj *qobj,
float radius,int slices,int stacks)
{
float rho, drho, theta, dtheta;
float x, y, z;
float s, t, ds, dt;
int i, j, imin, imax;
int normals;
float nsign;
normals=1;
nsign=1;
drho = M_PI / (float) stacks;
dtheta = 2.0 * M_PI / (float) slices;
/* draw +Z end as a triangle fan */
glBegin( GL_TRIANGLE_FAN );
glNormal3f( 0.0, 0.0, 1.0 );
glTexCoord2f(0.5,0.0);
glVertex3f( 0.0, 0.0, nsign * radius );
for (j=0;j<=slices;j++) {
theta = (j==slices) ? 0.0 : j * dtheta;
x = -sin(theta) * sin(drho);
y = cos(theta) * sin(drho);
z = nsign * cos(drho);
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign );
glVertex3f( x*radius, y*radius, z*radius );
}
glEnd();
ds = 1.0 / slices;
dt = 1.0 / stacks;
t = 1.0; /* because loop now runs from 0 */
if (1) {
imin = 0;
imax = stacks;
}
else {
imin = 1;
imax = stacks-1;
}
/* draw intermediate stacks as quad strips */
for (i=imin;i<imax;i++) {
rho = i * drho;
glBegin( GL_QUAD_STRIP );
s = 0.0;
for (j=0;j<=slices;j++) {
theta = (j==slices) ? 0.0 : j * dtheta;
x = -sin(theta) * sin(rho);
y = cos(theta) * sin(rho);
z = nsign * cos(rho);
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign );
glTexCoord2f(s,1-t);
glVertex3f( x*radius, y*radius, z*radius );
x = -sin(theta) * sin(rho+drho);
y = cos(theta) * sin(rho+drho);
z = nsign * cos(rho+drho);
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign );
glTexCoord2f(s,1-(t-dt));
s += ds;
glVertex3f( x*radius, y*radius, z*radius );
}
glEnd();
t -= dt;
}
/* draw -Z end as a triangle fan */
glBegin( GL_TRIANGLE_FAN );
glNormal3f( 0.0, 0.0, -1.0 );
glTexCoord2f(0.5,1.0);
glVertex3f( 0.0, 0.0, -radius*nsign );
rho = M_PI - drho;
s = 1.0;
t = dt;
for (j=slices;j>=0;j--) {
theta = (j==slices) ? 0.0 : j * dtheta;
x = -sin(theta) * sin(rho);
y = cos(theta) * sin(rho);
z = nsign * cos(rho);
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign );
glTexCoord2f(s,1-t);
s -= ds;
glVertex3f( x*radius, y*radius, z*radius );
}
glEnd();
}

23
3rdparty/tinygl-0.4-ugfx/examples/glu.h vendored Normal file
View File

@ -0,0 +1,23 @@
void gluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar );
typedef struct {
int draw_style;
} GLUquadricObj;
#define GLU_LINE 0
GLUquadricObj *gluNewQuadric(void);
void gluQuadricDrawStyle(GLUquadricObj *obj, int style);
void gluSphere(GLUquadricObj *qobj,
float radius,int slices,int stacks);
void gluCylinder( GLUquadricObj *qobj,
GLdouble baseRadius, GLdouble topRadius, GLdouble height,
GLint slices, GLint stacks );
void gluDisk( GLUquadricObj *qobj,
GLdouble innerRadius, GLdouble outerRadius,
GLint slices, GLint loops );
void drawTorus(float rc, int numc, float rt, int numt);

1753
3rdparty/tinygl-0.4-ugfx/examples/mech.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,113 @@
/*
* Demonstration program for Nano-X graphics.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MWINCLUDECOLORS
#include <microwin/nano-X.h>
#include <GL/gl.h>
#include <GL/nglx.h>
#include "ui.h"
static GR_WINDOW_ID w1; /* id for large window */
static GR_GC_ID gc1; /* graphics context for text */
void errorcatcher(); /* routine to handle errors */
void tkSwapBuffers(void)
{
nglXSwapBuffers(w1);
}
int
ui_loop(int argc,char **argv, const char *name)
{
GR_EVENT event; /* current event */
GR_IMAGE_ID id = 0;
NGLXContext cx;
int width, height, k;
if (GrOpen() < 0) {
fprintf(stderr, "cannot open graphics\n");
exit(1);
}
width = 400;
height = 300;
GrSetErrorHandler(errorcatcher);
w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE);
GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN);
GrMapWindow(w1);
gc1 = GrNewGC();
GrSetGCForeground(gc1, WHITE);
cx = nglXCreateContext(NULL, 0);
nglXMakeCurrent(w1, cx);
init();
reshape(width, height);
while (1) {
GrCheckNextEvent(&event);
switch(event.type) {
case GR_EVENT_TYPE_CLOSE_REQ:
GrFreeImage(id);
GrClose();
exit(0);
case GR_EVENT_TYPE_EXPOSURE:
break;
case GR_EVENT_TYPE_KEY_DOWN:
{
GR_EVENT_KEYSTROKE *kp = &event.keystroke;