ref: 187cf4397cc5b44b2c1794231efda7117c4fc651
parent: d58cccbb61ee55a816ae8a65f61915263a691777
author: David <gek@katherine>
date: Mon Feb 15 16:55:01 EST 2021
Clang format to the rescue
--- /dev/null
+++ b/SDL_Examples/.clang-format
@@ -1,0 +1,118 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 160
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Always
+...
+
--- /dev/null
+++ b/SDL_Examples/code_format.sh
@@ -1,0 +1,1 @@
+clang-format-8 -i *.c --style=file
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -8,60 +8,32 @@
//#define PLAY_MUSIC
#include <math.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../include/GL/gl.h"
#define CHAD_API_IMPL
+#include "../include/zbuffer.h"
#include "include/api_audio.h"
#include <SDL/SDL.h>
-#include "../include/zbuffer.h"
#ifndef M_PI
-# define M_PI 3.14159265
+#define M_PI 3.14159265
#endif
+GLubyte stipplepattern[128] = {0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-GLubyte stipplepattern[128] = {
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
-
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55
-};
-
/*
* 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.
@@ -72,404 +44,394 @@
* 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;
+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;
+ 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;
+ da = 2.0 * M_PI / teeth / 4.0;
- glShadeModel( GL_SMOOTH );
+ glShadeModel(GL_SMOOTH);
- glNormal3f( 0.0, 0.0, 1.0 );
+ 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 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;
+ /* 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();
+ 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 );
+ 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 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;
+ /* 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();
+ 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;
+ /* 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(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 );
+ glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
+ glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
- glEnd();
+ glEnd();
+ // glShadeModel( GL_SMOOTH );
- //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();
-
+ /* 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;
+static GLfloat view_rotx = 20.0, view_roty = 30.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
void draw() {
- angle += 2.0;
- 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 );
+ angle += 2.0;
+ 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.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, -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();
+ glPushMatrix();
+ glTranslatef(-3.1, 4.2, 0.0);
+ glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
+ glCallList(gear3);
+ glPopMatrix();
- glPopMatrix();
+ glPopMatrix();
}
-
void initScene() {
- //static GLfloat pos[4] = {0.408248290463863, 0.408248290463863, 0.816496580927726, 0.0 }; //Light at infinity.
- static GLfloat pos[4] = {5, 5, 10, 0.0 }; //Light at infinity.
-
- static GLfloat red[4] = {1.0, 0.0, 0.0, 0.0 };
- static GLfloat green[4] = {0.0, 1.0, 0.0, 0.0 };
- static GLfloat blue[4] = {0.0, 0.0, 1.0, 0.0 };
- static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0 };
+ // static GLfloat pos[4] = {0.408248290463863, 0.408248290463863, 0.816496580927726, 0.0 }; //Light at infinity.
+ static GLfloat pos[4] = {5, 5, 10, 0.0}; // Light at infinity.
- glLightfv( GL_LIGHT0, GL_POSITION, pos );
- glLightfv( GL_LIGHT0, GL_DIFFUSE, white);
- //glLightfv( GL_LIGHT0, GL_AMBIENT, white);
- //glLightfv( GL_LIGHT0, GL_SPECULAR, white);
- glEnable( GL_CULL_FACE );
- glEnable( GL_LIGHTING );
- //glDisable( GL_LIGHTING );
- glEnable( GL_LIGHT0 );
- glEnable( GL_DEPTH_TEST );
- //glShadeModel( GL_SMOOTH );
+ static GLfloat red[4] = {1.0, 0.0, 0.0, 0.0};
+ static GLfloat green[4] = {0.0, 1.0, 0.0, 0.0};
+ static GLfloat blue[4] = {0.0, 0.0, 1.0, 0.0};
+ static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple(stipplepattern);
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
+ // glLightfv( GL_LIGHT0, GL_AMBIENT, white);
+ // glLightfv( GL_LIGHT0, GL_SPECULAR, white);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ // glDisable( GL_LIGHTING );
+ glEnable(GL_LIGHT0);
+ glEnable(GL_DEPTH_TEST);
+ // glShadeModel( GL_SMOOTH );
-
+ glEnable(GL_POLYGON_STIPPLE);
+ glPolygonStipple(stipplepattern);
+
glTextSize(GL_TEXT_SIZE24x24);
- /* make the gears */
- gear1 = glGenLists(1);
- glNewList(gear1, GL_COMPILE);
- glMaterialfv( GL_FRONT, GL_DIFFUSE, blue );
- //glColor3fv(red);
- gear( 1.0, 4.0, 1.0, 20, 0.7 ); //The largest gear.
- glEndList();
+ /* make the gears */
+ gear1 = glGenLists(1);
+ glNewList(gear1, GL_COMPILE);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, blue);
+ // glColor3fv(red);
+ gear(1.0, 4.0, 1.0, 20, 0.7); // The largest gear.
+ glEndList();
- gear2 = glGenLists(1);
- glNewList(gear2, GL_COMPILE);
- glMaterialfv( GL_FRONT, GL_DIFFUSE, red );
- //glColor3fv(green);
- gear( 0.5, 2.0, 2.0, 10, 0.7 ); //The small gear with the smaller hole, to the right.
- glEndList();
+ gear2 = glGenLists(1);
+ glNewList(gear2, GL_COMPILE);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, red);
+ // glColor3fv(green);
+ gear(0.5, 2.0, 2.0, 10, 0.7); // The small gear with the smaller hole, to the right.
+ glEndList();
- gear3 = glGenLists(1);
- glNewList(gear3, GL_COMPILE);
- glMaterialfv( GL_FRONT, GL_DIFFUSE, green );
- //glColor3fv(blue);
- gear( 1.3, 2.0, 0.5, 10, 0.7 ); //The small gear above with the large hole.
- glEndList();
- //glEnable( GL_NORMALIZE );
+ gear3 = glGenLists(1);
+ glNewList(gear3, GL_COMPILE);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, green);
+ // glColor3fv(blue);
+ gear(1.3, 2.0, 0.5, 10, 0.7); // The small gear above with the large hole.
+ glEndList();
+ // glEnable( GL_NORMALIZE );
}
-int main(int argc, char **argv) {
- // initialize SDL video:
- int winSizeX=640;
- int winSizeY=480;
- unsigned int fps =0;
+int main(int argc, char** argv) {
+ // initialize SDL video:
+ int winSizeX = 640;
+ int winSizeY = 480;
+ unsigned int fps = 0;
char needsRGBAFix = 0;
- if(argc > 2){
- char* larg = argv[1];
- for(int i = 0; i < argc; i++){
- if(!strcmp(larg,"-w"))
+ if (argc > 2) {
+ char* larg = argv[1];
+ for (int i = 0; i < argc; i++) {
+ if (!strcmp(larg, "-w"))
winSizeX = atoi(argv[i]);
- if(!strcmp(larg,"-h"))
+ if (!strcmp(larg, "-h"))
winSizeY = atoi(argv[i]);
- if(!strcmp(larg,"-fps"))
- fps = strtoull(argv[i],0,10);
+ if (!strcmp(larg, "-fps"))
+ fps = strtoull(argv[i], 0, 10);
larg = argv[i];
- }
- }
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)<0) {
- fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
- return 1;
- }
+ }
+ }
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
+ fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
+ return 1;
+ }
#ifdef PLAY_MUSIC
- ainit(0);
+ ainit(0);
#endif
- SDL_Surface* screen = NULL;
- if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
- fprintf(stderr,"ERROR: Video mode set failed.\n");
- return 1;
- }
- printf("\nRMASK IS %u",screen->format->Rmask);
- printf("\nGMASK IS %u",screen->format->Gmask);
- printf("\nBMASK IS %u",screen->format->Bmask);
- printf("\nAMASK IS %u",screen->format->Amask);
+ SDL_Surface* screen = NULL;
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ printf("\nRMASK IS %u", screen->format->Rmask);
+ printf("\nGMASK IS %u", screen->format->Gmask);
+ printf("\nBMASK IS %u", screen->format->Bmask);
+ printf("\nAMASK IS %u", screen->format->Amask);
#if TGL_FEATURE_RENDER_BITS == 32
- if(
- screen->format->Rmask != 0x00FF0000 ||
- screen->format->Gmask != 0x0000FF00 ||
- screen->format->Bmask != 0x000000FF
- ){
+ if (screen->format->Rmask != 0x00FF0000 || screen->format->Gmask != 0x0000FF00 || screen->format->Bmask != 0x000000FF) {
needsRGBAFix = 1;
printf("\nYour screen is using an RGBA output different than this library expects.");
printf("\nYou should consider using the 16 bit version for optimal performance");
}
#endif
- printf("\nRSHIFT IS %u",screen->format->Rshift);
- printf("\nGSHIFT IS %u",screen->format->Gshift);
- printf("\nBSHIFT IS %u",screen->format->Bshift);
- printf("\nASHIFT IS %u\n",screen->format->Ashift);
- fflush(stdout);
- track* myTrack = NULL;
+ printf("\nRSHIFT IS %u", screen->format->Rshift);
+ printf("\nGSHIFT IS %u", screen->format->Gshift);
+ printf("\nBSHIFT IS %u", screen->format->Bshift);
+ printf("\nASHIFT IS %u\n", screen->format->Ashift);
+ fflush(stdout);
+ track* myTrack = NULL;
#ifdef PLAY_MUSIC
- myTrack = lmus("WWGW.mp3");
- mplay(myTrack, -1, 1000);
+ myTrack = lmus("WWGW.mp3");
+ mplay(myTrack, -1, 1000);
#endif
- SDL_ShowCursor(SDL_DISABLE);
- SDL_WM_SetCaption(argv[0],0);
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_WM_SetCaption(argv[0], 0);
- // initialize TinyGL:
- //unsigned int pitch;
- int mode;
- switch( screen->format->BitsPerPixel ) {
- case 8:
- fprintf(stderr,"ERROR: Palettes are currently not supported.\n");
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- return 1;
- case 16:
- //pitch = screen->pitch;
- //fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_5R6G5B;
- //return 1;
- break;
- case 24:
- //pitch = ( screen->pitch * 2 ) / 3;
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_RGB24;
- return 1;
- break;
- case 32:
- //pitch = screen->pitch / 2;
- mode = ZB_MODE_RGBA;
- break;
- default:
- return 1;
- break;
- }
- ZBuffer *frameBuffer = ZB_open( winSizeX, winSizeY, mode, 0, 0, 0, 0);
- glInit( frameBuffer );
+ // initialize TinyGL:
+ // unsigned int pitch;
+ int mode;
+ switch (screen->format->BitsPerPixel) {
+ case 8:
+ fprintf(stderr, "ERROR: Palettes are currently not supported.\n");
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ return 1;
+ case 16:
+ // pitch = screen->pitch;
+ // fprintf(stderr,"\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_5R6G5B;
+ // return 1;
+ break;
+ case 24:
+ // pitch = ( screen->pitch * 2 ) / 3;
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_RGB24;
+ return 1;
+ break;
+ case 32:
+ // pitch = screen->pitch / 2;
+ mode = ZB_MODE_RGBA;
+ break;
+ default:
+ return 1;
+ break;
+ }
+ ZBuffer* frameBuffer = ZB_open(winSizeX, winSizeY, mode, 0, 0, 0, 0);
+ glInit(frameBuffer);
- // initialize GL:
- glClearColor (0.0, 0.0, 0.0, 0.0);
- glViewport (0, 0, winSizeX, winSizeY);
- glEnable(GL_DEPTH_TEST);
- GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef( 0.0, 0.0, -45.0 );
+ // initialize GL:
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glViewport(0, 0, winSizeX, winSizeY);
+ glEnable(GL_DEPTH_TEST);
+ GLfloat h = (GLfloat)winSizeY / (GLfloat)winSizeX;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -45.0);
- initScene();
+ initScene();
- // variables for timing:
- unsigned int frames=0;
- unsigned int tNow=SDL_GetTicks();
- unsigned int tLastFps=tNow;
+ // variables for timing:
+ unsigned int frames = 0;
+ unsigned int tNow = SDL_GetTicks();
+ unsigned int tLastFps = tNow;
- // main loop:
- int isRunning=1;
- while(isRunning) {
- ++frames;
- tNow=SDL_GetTicks();
- // do event handling:
- SDL_Event evt;
- while( SDL_PollEvent( &evt ) ) switch(evt.type) {
- case SDL_KEYDOWN:
- switch(evt.key.keysym.sym) {
- case SDLK_UP:
- view_rotx += 5.0;
- break;
- case SDLK_DOWN:
- view_rotx -= 5.0;
- break;
- case SDLK_LEFT:
- view_roty += 5.0;
- break;
- case SDLK_RIGHT:
- view_roty -= 5.0;
- break;
- case SDLK_ESCAPE :
- case SDLK_q :
- isRunning=0;
- default:
- break;
- }
- break;
- case SDL_QUIT:
- isRunning=0;
- break;
- }
+ // main loop:
+ int isRunning = 1;
+ while (isRunning) {
+ ++frames;
+ tNow = SDL_GetTicks();
+ // do event handling:
+ SDL_Event evt;
+ while (SDL_PollEvent(&evt))
+ switch (evt.type) {
+ case SDL_KEYDOWN:
+ switch (evt.key.keysym.sym) {
+ case SDLK_UP:
+ view_rotx += 5.0;
+ break;
+ case SDLK_DOWN:
+ view_rotx -= 5.0;
+ break;
+ case SDLK_LEFT:
+ view_roty += 5.0;
+ break;
+ case SDLK_RIGHT:
+ view_roty -= 5.0;
+ break;
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ isRunning = 0;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ isRunning = 0;
+ break;
+ }
- // draw scene:
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- draw();
-
- glDrawText((unsigned char*)"RED text", 0, 0, 0x000000FF);
+ // draw scene:
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ draw();
- glDrawText((unsigned char*)"GREEN text", 0, 24,0x0000FF00);
+ glDrawText((unsigned char*)"RED text", 0, 0, 0x000000FF);
- glDrawText((unsigned char*)"BLUE text", 0, 48, 0x00FF0000);
- // swap buffers:
- if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
- fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
- return 1;
- }
- //Quickly convert all pixels to the correct format
+ glDrawText((unsigned char*)"GREEN text", 0, 24, 0x0000FF00);
+
+ glDrawText((unsigned char*)"BLUE text", 0, 48, 0x00FF0000);
+ // swap buffers:
+ if (SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen) < 0)) {
+ fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
+ return 1;
+ }
+ // Quickly convert all pixels to the correct format
#if TGL_FEATURE_RENDER_BITS == 32
-//for testing!
- if(needsRGBAFix)
- for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
+ // for testing!
+ if (needsRGBAFix)
+ for (int i = 0; i < frameBuffer->xsize * frameBuffer->ysize; i++) {
#define DATONE (frameBuffer->pbuf[i])
- DATONE = ((DATONE & 0x00FF0000) ) << screen->format->Rshift |
- ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
- ((DATONE & 0x000000FF) >>16) << screen->format->Bshift;
- }
+ DATONE = ((DATONE & 0x00FF0000)) << screen->format->Rshift | ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
+ ((DATONE & 0x000000FF) >> 16) << screen->format->Bshift;
+ }
#endif
- ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if ( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen);
- SDL_Flip(screen);
- if(fps>0)
- if((1000/fps)>(SDL_GetTicks()-tNow))
- {
- SDL_Delay((1000/fps)-(SDL_GetTicks()-tNow)); //Yay stable framerate!
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+ if (fps > 0)
+ if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
+ SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
}
- // check for error conditions:
- char* sdl_error = SDL_GetError( );
- if( sdl_error[0] != '\0' ) {
- fprintf(stderr,"SDL ERROR: \"%s\"\n",sdl_error);
- SDL_ClearError();
- }
- // update fps:
- if(tNow>=tLastFps+5000) {
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- tLastFps=tNow;
- frames=0;
- }
- }
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- // cleanup:
- glDeleteList(gear1);
- glDeleteList(gear2);
- glDeleteList(gear3);
- ZB_close(frameBuffer);
- if(SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ // check for error conditions:
+ char* sdl_error = SDL_GetError();
+ if (sdl_error[0] != '\0') {
+ fprintf(stderr, "SDL ERROR: \"%s\"\n", sdl_error);
+ SDL_ClearError();
+ }
+ // update fps:
+ if (tNow >= tLastFps + 5000) {
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f,
+ (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ tLastFps = tNow;
+ frames = 0;
+ }
+ }
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f, (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ // cleanup:
+ glDeleteList(gear1);
+ glDeleteList(gear2);
+ glDeleteList(gear3);
+ ZB_close(frameBuffer);
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- mhalt();
- Mix_FreeMusic(myTrack);
- acleanup();
+ mhalt();
+ Mix_FreeMusic(myTrack);
+ acleanup();
#endif
- SDL_Quit();
- return 0;
+ SDL_Quit();
+ return 0;
}
--- a/SDL_Examples/helloworld.c
+++ b/SDL_Examples/helloworld.c
@@ -7,93 +7,92 @@
*/
//#define PLAY_MUSIC
+#include "../include/GL/gl.h"
#include <math.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include "../include/GL/gl.h"
//#include <GL/glu.h>
#define CHAD_API_IMPL
#include "include/api_audio.h"
#define STB_IMAGE_IMPLEMENTATION
+#include "../include/zbuffer.h"
#include "include/stb_image.h"
#include <SDL/SDL.h>
-#include "../include/zbuffer.h"
#ifndef M_PI
-# define M_PI 3.14159265
+#define M_PI 3.14159265
#endif
GLuint tex = 0;
double time_passed = 0.0;
-int winSizeX=640;
-int winSizeY=480;
+int winSizeX = 640;
+int winSizeY = 480;
void draw() {
- //glEnable(GL_TEXTURE_2D);
- //glBindTexture(GL_TEXTURE_2D,tex);
- //time_passed += 0.0166666;
+ // glEnable(GL_TEXTURE_2D);
+ // glBindTexture(GL_TEXTURE_2D,tex);
+ // time_passed += 0.0166666;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
- glRotatef(time_passed,0, 0, 1);
- glBegin( GL_TRIANGLES );
- glColor3f(0.2, 0.2, 1.0); //BLUE!
- //glColor3f(1.0, 0.2, 0.2); //RED!
- glVertex3f(-0.8,-0.8,0.2);
+ glRotatef(time_passed, 0, 0, 1);
+ glBegin(GL_TRIANGLES);
+ glColor3f(0.2, 0.2, 1.0); // BLUE!
+ // glColor3f(1.0, 0.2, 0.2); //RED!
+ glVertex3f(-0.8, -0.8, 0.2);
- glColor3f(0.2, 1.0, 0.2); //GREEN!
- //glColor3f(1.0, 0.2, 0.2); //RED!
- glVertex3f(0.8,-0.8,0.2);
+ glColor3f(0.2, 1.0, 0.2); // GREEN!
+ // glColor3f(1.0, 0.2, 0.2); //RED!
+ glVertex3f(0.8, -0.8, 0.2);
- glColor3f(1.0, 0.2, 0.2); //RED!
- glVertex3f(0,1.2,0.2);
- glEnd();
- glPopMatrix();
+ glColor3f(1.0, 0.2, 0.2); // RED!
+ glVertex3f(0, 1.2, 0.2);
+ glEnd();
+ glPopMatrix();
}
+void draw2() {
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ int x = 0;
+ // Select and setup the projection matrix
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ mat4 m = perspective(65.0f, (GLfloat)winSizeX / (GLfloat)winSizeY, 1.0f, 100.0f);
+ glLoadMatrixf(m.d);
+ // GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
+ // glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
+ // Select and setup the modelview matrix
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRotatef(-90, 1, 0, 0);
+ glTranslatef(0, 0, -1.0f);
-void draw2(){
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- int x = 0;
- // Select and setup the projection matrix
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- mat4 m = perspective( 65.0f, (GLfloat)winSizeX/(GLfloat)winSizeY, 1.0f, 100.0f );
- glLoadMatrixf( m.d);
- //GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
- //glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
- // Select and setup the modelview matrix
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- glRotatef(-90, 1,0,0);
- glTranslatef(0,0,-1.0f);
-
- // Draw a rotating colorful triangle
- glTranslatef( 0.0f, 14.0f, 0.0f );
- glRotatef( 0.3f*(GLfloat)x + (GLfloat)time_passed*100.0f, 0.0f, 0.0f, 1.0f );
- glBegin( GL_TRIANGLES );
- glColor4f( 1.0f, 0.0f, 0.0f, 0.0f );
- glVertex3f( -5.0f, 0.0f, -4.0f );
- glColor4f( 0.0f, 1.0f, 0.0f, 0.0f );
- glVertex3f( 5.0f, 0.0f, -4.0f );
- glColor4f( 0.0f, 0.0f, 1.0f, 0.0f );
- glVertex3f( 0.0f, 0.0f, 6.0f );
- glEnd();
+ // Draw a rotating colorful triangle
+ glTranslatef(0.0f, 14.0f, 0.0f);
+ glRotatef(0.3f * (GLfloat)x + (GLfloat)time_passed * 100.0f, 0.0f, 0.0f, 1.0f);
+ glBegin(GL_TRIANGLES);
+ glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
+ glVertex3f(-5.0f, 0.0f, -4.0f);
+ glColor4f(0.0f, 1.0f, 0.0f, 0.0f);
+ glVertex3f(5.0f, 0.0f, -4.0f);
+ glColor4f(0.0f, 0.0f, 1.0f, 0.0f);
+ glVertex3f(0.0f, 0.0f, 6.0f);
+ glEnd();
}
void initScene() {
- //glLightfv( GL_LIGHT0, GL_AMBIENT, white);
- //glLightfv( GL_LIGHT0, GL_SPECULAR, white);
- //glEnable( GL_CULL_FACE );
- glDisable( GL_CULL_FACE );
- glEnable( GL_LIGHTING );
- glDisable( GL_TEXTURE_2D );
- glDisable( GL_LIGHTING );
- //glEnable( GL_LIGHT0 );
- glEnable( GL_DEPTH_TEST );
- glShadeModel( GL_SMOOTH );
+ // glLightfv( GL_LIGHT0, GL_AMBIENT, white);
+ // glLightfv( GL_LIGHT0, GL_SPECULAR, white);
+ // glEnable( GL_CULL_FACE );
+ glDisable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_LIGHTING);
+ // glEnable( GL_LIGHT0 );
+ glEnable(GL_DEPTH_TEST);
+ glShadeModel(GL_SMOOTH);
glTextSize(GL_TEXT_SIZE24x24);
/*
{
@@ -106,48 +105,44 @@
printf("\nCan't load texture!\n");
}
}*/
- glEnable( GL_NORMALIZE );
+ glEnable(GL_NORMALIZE);
}
-int main(int argc, char **argv) {
- // initialize SDL video:
+int main(int argc, char** argv) {
+ // initialize SDL video:
- unsigned int fps =0;
+ unsigned int fps = 0;
char needsRGBAFix = 0;
- if(argc > 2){
- char* larg = argv[1];
- for(int i = 0; i < argc; i++){
- if(!strcmp(larg,"-w"))
+ if (argc > 2) {
+ char* larg = argv[1];
+ for (int i = 0; i < argc; i++) {
+ if (!strcmp(larg, "-w"))
winSizeX = atoi(argv[i]);
- if(!strcmp(larg,"-h"))
+ if (!strcmp(larg, "-h"))
winSizeY = atoi(argv[i]);
- if(!strcmp(larg,"-fps"))
- fps = strtoull(argv[i],0,10);
+ if (!strcmp(larg, "-fps"))
+ fps = strtoull(argv[i], 0, 10);
larg = argv[i];
- }
- }
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)<0) {
- fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
- return 1;
- }
+ }
+ }
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
+ fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
+ return 1;
+ }
#ifdef PLAY_MUSIC
- ainit(0);
+ ainit(0);
#endif
- SDL_Surface* screen = NULL;
- if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
- fprintf(stderr,"ERROR: Video mode set failed.\n");
- return 1;
- }
- printf("\nRMASK IS %u",screen->format->Rmask);
- printf("\nGMASK IS %u",screen->format->Gmask);
- printf("\nBMASK IS %u",screen->format->Bmask);
- printf("\nAMASK IS %u",screen->format->Amask);
+ SDL_Surface* screen = NULL;
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ printf("\nRMASK IS %u", screen->format->Rmask);
+ printf("\nGMASK IS %u", screen->format->Gmask);
+ printf("\nBMASK IS %u", screen->format->Bmask);
+ printf("\nAMASK IS %u", screen->format->Amask);
#if TGL_FEATURE_RENDER_BITS == 32
- if(
- screen->format->Rmask != 0x00FF0000 ||
- screen->format->Gmask != 0x0000FF00 ||
- screen->format->Bmask != 0x000000FF
- ){
+ if (screen->format->Rmask != 0x00FF0000 || screen->format->Gmask != 0x0000FF00 || screen->format->Bmask != 0x000000FF) {
needsRGBAFix = 1;
printf("\nYour screen is using an RGBA output different than this library expects.");
printf("\nYou should consider using the 16 bit version for optimal performance");
@@ -154,148 +149,149 @@
}
#endif
- printf("\nRSHIFT IS %u",screen->format->Rshift);
- printf("\nGSHIFT IS %u",screen->format->Gshift);
- printf("\nBSHIFT IS %u",screen->format->Bshift);
- printf("\nASHIFT IS %u\n",screen->format->Ashift);
- fflush(stdout);
- track* myTrack = NULL;
+ printf("\nRSHIFT IS %u", screen->format->Rshift);
+ printf("\nGSHIFT IS %u", screen->format->Gshift);
+ printf("\nBSHIFT IS %u", screen->format->Bshift);
+ printf("\nASHIFT IS %u\n", screen->format->Ashift);
+ fflush(stdout);
+ track* myTrack = NULL;
#ifdef PLAY_MUSIC
- myTrack = lmus("WWGW.mp3");
- mplay(myTrack, -1, 1000);
+ myTrack = lmus("WWGW.mp3");
+ mplay(myTrack, -1, 1000);
#endif
- SDL_ShowCursor(SDL_DISABLE);
- SDL_WM_SetCaption(argv[0],0);
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_WM_SetCaption(argv[0], 0);
- // initialize TinyGL:
- //unsigned int pitch;
- int mode;
- switch( screen->format->BitsPerPixel ) {
- case 8:
- fprintf(stderr,"ERROR: Palettes are currently not supported.\n");
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- return 1;
- case 16:
-
- //fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_5R6G5B;
- //return 1;
- break;
- case 24:
-
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_RGB24;
- return 1;
- break;
- case 32:
-
- mode = ZB_MODE_RGBA;
- break;
- default:
- return 1;
- break;
- }
- ZBuffer *frameBuffer = ZB_open( winSizeX, winSizeY, mode, 0, 0, 0, 0);
- glInit( frameBuffer );
+ // initialize TinyGL:
+ // unsigned int pitch;
+ int mode;
+ switch (screen->format->BitsPerPixel) {
+ case 8:
+ fprintf(stderr, "ERROR: Palettes are currently not supported.\n");
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ return 1;
+ case 16:
- // initialize GL:
- glClearColor (0.0, 0.0, 0.0, 0.0);
- glViewport (0, 0, winSizeX, winSizeY);
- glEnable(GL_DEPTH_TEST);
- //GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- //glTranslatef( 0.0, 0.0, -45.0 );
+ // fprintf(stderr,"\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_5R6G5B;
+ // return 1;
+ break;
+ case 24:
- initScene();
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_RGB24;
+ return 1;
+ break;
+ case 32:
- // variables for timing:
- unsigned int frames=0;
- unsigned int tNow=SDL_GetTicks();
- unsigned int tLastFps=tNow;
+ mode = ZB_MODE_RGBA;
+ break;
+ default:
+ return 1;
+ break;
+ }
+ ZBuffer* frameBuffer = ZB_open(winSizeX, winSizeY, mode, 0, 0, 0, 0);
+ glInit(frameBuffer);
- // main loop:
- int isRunning=1;
- while(isRunning) {
- ++frames;
- tNow=SDL_GetTicks();
- time_passed += 0.01666666;
- // do event handling:
- SDL_Event evt;
- while( SDL_PollEvent( &evt ) ) switch(evt.type) {
- case SDL_KEYDOWN:
- switch(evt.key.keysym.sym) {
- case SDLK_ESCAPE :
- case SDLK_q :
- isRunning=0;
- default:
- break;
- }
- break;
- case SDL_QUIT:
- isRunning=0;
- break;
- }
+ // initialize GL:
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glViewport(0, 0, winSizeX, winSizeY);
+ glEnable(GL_DEPTH_TEST);
+ // GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ // glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ // glTranslatef( 0.0, 0.0, -45.0 );
- // draw scene:
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- draw2();
+ initScene();
+
+ // variables for timing:
+ unsigned int frames = 0;
+ unsigned int tNow = SDL_GetTicks();
+ unsigned int tLastFps = tNow;
+
+ // main loop:
+ int isRunning = 1;
+ while (isRunning) {
+ ++frames;
+ tNow = SDL_GetTicks();
+ time_passed += 0.01666666;
+ // do event handling:
+ SDL_Event evt;
+ while (SDL_PollEvent(&evt))
+ switch (evt.type) {
+ case SDL_KEYDOWN:
+ switch (evt.key.keysym.sym) {
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ isRunning = 0;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ isRunning = 0;
+ break;
+ }
+
+ // draw scene:
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ draw2();
glDrawText((unsigned char*)"Hello World!\nFrom TinyGL", 0, 0, 0x00FFFFFF);
- // swap buffers:
- if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
- fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
- return 1;
- }
- /*
+ // swap buffers:
+ if (SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen) < 0)) {
+ fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
+ return 1;
+ }
+ /*
printf("\nRMASK IS %u",screen->format->Rmask);
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
- */
- //Quickly convert all pixels to the correct format
+ */
+ // Quickly convert all pixels to the correct format
#if TGL_FEATURE_RENDER_BITS == 32
- if(needsRGBAFix)
- for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
+ if (needsRGBAFix)
+ for (int i = 0; i < frameBuffer->xsize * frameBuffer->ysize; i++) {
#define DATONE (frameBuffer->pbuf[i])
- DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
- ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
- ((DATONE & 0x00FF0000) >>16) << screen->format->Bshift;
- }
+ DATONE = ((DATONE & 0x000000FF)) << screen->format->Rshift | ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
+ ((DATONE & 0x00FF0000) >> 16) << screen->format->Bshift;
+ }
#endif
- ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if ( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen);
- SDL_Flip(screen);
- if(fps>0)
- if((1000/fps)>(SDL_GetTicks()-tNow))
- {
- SDL_Delay((1000/fps)-(SDL_GetTicks()-tNow)); //Yay stable framerate!
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+ if (fps > 0)
+ if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
+ SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
}
- // check for error conditions:
- char* sdl_error = SDL_GetError( );
- if( sdl_error[0] != '\0' ) {
- fprintf(stderr,"SDL ERROR: \"%s\"\n",sdl_error);
- SDL_ClearError();
- }
- // update fps:
- if(tNow>=tLastFps+5000) {
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- tLastFps=tNow;
- frames=0;
- }
- }
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- // cleanup:
- ZB_close(frameBuffer);
- if(SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ // check for error conditions:
+ char* sdl_error = SDL_GetError();
+ if (sdl_error[0] != '\0') {
+ fprintf(stderr, "SDL ERROR: \"%s\"\n", sdl_error);
+ SDL_ClearError();
+ }
+ // update fps:
+ if (tNow >= tLastFps + 5000) {
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f,
+ (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ tLastFps = tNow;
+ frames = 0;
+ }
+ }
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f, (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ // cleanup:
+ ZB_close(frameBuffer);
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- mhalt();
- Mix_FreeMusic(myTrack);
- acleanup();
+ mhalt();
+ Mix_FreeMusic(myTrack);
+ acleanup();
#endif
- SDL_Quit();
- return 0;
+ SDL_Quit();
+ return 0;
}
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -7,8 +7,8 @@
//#define PLAY_MUSIC
#include <math.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../include/GL/gl.h"
@@ -18,168 +18,125 @@
#include "include/3dMath.h"
#include "include/tobjparse.h"
#define CHAD_API_IMPL
+#include "../include/zbuffer.h"
#include "include/api_audio.h"
#include <SDL/SDL.h>
-#include "../include/zbuffer.h"
#include <time.h>
#ifndef M_PI
-# define M_PI 3.14159265
+#define M_PI 3.14159265
#endif
-
-
-
-vec3 campos = (vec3){.d[0]=0,.d[1]=0,.d[2]=-3};
-vec3 camforw = (vec3){.d[0]=0,.d[1]=0,.d[2]=-1};
-vec3 camup = (vec3){.d[0]=0,.d[1]=1,.d[2]=0};
-uint wasdstate[4] = {0,0,0,0};
-const float mouseratiox = 1.0/300.0f;
-const float mouseratioy = 1.0/300.0f;
+vec3 campos = (vec3){.d[0] = 0, .d[1] = 0, .d[2] = -3};
+vec3 camforw = (vec3){.d[0] = 0, .d[1] = 0, .d[2] = -1};
+vec3 camup = (vec3){.d[0] = 0, .d[1] = 1, .d[2] = 0};
+uint wasdstate[4] = {0, 0, 0, 0};
+const float mouseratiox = 1.0 / 300.0f;
+const float mouseratioy = 1.0 / 300.0f;
int mousex = 0, mousey = 0;
-void rotateCamera(){
+void rotateCamera() {
vec3 a;
a.d[1] = (float)mousex * mouseratiox;
a.d[2] = (float)mousey * mouseratioy;
- //if(fabsf(camforw.d[0]) < 0.001) camforw.d[0] = 0.001;
- vec3 right = normalizev3(
- crossv3(
- normalizev3(camforw),
- normalizev3(camup)
- )
- );right.d[1]=0;
- vec3 result = rotatev3(camforw,right,-a.d[2]);
- camup = crossv3(right,camforw);
- camforw = rotatev3(result,camup,-a.d[1]);
- //if(fabsf(camforw.d[0]) < 0.001) camforw.d[0] = 0.001;
+ // if(fabsf(camforw.d[0]) < 0.001) camforw.d[0] = 0.001;
+ vec3 right = normalizev3(crossv3(normalizev3(camforw), normalizev3(camup)));
+ right.d[1] = 0;
+ vec3 result = rotatev3(camforw, right, -a.d[2]);
+ camup = crossv3(right, camforw);
+ camforw = rotatev3(result, camup, -a.d[1]);
+ // if(fabsf(camforw.d[0]) < 0.001) camforw.d[0] = 0.001;
}
-
-
-GLuint loadRGBTexture(unsigned char* buf, unsigned int w, unsigned int h){
+GLuint loadRGBTexture(unsigned char* buf, unsigned int w, unsigned int h) {
GLuint t = 0;
glGenTextures(1, &t);
// for(unsigned int i = 0; i < w * h; i++)
- // {
- // unsigned char t = 0;
- // unsigned char* r = buf + i*3;
- // // unsigned char* g = buf + i*3+1;
- // unsigned char* b = buf + i*3+2;
- // t = *r;
- // *r = *b;
- // *b = t;
- // }
- glBindTexture(GL_TEXTURE_2D,t);
+ // {
+ // unsigned char t = 0;
+ // unsigned char* r = buf + i*3;
+ // // unsigned char* g = buf + i*3+1;
+ // unsigned char* b = buf + i*3+2;
+ // t = *r;
+ // *r = *b;
+ // *b = t;
+ // }
+ glBindTexture(GL_TEXTURE_2D, t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D,0,3,w,h,0,GL_RGB,GL_UNSIGNED_BYTE,buf);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
return t;
}
-
void drawModel(
-//HUGE important note! these depend on the math library using
-//f_ as float and not double!
-//Remember that!
- vec3* points, uint npoints,
- vec3* colors,
- vec3* normals,
- vec3* texcoords
-){
- if(!points)return;
+ // HUGE important note! these depend on the math library using
+ // f_ as float and not double!
+ // Remember that!
+ vec3* points, uint npoints, vec3* colors, vec3* normals, vec3* texcoords) {
+ if (!points)
+ return;
glBegin(GL_TRIANGLES);
- for(uint i = 0; i < npoints;i++){
- if(colors){ //Fix for TinyGL color interpolation.
- glColor3f(colors[i].d[0],colors[i].d[1],colors[i].d[2]);
+ for (uint i = 0; i < npoints; i++) {
+ if (colors) { // Fix for TinyGL color interpolation.
+ glColor3f(colors[i].d[0], colors[i].d[1], colors[i].d[2]);
}
- if(texcoords)
- glTexCoord2f(texcoords[i].d[0],texcoords[i].d[1]);
- if(normals)
- glNormal3f(normals[i].d[0],normals[i].d[1],normals[i].d[2]);
- glVertex3f(points[i].d[0],points[i].d[1],points[i].d[2]);
+ if (texcoords)
+ glTexCoord2f(texcoords[i].d[0], texcoords[i].d[1]);
+ if (normals)
+ glNormal3f(normals[i].d[0], normals[i].d[1], normals[i].d[2]);
+ glVertex3f(points[i].d[0], points[i].d[1], points[i].d[2]);
}
glEnd();
}
-
-
-
GLuint createModelDisplayList(
-//HUGE important note! these depend on the math library using
-//f_ as float and not double!
-//Remember that!
- vec3* points, uint npoints,
- vec3* colors,
- vec3* normals,
- vec3* texcoords
-){
+ // HUGE important note! these depend on the math library using
+ // f_ as float and not double!
+ // Remember that!
+ vec3* points, uint npoints, vec3* colors, vec3* normals, vec3* texcoords) {
GLuint ret = 0;
- if(!points)return 0;
+ if (!points)
+ return 0;
ret = glGenLists(1);
glNewList(ret, GL_COMPILE);
- glBegin(GL_TRIANGLES);
- for(uint i = 0; i < npoints; i++){
- if(colors){
- glColor3f(colors[i].d[0],colors[i].d[1],colors[i].d[2]);
- }
- if(texcoords)
- glTexCoord2f(texcoords[i].d[0],texcoords[i].d[1]);
- if(normals)
- glNormal3f(normals[i].d[0],normals[i].d[1],normals[i].d[2]);
- glVertex3f(points[i].d[0],points[i].d[1],points[i].d[2]);
+ glBegin(GL_TRIANGLES);
+ for (uint i = 0; i < npoints; i++) {
+ if (colors) {
+ glColor3f(colors[i].d[0], colors[i].d[1], colors[i].d[2]);
}
- //printf("\ncreateModelDisplayList is not the problem.\n");
- glEnd();
+ if (texcoords)
+ glTexCoord2f(texcoords[i].d[0], texcoords[i].d[1]);
+ if (normals)
+ glNormal3f(normals[i].d[0], normals[i].d[1], normals[i].d[2]);
+ glVertex3f(points[i].d[0], points[i].d[1], points[i].d[2]);
+ }
+ // printf("\ncreateModelDisplayList is not the problem.\n");
+ glEnd();
glEndList();
return ret;
}
+GLubyte stipplepattern[128] = {0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
-GLubyte stipplepattern[128] = {
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
-
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55,
- 0xAA,0xAA,0xAA,0xAA,
- 0x55,0x55,0x55,0x55
-};
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
+ 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};
-
-#define BEGIN_EVENT_HANDLER void events(SDL_Event* e){switch(e->type){
+#define BEGIN_EVENT_HANDLER \
+ void events(SDL_Event* e) { \
+ switch (e->type) {
#define E_KEYSYM e->key.keysym.sym
-#define END_EVENT_HANDLER }}
+#define END_EVENT_HANDLER \
+ } \
+ }
#define EVENT_HANDLER events
#define E_MOTION e->motion
#define E_BUTTON e->button.button
@@ -187,7 +144,7 @@
#define E_WINW e->window.data1
#define E_WINH e->window.data2
-int isRunning=1;
+int isRunning = 1;
/*
mousex = (kHeld & KEY_Y)?-30:0 + (kHeld & KEY_A)?30:0;
@@ -195,386 +152,377 @@
*/
BEGIN_EVENT_HANDLER
case SDL_KEYDOWN:
- switch(E_KEYSYM) {
- case SDLK_w:
- wasdstate[0] = 1;break;
- case SDLK_a:
- wasdstate[1] = 1;break;
- case SDLK_s:
- wasdstate[2] = 1;break;
- case SDLK_d:
- wasdstate[3] = 1;break;
- case SDLK_UP:
- mousey = -30;
- break;
- case SDLK_DOWN:
- mousey = 30;
- break;
- case SDLK_LEFT:
- mousex = -30;
- break;
- case SDLK_RIGHT:
- mousex = 30;
- break;
- case SDLK_ESCAPE :
- case SDLK_q :
- isRunning=0;break;
- default:
- break;
- }
+switch (E_KEYSYM) {
+case SDLK_w:
+ wasdstate[0] = 1;
break;
+case SDLK_a:
+ wasdstate[1] = 1;
+ break;
+case SDLK_s:
+ wasdstate[2] = 1;
+ break;
+case SDLK_d:
+ wasdstate[3] = 1;
+ break;
+case SDLK_UP:
+ mousey = -30;
+ break;
+case SDLK_DOWN:
+ mousey = 30;
+ break;
+case SDLK_LEFT:
+ mousex = -30;
+ break;
+case SDLK_RIGHT:
+ mousex = 30;
+ break;
+case SDLK_ESCAPE:
+case SDLK_q:
+ isRunning = 0;
+ break;
+default:
+ break;
+}
+break;
case SDL_KEYUP:
- switch(E_KEYSYM) {
- case SDLK_w:
- wasdstate[0] = 0;break;
- case SDLK_a:
- wasdstate[1] = 0;break;
- case SDLK_s:
- wasdstate[2] = 0;break;
- case SDLK_d:
- wasdstate[3] = 0;break;
- case SDLK_UP:
- case SDLK_DOWN:
- mousey = 0; break;
- case SDLK_LEFT:
- case SDLK_RIGHT:
- mousex = 0; break;
- default:
- break;
- }
+switch (E_KEYSYM) {
+case SDLK_w:
+ wasdstate[0] = 0;
break;
-case SDL_QUIT:
- isRunning=0;
+case SDLK_a:
+ wasdstate[1] = 0;
break;
+case SDLK_s:
+ wasdstate[2] = 0;
+ break;
+case SDLK_d:
+ wasdstate[3] = 0;
+ break;
+case SDLK_UP:
+case SDLK_DOWN:
+ mousey = 0;
+ break;
+case SDLK_LEFT:
+case SDLK_RIGHT:
+ mousex = 0;
+ break;
+default:
+ break;
+}
+break;
+case SDL_QUIT:
+isRunning = 0;
+break;
END_EVENT_HANDLER
-int main(int argc, char **argv) {
- // initialize SDL video:
- int winSizeX=640;
- int winSizeY=480;
- char needsRGBAFix = 0;
- unsigned int count = 40;
- GLuint modelDisplayList = 0; int dlExists = 0; int doTextures = 1;
+int main(int argc, char** argv) {
+ // initialize SDL video:
+ int winSizeX = 640;
+ int winSizeY = 480;
+ char needsRGBAFix = 0;
+ unsigned int count = 40;
+ GLuint modelDisplayList = 0;
+ int dlExists = 0;
+ int doTextures = 1;
char* modelName = "extrude.obj";
track* myTrack = NULL;
- unsigned int fps =0;
- if(argc > 2){
- char* larg = argv[1];
- for(int i = 0; i < argc; i++){
- if(!strcmp(larg,"-w"))
+ unsigned int fps = 0;
+ if (argc > 2) {
+ char* larg = argv[1];
+ for (int i = 0; i < argc; i++) {
+ if (!strcmp(larg, "-w"))
winSizeX = atoi(argv[i]);
- if(!strcmp(larg,"-h"))
+ if (!strcmp(larg, "-h"))
winSizeY = atoi(argv[i]);
- if(!strcmp(larg,"-fps"))
- fps = strtoull(argv[i],0,10);
- if(!strcmp(larg,"-count"))
- count = strtoull(argv[i],0,10);
- if(!strcmp(larg,"-m"))
+ if (!strcmp(larg, "-fps"))
+ fps = strtoull(argv[i], 0, 10);
+ if (!strcmp(larg, "-count"))
+ count = strtoull(argv[i], 0, 10);
+ if (!strcmp(larg, "-m"))
modelName = argv[i];
- if(!strcmp(argv[i],"-notexture") || !strcmp(larg,"-notexture"))
+ if (!strcmp(argv[i], "-notexture") || !strcmp(larg, "-notexture"))
doTextures = 0;
larg = argv[i];
- }
- }
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)<0) {
- fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
- return 1;
- }
+ }
+ }
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
+ fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
+ return 1;
+ }
#ifdef PLAY_MUSIC
- ainit(0);
+ ainit(0);
#endif
- SDL_Surface* screen = NULL;
- if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
- fprintf(stderr,"ERROR: Video mode set failed.\n");
- return 1;
- }
- printf("\nRMASK IS %u",screen->format->Rmask);
- printf("\nGMASK IS %u",screen->format->Gmask);
- printf("\nBMASK IS %u",screen->format->Bmask);
- printf("\nAMASK IS %u",screen->format->Amask);
+ SDL_Surface* screen = NULL;
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ printf("\nRMASK IS %u", screen->format->Rmask);
+ printf("\nGMASK IS %u", screen->format->Gmask);
+ printf("\nBMASK IS %u", screen->format->Bmask);
+ printf("\nAMASK IS %u", screen->format->Amask);
#if TGL_FEATURE_RENDER_BITS == 32
- if(
- screen->format->Rmask != 0x00FF0000 ||
- screen->format->Gmask != 0x0000FF00 ||
- screen->format->Bmask != 0x000000FF
- ){
+ if (screen->format->Rmask != 0x00FF0000 || screen->format->Gmask != 0x0000FF00 || screen->format->Bmask != 0x000000FF) {
needsRGBAFix = 1;
printf("\nYour screen is using an RGBA output different than this library expects.");
printf("\nYou should consider using the 16 bit version for optimal performance");
}
#endif
- printf("\nRSHIFT IS %u",screen->format->Rshift);
- printf("\nGSHIFT IS %u",screen->format->Gshift);
- printf("\nBSHIFT IS %u",screen->format->Bshift);
- printf("\nASHIFT IS %u\n",screen->format->Ashift);
- fflush(stdout);
+ printf("\nRSHIFT IS %u", screen->format->Rshift);
+ printf("\nGSHIFT IS %u", screen->format->Gshift);
+ printf("\nBSHIFT IS %u", screen->format->Bshift);
+ printf("\nASHIFT IS %u\n", screen->format->Ashift);
+ fflush(stdout);
#ifdef PLAY_MUSIC
myTrack = lmus("WWGW.mp3");
mplay(myTrack, -1, 1000);
#endif
-
- SDL_ShowCursor(SDL_DISABLE);
- SDL_WM_SetCaption(argv[0],0);
- // initialize TinyGL:
- int mode;
- switch( screen->format->BitsPerPixel ) {
- case 8:
- fprintf(stderr,"ERROR: Palettes are currently not supported.\n");
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- return 1;
- case 16:
- //fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_5R6G5B;
- //return 1;
- break;
- case 24:
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_RGB24;
- return 1;
- break;
- case 32:
- mode = ZB_MODE_RGBA;
- break;
- default:
- return 1;
- break;
- }
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_WM_SetCaption(argv[0], 0);
- ZBuffer *frameBuffer = ZB_open( winSizeX, winSizeY, mode, 0, 0, 0, 0);
- glInit( frameBuffer );
+ // initialize TinyGL:
+ int mode;
+ switch (screen->format->BitsPerPixel) {
+ case 8:
+ fprintf(stderr, "ERROR: Palettes are currently not supported.\n");
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ return 1;
+ case 16:
+ // fprintf(stderr,"\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_5R6G5B;
+ // return 1;
+ break;
+ case 24:
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_RGB24;
+ return 1;
+ break;
+ case 32:
+ mode = ZB_MODE_RGBA;
+ break;
+ default:
+ return 1;
+ break;
+ }
+ ZBuffer* frameBuffer = ZB_open(winSizeX, winSizeY, mode, 0, 0, 0, 0);
+ glInit(frameBuffer);
+
srand(time(NULL));
-// initGL(winSizeX,winSizeY);
- // initialize GL:
- glShadeModel(GL_SMOOTH);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- // glEnable(GL_TEXTURE_2D);
- glEnable(GL_COLOR_MATERIAL);
- // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
- glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
- glClearColor(0,0,0,0);
- glClearDepth(1.0f);
+ // initGL(winSizeX,winSizeY);
+ // initialize GL:
+ glShadeModel(GL_SMOOTH);
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ // glEnable(GL_TEXTURE_2D);
+ glEnable(GL_COLOR_MATERIAL);
+ // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ glClearColor(0, 0, 0, 0);
+ glClearDepth(1.0f);
-
- glClearColor(0,0,0.3,0);
+ glClearColor(0, 0, 0.3, 0);
glDisable(GL_TEXTURE_2D);
-
+
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
- //glDisable(GL_DEPTH_TEST);
+ // glDisable(GL_DEPTH_TEST);
double t = 0;
- glViewport(0,0,winSizeX,winSizeY);
- //glEnable(GL_POLYGON_STIPPLE);
- //glPolygonStipple(stipplepattern);
- //initScene();
+ glViewport(0, 0, winSizeX, winSizeY);
+ // glEnable(GL_POLYGON_STIPPLE);
+ // glPolygonStipple(stipplepattern);
+ // initScene();
{
- objraw omodel; model m = initmodel();
+ objraw omodel;
+ model m = initmodel();
omodel = tobj_load(modelName);
-
- if(!omodel.positions) {puts("\nERROR! No positions in model. Aborting...\n");} else {
- m = tobj_tomodel(&omodel);
- printf("\nHas %d points.\n",m.npoints);
- modelDisplayList = createModelDisplayList(
- m.d, m.npoints,
- m.c,
- m.n,
- m.t
- );dlExists = 1;
- freemodel(&m);
+
+ if (!omodel.positions) {
+ puts("\nERROR! No positions in model. Aborting...\n");
+ } else {
+ m = tobj_tomodel(&omodel);
+ printf("\nHas %d points.\n", m.npoints);
+ modelDisplayList = createModelDisplayList(m.d, m.npoints, m.c, m.n, m.t);
+ dlExists = 1;
+ freemodel(&m);
}
freeobjraw(&omodel);
}
GLuint tex = 0;
- if(doTextures){
- int sw = 0, sh = 0, sc = 0; //sc goes unused.
+ if (doTextures) {
+ int sw = 0, sh = 0, sc = 0; // sc goes unused.
uchar* source_data = stbi_load("tex.jpg", &sw, &sh, &sc, 3);
- if(source_data){
+ if (source_data) {
tex = loadRGBTexture(source_data, sw, sh);
free(source_data);
}
- //tex =
+ // tex =
}
glDisable(GL_LIGHTING);
- //glEnable( GL_NORMALIZE );
- // variables for timing:
- unsigned int frames=0;
- unsigned int tNow=SDL_GetTicks();
- unsigned int tLastFps=tNow;
+ // glEnable( GL_NORMALIZE );
+ // variables for timing:
+ unsigned int frames = 0;
+ unsigned int tNow = SDL_GetTicks();
+ unsigned int tLastFps = tNow;
- // main loop:
-
- while(isRunning) {
- ++frames;
- t+=0.016666f;
- tNow=SDL_GetTicks();
- // do event handling:
- SDL_Event evt;
- mousex = 0; mousey = 0;
- while( SDL_PollEvent( &evt ) ) EVENT_HANDLER(&evt) ;
-/*
- switch(evt.type) {
-
-
- }
-*/
- // draw scene:
+ // main loop:
+
+ while (isRunning) {
+ ++frames;
+ t += 0.016666f;
+ tNow = SDL_GetTicks();
+ // do event handling:
+ SDL_Event evt;
+ mousex = 0;
+ mousey = 0;
+ while (SDL_PollEvent(&evt))
+ EVENT_HANDLER(&evt);
+ /*
+ switch(evt.type) {
+
+
+ }
+ */
+ // draw scene:
#define WIDTH winSizeX
#define HEIGHT winSizeY
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- //gluPerspective(70,(float)WIDTH/(float)HEIGHT,1,512);
- mat4 matrix = perspective(70,(float)WIDTH/(float)HEIGHT,1,512);
+ // gluPerspective(70,(float)WIDTH/(float)HEIGHT,1,512);
+ mat4 matrix = perspective(70, (float)WIDTH / (float)HEIGHT, 1, 512);
glLoadMatrixf(matrix.d);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- glPushMatrix(); //Pushing on the LookAt Matrix.
+ glPushMatrix(); // Pushing on the LookAt Matrix.
- vec3 right = normalizev3(
- crossv3(
- normalizev3(camforw),
- normalizev3(camup)
- )
- );right.d[1]=0;
- matrix = (lookAt(campos,addv3(campos,camforw),camup)); //Using right vector to correct for screen rotation.
+ vec3 right = normalizev3(crossv3(normalizev3(camforw), normalizev3(camup)));
+ right.d[1] = 0;
+ matrix = (lookAt(campos, addv3(campos, camforw), camup)); // Using right vector to correct for screen rotation.
glLoadMatrixf(matrix.d);
- if(wasdstate[0])
- campos = addv3(campos,
- scalev3(0.1,
- camforw
- )
- );
- if(wasdstate[2])
- campos = addv3(campos,
- scalev3(-0.1,
- camforw
- )
- );
- if(wasdstate[1])
- campos = addv3(campos,
- scalev3(-0.1,
- right
- )
- );
- if(wasdstate[3])
- campos = addv3(campos,
- scalev3(0.1,
- right
- )
- );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ if (wasdstate[0])
+ campos = addv3(campos, scalev3(0.1, camforw));
+ if (wasdstate[2])
+ campos = addv3(campos, scalev3(-0.1, camforw));
+ if (wasdstate[1])
+ campos = addv3(campos, scalev3(-0.1, right));
+ if (wasdstate[3])
+ campos = addv3(campos, scalev3(0.1, right));
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
- if(doTextures)
- glBindTexture(GL_TEXTURE_2D,tex);
- //glDisable(GL_BLEND);
- //glDisable(GL_TEXTURE_2D);
- //printf("\nNew triangle!\n");
- if(!dlExists){
+ if (doTextures)
+ glBindTexture(GL_TEXTURE_2D, tex);
+ // glDisable(GL_BLEND);
+ // glDisable(GL_TEXTURE_2D);
+ // printf("\nNew triangle!\n");
+ if (!dlExists) {
glDisable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
- //glColor3f(0,0,1);
- glColor3f(1,0,0);glTexCoord2f(0,0);glVertex3f(-1,-1,-10);
- glColor3f(0,1,0);glTexCoord2f(1,0);glVertex3f(1,-1,-10);
- glColor3f(0,0,1);glTexCoord2f(0.5,1);glVertex3f(0,1,-10);
- //glColor3f(0,1,0);
+ // glColor3f(0,0,1);
+ glColor3f(1, 0, 0);
+ glTexCoord2f(0, 0);
+ glVertex3f(-1, -1, -10);
+ glColor3f(0, 1, 0);
+ glTexCoord2f(1, 0);
+ glVertex3f(1, -1, -10);
+ glColor3f(0, 0, 1);
+ glTexCoord2f(0.5, 1);
+ glVertex3f(0, 1, -10);
+ // glColor3f(0,1,0);
glEnd();
} else {
- if(doTextures)
+ if (doTextures)
glEnable(GL_TEXTURE_2D);
- //glDisable(GL_TEXTURE_2D);
+ // glDisable(GL_TEXTURE_2D);
glEnable(GL_POLYGON_STIPPLE);
- //glDisable(GL_COLOR_MATERIAL);
- for(unsigned int i = 0; i < count; i++){
+ // glDisable(GL_COLOR_MATERIAL);
+ for (unsigned int i = 0; i < count; i++) {
glPushMatrix();
- glTranslatef((float)(i%10) * 8.0,(float)(i/10) * 8.0,-10);
+ glTranslatef((float)(i % 10) * 8.0, (float)(i / 10) * 8.0, -10);
glCallList(modelDisplayList);
// drawModel(
- // m.d, m.npoints,
- // m.c,
- // m.n,
- // m.t
+ // m.d, m.npoints,
+ // m.c,
+ // m.n,
+ // m.t
// );
glPopMatrix();
}
glDisable(GL_POLYGON_STIPPLE);
- if(doTextures)
+ if (doTextures)
glDisable(GL_TEXTURE_2D);
}
- //draw();
- glPopMatrix(); //The view transform.
+ // draw();
+ glPopMatrix(); // The view transform.
rotateCamera();
glTextSize(GL_TEXT_SIZE16x16);
glDrawText((unsigned char*)"\nModel Viewer Demo-\nTinyGL\nSDL 1.2\n", 0, 0, 0x000000FF);
-
-
-
-
- // swap buffers:
- if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
- fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
- return 1;
- }
- /*
+ // swap buffers:
+ if (SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen) < 0)) {
+ fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
+ return 1;
+ }
+ /*
printf("\nRMASK IS %u",screen->format->Rmask);
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
- */
- //Quickly convert all pixels to the correct format
+ */
+ // Quickly convert all pixels to the correct format
#if TGL_FEATURE_RENDER_BITS == 32
- if(needsRGBAFix)
- for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
+ if (needsRGBAFix)
+ for (int i = 0; i < frameBuffer->xsize * frameBuffer->ysize; i++) {
#define DATONE (frameBuffer->pbuf[i])
- DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
- ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
- ((DATONE & 0x00FF0000) >>16) << screen->format->Bshift;
- }
-#endif
- ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if ( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen);
- SDL_Flip(screen);
- if(fps>0)
- if((1000/fps)>(SDL_GetTicks()-tNow))
- {
- SDL_Delay((1000/fps)-(SDL_GetTicks()-tNow)); //Yay stable framerate!
+ DATONE = ((DATONE & 0x000000FF)) << screen->format->Rshift | ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
+ ((DATONE & 0x00FF0000) >> 16) << screen->format->Bshift;
}
- // check for error conditions:
- char* sdl_error = SDL_GetError( );
- if( sdl_error[0] != '\0' ) {
- fprintf(stderr,"SDL ERROR: \"%s\"\n",sdl_error);
- SDL_ClearError();
- }
- // update fps:
- if(tNow>=tLastFps+5000) {
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- tLastFps=tNow;
- frames=0;
- }
- }
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- // cleanup:
+#endif
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+ if (fps > 0)
+ if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
+ SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
+ }
+ // check for error conditions:
+ char* sdl_error = SDL_GetError();
+ if (sdl_error[0] != '\0') {
+ fprintf(stderr, "SDL ERROR: \"%s\"\n", sdl_error);
+ SDL_ClearError();
+ }
+ // update fps:
+ if (tNow >= tLastFps + 5000) {
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f,
+ (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ tLastFps = tNow;
+ frames = 0;
+ }
+ }
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f, (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ // cleanup:
glDeleteTextures(1, &tex);
- //glDeleteList(modelDisplayList);
+ // glDeleteList(modelDisplayList);
glDeleteLists(modelDisplayList, 1);
- ZB_close(frameBuffer);
-
- if(SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ ZB_close(frameBuffer);
+
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- mhalt();
- Mix_FreeMusic(myTrack);
- acleanup();
+ mhalt();
+ Mix_FreeMusic(myTrack);
+ acleanup();
#endif
- SDL_Quit();
- return 0;
+ SDL_Quit();
+ return 0;
}
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -7,8 +7,8 @@
//#define PLAY_MUSIC
#include <math.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../include/GL/gl.h"
@@ -15,92 +15,85 @@
#define CHAD_API_IMPL
#include "include/api_audio.h"
#define STB_IMAGE_IMPLEMENTATION
+#include "../include/zbuffer.h"
#include "include/stb_image.h"
#include <SDL/SDL.h>
-#include "../include/zbuffer.h"
#ifndef M_PI
-# define M_PI 3.14159265
+#define M_PI 3.14159265
#endif
GLuint tex = 0;
-
-GLuint loadRGBTexture(unsigned char* buf, unsigned int w, unsigned int h){
+GLuint loadRGBTexture(unsigned char* buf, unsigned int w, unsigned int h) {
GLuint t = 0;
glGenTextures(1, &t);
// for(unsigned int i = 0; i < w * h; i++)
- // {
- // unsigned char t = 0;
- // unsigned char* r = buf + i*3;
- // // unsigned char* g = buf + i*3+1;
- // unsigned char* b = buf + i*3+2;
- // t = *r;
- // *r = *b;
- // *b = t;
- // }
- glBindTexture(GL_TEXTURE_2D,t);
+ // {
+ // unsigned char t = 0;
+ // unsigned char* r = buf + i*3;
+ // // unsigned char* g = buf + i*3+1;
+ // unsigned char* b = buf + i*3+2;
+ // t = *r;
+ // *r = *b;
+ // *b = t;
+ // }
+ glBindTexture(GL_TEXTURE_2D, t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D,0,3,w,h,0,GL_RGB,GL_UNSIGNED_BYTE,buf);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
return t;
}
-
void draw() {
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,tex);
- glBegin( GL_TRIANGLES );
- //TRIANGLE 1,
- glTexCoord2f(0,0);
- glVertex3f(-1,-1, 0.5);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glBegin(GL_TRIANGLES);
+ // TRIANGLE 1,
+ glTexCoord2f(0, 0);
+ glVertex3f(-1, -1, 0.5);
-
+ glTexCoord2f(1, -1);
+ glVertex3f(1, 1, 0.5);
- glTexCoord2f(1,-1);
- glVertex3f(1,1, 0.5);
+ glTexCoord2f(0, -1);
+ glVertex3f(-1, 1, 0.5);
+ // TRIANGLE 2
+ glTexCoord2f(0, 0);
+ glVertex3f(-1, -1, 0.5);
- glTexCoord2f(0,-1);
- glVertex3f(-1,1 ,0.5);
- //TRIANGLE 2
- glTexCoord2f(0,0);
- glVertex3f(-1,-1, 0.5);
+ glTexCoord2f(1, 0);
+ glVertex3f(1, -1, 0.5);
-
- glTexCoord2f(1,0);
- glVertex3f(1,-1, 0.5);
-
- glTexCoord2f(1,-1);
- glVertex3f(1,1, 0.5);
- glEnd();
+ glTexCoord2f(1, -1);
+ glVertex3f(1, 1, 0.5);
+ glEnd();
}
-
void initScene() {
- static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
-
-
- static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0 };
+ static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0};
- glLightfv( GL_LIGHT0, GL_POSITION, pos );
- glLightfv( GL_LIGHT0, GL_DIFFUSE, white);
- //glLightfv( GL_LIGHT0, GL_AMBIENT, white);
- //glLightfv( GL_LIGHT0, GL_SPECULAR, white);
- glEnable( GL_CULL_FACE );
- //glDisable( GL_CULL_FACE );
- glEnable( GL_LIGHTING );
- glEnable( GL_TEXTURE_2D );
- glDisable( GL_LIGHTING );
- //glEnable( GL_LIGHT0 );
- glEnable( GL_DEPTH_TEST );
- glShadeModel( GL_SMOOTH );
+ static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
+
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
+ // glLightfv( GL_LIGHT0, GL_AMBIENT, white);
+ // glLightfv( GL_LIGHT0, GL_SPECULAR, white);
+ glEnable(GL_CULL_FACE);
+ // glDisable( GL_CULL_FACE );
+ glEnable(GL_LIGHTING);
+ glEnable(GL_TEXTURE_2D);
+ glDisable(GL_LIGHTING);
+ // glEnable( GL_LIGHT0 );
+ glEnable(GL_DEPTH_TEST);
+ glShadeModel(GL_SMOOTH);
glTextSize(GL_TEXT_SIZE24x24);
{
- int sw = 0, sh = 0, sc = 0; //sc goes unused.
+ int sw = 0, sh = 0, sc = 0; // sc goes unused.
uchar* source_data = stbi_load("texture.png", &sw, &sh, &sc, 3);
- if(source_data){
+ if (source_data) {
tex = loadRGBTexture(source_data, sw, sh);
free(source_data);
} else {
@@ -107,49 +100,45 @@
printf("\nCan't load texture!\n");
}
}
- glEnable( GL_NORMALIZE );
+ glEnable(GL_NORMALIZE);
}
-int main(int argc, char **argv) {
- // initialize SDL video:
- int winSizeX=640;
- int winSizeY=480;
- unsigned int fps =0;
+int main(int argc, char** argv) {
+ // initialize SDL video:
+ int winSizeX = 640;
+ int winSizeY = 480;
+ unsigned int fps = 0;
char needsRGBAFix = 0;
- if(argc > 2){
- char* larg = argv[1];
- for(int i = 0; i < argc; i++){
- if(!strcmp(larg,"-w"))
+ if (argc > 2) {
+ char* larg = argv[1];
+ for (int i = 0; i < argc; i++) {
+ if (!strcmp(larg, "-w"))
winSizeX = atoi(argv[i]);
- if(!strcmp(larg,"-h"))
+ if (!strcmp(larg, "-h"))
winSizeY = atoi(argv[i]);
- if(!strcmp(larg,"-fps"))
- fps = strtoull(argv[i],0,10);
+ if (!strcmp(larg, "-fps"))
+ fps = strtoull(argv[i], 0, 10);
larg = argv[i];
- }
- }
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)<0) {
- fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
- return 1;
- }
+ }
+ }
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
+ fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
+ return 1;
+ }
#ifdef PLAY_MUSIC
- ainit(0);
+ ainit(0);
#endif
- SDL_Surface* screen = NULL;
- if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
- fprintf(stderr,"ERROR: Video mode set failed.\n");
- return 1;
- }
- printf("\nRMASK IS %u",screen->format->Rmask);
- printf("\nGMASK IS %u",screen->format->Gmask);
- printf("\nBMASK IS %u",screen->format->Bmask);
- printf("\nAMASK IS %u",screen->format->Amask);
+ SDL_Surface* screen = NULL;
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ printf("\nRMASK IS %u", screen->format->Rmask);
+ printf("\nGMASK IS %u", screen->format->Gmask);
+ printf("\nBMASK IS %u", screen->format->Bmask);
+ printf("\nAMASK IS %u", screen->format->Amask);
#if TGL_FEATURE_RENDER_BITS == 32
- if(
- screen->format->Rmask != 0x00FF0000 ||
- screen->format->Gmask != 0x0000FF00 ||
- screen->format->Bmask != 0x000000FF
- ){
+ if (screen->format->Rmask != 0x00FF0000 || screen->format->Gmask != 0x0000FF00 || screen->format->Bmask != 0x000000FF) {
needsRGBAFix = 1;
printf("\nYour screen is using an RGBA output different than this library expects.");
printf("\nYou should consider using the 16 bit version for optimal performance");
@@ -156,138 +145,139 @@
}
#endif
- printf("\nRSHIFT IS %u",screen->format->Rshift);
- printf("\nGSHIFT IS %u",screen->format->Gshift);
- printf("\nBSHIFT IS %u",screen->format->Bshift);
- printf("\nASHIFT IS %u\n",screen->format->Ashift);
- fflush(stdout);
- track* myTrack = NULL;
+ printf("\nRSHIFT IS %u", screen->format->Rshift);
+ printf("\nGSHIFT IS %u", screen->format->Gshift);
+ printf("\nBSHIFT IS %u", screen->format->Bshift);
+ printf("\nASHIFT IS %u\n", screen->format->Ashift);
+ fflush(stdout);
+ track* myTrack = NULL;
#ifdef PLAY_MUSIC
- myTrack = lmus("WWGW.mp3");
- mplay(myTrack, -1, 1000);
+ myTrack = lmus("WWGW.mp3");
+ mplay(myTrack, -1, 1000);
#endif
- SDL_ShowCursor(SDL_DISABLE);
- SDL_WM_SetCaption(argv[0],0);
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_WM_SetCaption(argv[0], 0);
- // initialize TinyGL:
-
- int mode;
- switch( screen->format->BitsPerPixel ) {
- case 16:
-
- //fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_5R6G5B;
- //return 1;
- break;
- case 32:
-
- mode = ZB_MODE_RGBA;
- break;
- default:
- return 1;
- break;
- }
- ZBuffer *frameBuffer = ZB_open( winSizeX, winSizeY, mode, 0, 0, 0, 0);
- glInit( frameBuffer );
+ // initialize TinyGL:
- // initialize GL:
- glClearColor (0.0, 0.0, 0.0, 0.0);
- glViewport (0, 0, winSizeX, winSizeY);
- glEnable(GL_DEPTH_TEST);
- //GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- //glTranslatef( 0.0, 0.0, -45.0 );
+ int mode;
+ switch (screen->format->BitsPerPixel) {
+ case 16:
- initScene();
+ // fprintf(stderr,"\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_5R6G5B;
+ // return 1;
+ break;
+ case 32:
- // variables for timing:
- unsigned int frames=0;
- unsigned int tNow=SDL_GetTicks();
- unsigned int tLastFps=tNow;
+ mode = ZB_MODE_RGBA;
+ break;
+ default:
+ return 1;
+ break;
+ }
+ ZBuffer* frameBuffer = ZB_open(winSizeX, winSizeY, mode, 0, 0, 0, 0);
+ glInit(frameBuffer);
- // main loop:
- int isRunning=1;
- while(isRunning) {
- ++frames;
- tNow=SDL_GetTicks();
- // do event handling:
- SDL_Event evt;
- while( SDL_PollEvent( &evt ) ) switch(evt.type) {
- case SDL_KEYDOWN:
- switch(evt.key.keysym.sym) {
- break;
- case SDLK_ESCAPE :
- case SDLK_q :
- isRunning=0;
- default:
- break;
- }
- break;
- case SDL_QUIT:
- isRunning=0;
- break;
- }
+ // initialize GL:
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glViewport(0, 0, winSizeX, winSizeY);
+ glEnable(GL_DEPTH_TEST);
+ // GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ // glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ // glTranslatef( 0.0, 0.0, -45.0 );
- // draw scene:
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- draw();
+ initScene();
+
+ // variables for timing:
+ unsigned int frames = 0;
+ unsigned int tNow = SDL_GetTicks();
+ unsigned int tLastFps = tNow;
+
+ // main loop:
+ int isRunning = 1;
+ while (isRunning) {
+ ++frames;
+ tNow = SDL_GetTicks();
+ // do event handling:
+ SDL_Event evt;
+ while (SDL_PollEvent(&evt))
+ switch (evt.type) {
+ case SDL_KEYDOWN:
+ switch (evt.key.keysym.sym) {
+ break;
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ isRunning = 0;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ isRunning = 0;
+ break;
+ }
+
+ // draw scene:
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ draw();
glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x000000FF);
- // swap buffers:
- if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
- fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
- return 1;
- }
- /*
+ // swap buffers:
+ if (SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen) < 0)) {
+ fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
+ return 1;
+ }
+ /*
printf("\nRMASK IS %u",screen->format->Rmask);
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
- */
- //Quickly convert all pixels to the correct format
+ */
+ // Quickly convert all pixels to the correct format
#if TGL_FEATURE_RENDER_BITS == 32
-if(needsRGBAFix)
- for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
+ if (needsRGBAFix)
+ for (int i = 0; i < frameBuffer->xsize * frameBuffer->ysize; i++) {
#define DATONE (frameBuffer->pbuf[i])
- DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
- ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
- ((DATONE & 0x00FF0000) >>16) << screen->format->Bshift;
- }
+ DATONE = ((DATONE & 0x000000FF)) << screen->format->Rshift | ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
+ ((DATONE & 0x00FF0000) >> 16) << screen->format->Bshift;
+ }
#endif
- ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if ( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen);
- SDL_Flip(screen);
- if(fps>0)
- if((1000/fps)>(SDL_GetTicks()-tNow))
- {
- SDL_Delay((1000/fps)-(SDL_GetTicks()-tNow)); //Yay stable framerate!
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+ if (fps > 0)
+ if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
+ SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
}
- // check for error conditions:
- char* sdl_error = SDL_GetError( );
- if( sdl_error[0] != '\0' ) {
- fprintf(stderr,"SDL ERROR: \"%s\"\n",sdl_error);
- SDL_ClearError();
- }
- // update fps:
- if(tNow>=tLastFps+5000) {
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- tLastFps=tNow;
- frames=0;
- }
- }
- printf("%i frames in %f secs, %f frames per second.\n",frames,(float)(tNow-tLastFps)*0.001f,(float)frames*1000.0f/(float)(tNow-tLastFps));
- // cleanup:
- ZB_close(frameBuffer);
- if(SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ // check for error conditions:
+ char* sdl_error = SDL_GetError();
+ if (sdl_error[0] != '\0') {
+ fprintf(stderr, "SDL ERROR: \"%s\"\n", sdl_error);
+ SDL_ClearError();
+ }
+ // update fps:
+ if (tNow >= tLastFps + 5000) {
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f,
+ (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ tLastFps = tNow;
+ frames = 0;
+ }
+ }
+ printf("%i frames in %f secs, %f frames per second.\n", frames, (float)(tNow - tLastFps) * 0.001f, (float)frames * 1000.0f / (float)(tNow - tLastFps));
+ // cleanup:
+ ZB_close(frameBuffer);
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- mhalt();
- Mix_FreeMusic(myTrack);
- acleanup();
+ mhalt();
+ Mix_FreeMusic(myTrack);
+ acleanup();
#endif
- SDL_Quit();
- return 0;
+ SDL_Quit();
+ return 0;
}
--- /dev/null
+++ b/src/.clang-format
@@ -1,0 +1,118 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 160
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Always
+...
+
--- a/src/api.c
+++ b/src/api.c
@@ -2,679 +2,598 @@
#include <stdio.h>
/* glVertex */
-void glVertex4f(GLfloat x,GLfloat y,GLfloat z,GLfloat w)
-{
- GLParam p[5];
+void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
+ GLParam p[5];
- p[0].op=OP_Vertex;
- p[1].f=x;
- p[2].f=y;
- p[3].f=z;
- p[4].f=w;
+ p[0].op = OP_Vertex;
+ p[1].f = x;
+ p[2].f = y;
+ p[3].f = z;
+ p[4].f = w;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glVertex2f(GLfloat x,GLfloat y)
-{
- glVertex4f(x,y,0,1);
-}
+void glVertex2f(GLfloat x, GLfloat y) { glVertex4f(x, y, 0, 1); }
-void glVertex3f(GLfloat x,GLfloat y,GLfloat z)
-{
- glVertex4f(x,y,z,1);
-}
+void glVertex3f(GLfloat x, GLfloat y, GLfloat z) { glVertex4f(x, y, z, 1); }
-void glVertex3fv(GLfloat *v)
-{
- glVertex4f(v[0],v[1],v[2],1);
-}
+void glVertex3fv(GLfloat* v) { glVertex4f(v[0], v[1], v[2], 1); }
/* glNormal */
-void glNormal3f(GLfloat x,GLfloat y,GLfloat z)
-{
- GLParam p[4];
+void glNormal3f(GLfloat x, GLfloat y, GLfloat z) {
+ GLParam p[4];
- p[0].op=OP_Normal;
- p[1].f=x;
- p[2].f=y;
- p[3].f=z;
+ p[0].op = OP_Normal;
+ p[1].f = x;
+ p[2].f = y;
+ p[3].f = z;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glNormal3fv(GLfloat *v)
-{
- glNormal3f(v[0],v[1],v[2]);
-}
+void glNormal3fv(GLfloat* v) { glNormal3f(v[0], v[1], v[2]); }
/* glColor */
-void glColor4f(GLfloat r,GLfloat g,GLfloat b,GLfloat a)
-{
- GLParam p[8];
+void glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
+ GLParam p[8];
- p[0].op=OP_Color;
- p[1].f=r;
- p[2].f=g;
- p[3].f=b;
- p[4].f=a;
- /* direct convertion to GLinteger to go faster if no shading */
- /*
- p[5].ui = (GLuint) (r * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) +
- ZB_POINT_RED_MIN);
- p[6].ui = (GLuint) (g * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) +
- ZB_POINT_GREEN_MIN);
- p[7].ui = (GLuint) (b * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) +
- ZB_POINT_BLUE_MIN);
- */
- p[5].ui = (((GLuint)(r * 65535)) & 65535);
- p[6].ui = (((GLuint)(g * 65535)) & 65535);
- p[7].ui = (((GLuint)(b * 65535)) & 65535);
- gl_add_op(p);
+ p[0].op = OP_Color;
+ p[1].f = r;
+ p[2].f = g;
+ p[3].f = b;
+ p[4].f = a;
+ /* direct convertion to GLinteger to go faster if no shading */
+ /*
+ p[5].ui = (GLuint) (r * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) +
+ ZB_POINT_RED_MIN);
+ p[6].ui = (GLuint) (g * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) +
+ ZB_POINT_GREEN_MIN);
+ p[7].ui = (GLuint) (b * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) +
+ ZB_POINT_BLUE_MIN);
+ */
+ p[5].ui = (((GLuint)(r * 65535)) & 65535);
+ p[6].ui = (((GLuint)(g * 65535)) & 65535);
+ p[7].ui = (((GLuint)(b * 65535)) & 65535);
+ gl_add_op(p);
}
-void glColor4fv(GLfloat *v)
-{
- GLParam p[8];
+void glColor4fv(GLfloat* v) {
+ GLParam p[8];
- p[0].op=OP_Color;
- p[1].f=v[0];
- p[2].f=v[1];
- p[3].f=v[2];
- p[4].f=v[3];
- /* direct convertion to GLinteger to go faster if no shading */
- /*
- p[5].ui = (GLuint) (v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) +
- ZB_POINT_RED_MIN);
- p[6].ui = (GLuint) (v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) +
- ZB_POINT_GREEN_MIN);
- p[7].ui = (GLuint) (v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) +
- ZB_POINT_BLUE_MIN);
- */
- p[5].ui = (((GLuint)(v[0] * 65535)) & 65535);
- p[6].ui = (((GLuint)(v[1] * 65535)) & 65535);
- p[7].ui = (((GLuint)(v[2] * 65535)) & 65535);
-
- gl_add_op(p);
-}
+ p[0].op = OP_Color;
+ p[1].f = v[0];
+ p[2].f = v[1];
+ p[3].f = v[2];
+ p[4].f = v[3];
+ /* direct convertion to GLinteger to go faster if no shading */
+ /*
+ p[5].ui = (GLuint) (v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) +
+ ZB_POINT_RED_MIN);
+ p[6].ui = (GLuint) (v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) +
+ ZB_POINT_GREEN_MIN);
+ p[7].ui = (GLuint) (v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) +
+ ZB_POINT_BLUE_MIN);
+ */
+ p[5].ui = (((GLuint)(v[0] * 65535)) & 65535);
+ p[6].ui = (((GLuint)(v[1] * 65535)) & 65535);
+ p[7].ui = (((GLuint)(v[2] * 65535)) & 65535);
-void glColor3f(GLfloat x,GLfloat y,GLfloat z)
-{
- glColor4f(x,y,z,1);
+ gl_add_op(p);
}
-void glColor3fv(GLfloat *v)
-{
- glColor4f(v[0],v[1],v[2],1);
-}
+void glColor3f(GLfloat x, GLfloat y, GLfloat z) { glColor4f(x, y, z, 1); }
+void glColor3fv(GLfloat* v) { glColor4f(v[0], v[1], v[2], 1); }
/* TexCoord */
-void glTexCoord4f(GLfloat s,GLfloat t,GLfloat r,GLfloat q)
-{
- GLParam p[5];
+void glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
+ GLParam p[5];
- p[0].op=OP_TexCoord;
- p[1].f=s;
- p[2].f=t;
- p[3].f=r;
- p[4].f=q;
+ p[0].op = OP_TexCoord;
+ p[1].f = s;
+ p[2].f = t;
+ p[3].f = r;
+ p[4].f = q;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glTexCoord2f(GLfloat s,GLfloat t)
-{
- glTexCoord4f(s,t,0,1);
-}
+void glTexCoord2f(GLfloat s, GLfloat t) { glTexCoord4f(s, t, 0, 1); }
-void glTexCoord2fv(GLfloat *v)
-{
- glTexCoord4f(v[0],v[1],0,1);
-}
+void glTexCoord2fv(GLfloat* v) { glTexCoord4f(v[0], v[1], 0, 1); }
-void glEdgeFlag(GLint flag)
-{
- GLParam p[2];
+void glEdgeFlag(GLint flag) {
+ GLParam p[2];
- p[0].op=OP_EdgeFlag;
- p[1].i=flag;
+ p[0].op = OP_EdgeFlag;
+ p[1].i = flag;
- gl_add_op(p);
+ gl_add_op(p);
}
/* misc */
-void glShadeModel(GLint mode)
-{
- GLParam p[2];
+void glShadeModel(GLint mode) {
+ GLParam p[2];
- assert(mode == GL_FLAT || mode == GL_SMOOTH);
+ assert(mode == GL_FLAT || mode == GL_SMOOTH);
- p[0].op=OP_ShadeModel;
- p[1].i=mode;
+ p[0].op = OP_ShadeModel;
+ p[1].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glCullFace(GLint mode)
-{
- GLParam p[2];
+void glCullFace(GLint mode) {
+ GLParam p[2];
- assert(mode == GL_BACK ||
- mode == GL_FRONT ||
- mode == GL_FRONT_AND_BACK);
+ assert(mode == GL_BACK || mode == GL_FRONT || mode == GL_FRONT_AND_BACK);
- p[0].op=OP_CullFace;
- p[1].i=mode;
+ p[0].op = OP_CullFace;
+ p[1].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glFrontFace(GLint mode)
-{
- GLParam p[2];
+void glFrontFace(GLint mode) {
+ GLParam p[2];
- assert(mode == GL_CCW || mode == GL_CW);
+ assert(mode == GL_CCW || mode == GL_CW);
- mode = (mode != GL_CCW);
+ mode = (mode != GL_CCW);
- p[0].op=OP_FrontFace;
- p[1].i=mode;
+ p[0].op = OP_FrontFace;
+ p[1].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glPolygonMode(GLint face,GLint mode)
-{
- GLParam p[3];
+void glPolygonMode(GLint face, GLint mode) {
+ GLParam p[3];
- assert(face == GL_BACK ||
- face == GL_FRONT ||
- face == GL_FRONT_AND_BACK);
- assert(mode == GL_POINT || mode == GL_LINE || mode==GL_FILL);
+ assert(face == GL_BACK || face == GL_FRONT || face == GL_FRONT_AND_BACK);
+ assert(mode == GL_POINT || mode == GL_LINE || mode == GL_FILL);
- p[0].op=OP_PolygonMode;
- p[1].i=face;
- p[2].i=mode;
+ p[0].op = OP_PolygonMode;
+ p[1].i = face;
+ p[2].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-
/* glEnable / glDisable */
-void glEnable(GLint cap)
-{
- GLParam p[3];
+void glEnable(GLint cap) {
+ GLParam p[3];
- p[0].op=OP_EnableDisable;
- p[1].i=cap;
- p[2].i=1;
+ p[0].op = OP_EnableDisable;
+ p[1].i = cap;
+ p[2].i = 1;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glDisable(GLint cap)
-{
- GLParam p[3];
+void glDisable(GLint cap) {
+ GLParam p[3];
- p[0].op=OP_EnableDisable;
- p[1].i=cap;
- p[2].i=0;
+ p[0].op = OP_EnableDisable;
+ p[1].i = cap;
+ p[2].i = 0;
- gl_add_op(p);
+ gl_add_op(p);
}
/* glBegin / glEnd */
-void glBegin(GLint mode)
-{
- GLParam p[2];
+void glBegin(GLint mode) {
+ GLParam p[2];
- p[0].op=OP_Begin;
- p[1].i=mode;
+ p[0].op = OP_Begin;
+ p[1].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glEnd(void)
-{
- GLParam p[1];
+void glEnd(void) {
+ GLParam p[1];
- p[0].op=OP_End;
+ p[0].op = OP_End;
- gl_add_op(p);
+ gl_add_op(p);
}
/* matrix */
-void glMatrixMode(GLint mode)
-{
- GLParam p[2];
+void glMatrixMode(GLint mode) {
+ GLParam p[2];
- p[0].op=OP_MatrixMode;
- p[1].i=mode;
+ p[0].op = OP_MatrixMode;
+ p[1].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glLoadMatrixf(const GLfloat *m)
-{
- GLParam p[17];
- GLint i;
+void glLoadMatrixf(const GLfloat* m) {
+ GLParam p[17];
+ GLint i;
- p[0].op=OP_LoadMatrix;
- for(i=0;i<16;i++) p[i+1].f=m[i];
+ p[0].op = OP_LoadMatrix;
+ for (i = 0; i < 16; i++)
+ p[i + 1].f = m[i];
- gl_add_op(p);
+ gl_add_op(p);
}
-void glLoadIdentity(void)
-{
- GLParam p[1];
+void glLoadIdentity(void) {
+ GLParam p[1];
- p[0].op=OP_LoadIdentity;
+ p[0].op = OP_LoadIdentity;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glMultMatrixf(const GLfloat *m)
-{
- GLParam p[17];
- GLint i;
+void glMultMatrixf(const GLfloat* m) {
+ GLParam p[17];
+ GLint i;
- p[0].op=OP_MultMatrix;
- for(i=0;i<16;i++) p[i+1].f=m[i];
+ p[0].op = OP_MultMatrix;
+ for (i = 0; i < 16; i++)
+ p[i + 1].f = m[i];
- gl_add_op(p);
+ gl_add_op(p);
}
-void glPushMatrix(void)
-{
- GLParam p[1];
+void glPushMatrix(void) {
+ GLParam p[1];
- p[0].op=OP_PushMatrix;
+ p[0].op = OP_PushMatrix;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glPopMatrix(void)
-{
- GLParam p[1];
+void glPopMatrix(void) {
+ GLParam p[1];
- p[0].op=OP_PopMatrix;
+ p[0].op = OP_PopMatrix;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glRotatef(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)
-{
- GLParam p[5];
+void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
+ GLParam p[5];
- p[0].op=OP_Rotate;
- p[1].f=angle;
- p[2].f=x;
- p[3].f=y;
- p[4].f=z;
+ p[0].op = OP_Rotate;
+ p[1].f = angle;
+ p[2].f = x;
+ p[3].f = y;
+ p[4].f = z;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glTranslatef(GLfloat x,GLfloat y,GLfloat z)
-{
- GLParam p[4];
+void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
+ GLParam p[4];
- p[0].op=OP_Translate;
- p[1].f=x;
- p[2].f=y;
- p[3].f=z;
+ p[0].op = OP_Translate;
+ p[1].f = x;
+ p[2].f = y;
+ p[3].f = z;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glScalef(GLfloat x,GLfloat y,GLfloat z)
-{
- GLParam p[4];
+void glScalef(GLfloat x, GLfloat y, GLfloat z) {
+ GLParam p[4];
- p[0].op=OP_Scale;
- p[1].f=x;
- p[2].f=y;
- p[3].f=z;
+ p[0].op = OP_Scale;
+ p[1].f = x;
+ p[2].f = y;
+ p[3].f = z;
- gl_add_op(p);
+ gl_add_op(p);
}
+void glViewport(GLint x, GLint y, GLint width, GLint height) {
+ GLParam p[5];
-void glViewport(GLint x,GLint y,GLint width,GLint height)
-{
- GLParam p[5];
+ p[0].op = OP_Viewport;
+ p[1].i = x;
+ p[2].i = y;
+ p[3].i = width;
+ p[4].i = height;
- p[0].op=OP_Viewport;
- p[1].i=x;
- p[2].i=y;
- p[3].i=width;
- p[4].i=height;
-
- gl_add_op(p);
+ gl_add_op(p);
}
-void glFrustum(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,
- GLdouble near,GLdouble farv)
-{
- GLParam p[7];
+void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble farv) {
+ GLParam p[7];
- p[0].op=OP_Frustum;
- p[1].f=left;
- p[2].f=right;
- p[3].f=bottom;
- p[4].f=top;
- p[5].f=near;
- p[6].f=farv;
+ p[0].op = OP_Frustum;
+ p[1].f = left;
+ p[2].f = right;
+ p[3].f = bottom;
+ p[4].f = top;
+ p[5].f = near;
+ p[6].f = farv;
- gl_add_op(p);
+ gl_add_op(p);
}
/* lightening */
-void glMaterialfv(GLint mode,GLint type,GLfloat *v)
-{
- GLParam p[7];
- GLint i,n;
+void glMaterialfv(GLint mode, GLint type, GLfloat* v) {
+ GLParam p[7];
+ GLint i, n;
- assert(mode == GL_FRONT || mode == GL_BACK || mode==GL_FRONT_AND_BACK);
+ assert(mode == GL_FRONT || mode == GL_BACK || mode == GL_FRONT_AND_BACK);
- p[0].op=OP_Material;
- p[1].i=mode;
- p[2].i=type;
- n=4;
- if (type == GL_SHININESS) n=1;
- for(i=0;i<4;i++) p[3+i].f=v[i];
- for(i=n;i<4;i++) p[3+i].f=0;
+ p[0].op = OP_Material;
+ p[1].i = mode;
+ p[2].i = type;
+ n = 4;
+ if (type == GL_SHININESS)
+ n = 1;
+ for (i = 0; i < 4; i++)
+ p[3 + i].f = v[i];
+ for (i = n; i < 4; i++)
+ p[3 + i].f = 0;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glMaterialf(GLint mode,GLint type,GLfloat v)
-{
- GLParam p[7];
- GLint i;
+void glMaterialf(GLint mode, GLint type, GLfloat v) {
+ GLParam p[7];
+ GLint i;
- p[0].op=OP_Material;
- p[1].i=mode;
- p[2].i=type;
- p[3].f=v;
- for(i=0;i<3;i++) p[4+i].f=0;
+ p[0].op = OP_Material;
+ p[1].i = mode;
+ p[2].i = type;
+ p[3].f = v;
+ for (i = 0; i < 3; i++)
+ p[4 + i].f = 0;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glColorMaterial(GLint mode,GLint type)
-{
- GLParam p[3];
+void glColorMaterial(GLint mode, GLint type) {
+ GLParam p[3];
- p[0].op=OP_ColorMaterial;
- p[1].i=mode;
- p[2].i=type;
+ p[0].op = OP_ColorMaterial;
+ p[1].i = mode;
+ p[2].i = type;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glLightfv(GLint light,GLint type,GLfloat *v)
-{
- GLParam p[7];
- GLint i;
+void glLightfv(GLint light, GLint type, GLfloat* v) {
+ GLParam p[7];
+ GLint i;
- p[0].op=OP_Light;
- p[1].i=light;
- p[2].i=type;
- /* TODO: 3 composants ? */
- for(i=0;i<4;i++) p[3+i].f=v[i];
+ p[0].op = OP_Light;
+ p[1].i = light;
+ p[2].i = type;
+ /* TODO: 3 composants ? */
+ for (i = 0; i < 4; i++)
+ p[3 + i].f = v[i];
- gl_add_op(p);
+ gl_add_op(p);
}
+void glLightf(GLint light, GLint type, GLfloat v) {
+ GLParam p[7];
+ GLint i;
-void glLightf(GLint light,GLint type,GLfloat v)
-{
- GLParam p[7];
- GLint i;
+ p[0].op = OP_Light;
+ p[1].i = light;
+ p[2].i = type;
+ p[3].f = v;
+ for (i = 0; i < 3; i++)
+ p[4 + i].f = 0;
- p[0].op=OP_Light;
- p[1].i=light;
- p[2].i=type;
- p[3].f=v;
- for(i=0;i<3;i++) p[4+i].f=0;
-
- gl_add_op(p);
+ gl_add_op(p);
}
-void glLightModeli(GLint pname,GLint param)
-{
- GLParam p[6];
+void glLightModeli(GLint pname, GLint param) {
+ GLParam p[6];
- p[0].op=OP_LightModel;
- p[1].i=pname;
- p[2].f=(GLfloat)param;
-// for(i=0;i<4;i++) p[3+i].f=0;
-// for(i=0;i<3;i++) p[3+i].f=0;
- p[3].f=0;
- p[4].f=0;
- p[5].f=0;
- gl_add_op(p);
+ p[0].op = OP_LightModel;
+ p[1].i = pname;
+ p[2].f = (GLfloat)param;
+ // for(i=0;i<4;i++) p[3+i].f=0;
+ // for(i=0;i<3;i++) p[3+i].f=0;
+ p[3].f = 0;
+ p[4].f = 0;
+ p[5].f = 0;
+ gl_add_op(p);
}
-void glLightModelfv(GLint pname,GLfloat *param)
-{
- GLParam p[6];
- GLint i;
+void glLightModelfv(GLint pname, GLfloat* param) {
+ GLParam p[6];
+ GLint i;
- p[0].op=OP_LightModel;
- p[1].i=pname;
- for(i=0;i<4;i++) p[2+i].f=param[i];
+ p[0].op = OP_LightModel;
+ p[1].i = pname;
+ for (i = 0; i < 4; i++)
+ p[2 + i].f = param[i];
- gl_add_op(p);
+ gl_add_op(p);
}
/* clear */
-void glClear(GLint mask)
-{
- GLParam p[2];
+void glClear(GLint mask) {
+ GLParam p[2];
- p[0].op=OP_Clear;
- p[1].i=mask;
+ p[0].op = OP_Clear;
+ p[1].i = mask;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glClearColor(GLfloat r,GLfloat g,GLfloat b,GLfloat a)
-{
- GLParam p[5];
+void glClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
+ GLParam p[5];
- p[0].op=OP_ClearColor;
- p[1].f=r;
- p[2].f=g;
- p[3].f=b;
- p[4].f=a;
+ p[0].op = OP_ClearColor;
+ p[1].f = r;
+ p[2].f = g;
+ p[3].f = b;
+ p[4].f = a;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glClearDepth(GLdouble depth)
-{
- GLParam p[2];
+void glClearDepth(GLdouble depth) {
+ GLParam p[2];
- p[0].op=OP_ClearDepth;
- p[1].f=depth;
+ p[0].op = OP_ClearDepth;
+ p[1].f = depth;
- gl_add_op(p);
+ gl_add_op(p);
}
-
/* textures */
-void glTexImage2D( GLint target, GLint level, GLint components,
- GLint width, GLint height, GLint border,
- GLint format, GLint type, void *pixels)
-{
- GLParam p[10];
+void glTexImage2D(GLint target, GLint level, GLint components, GLint width, GLint height, GLint border, GLint format, GLint type, void* pixels) {
+ GLParam p[10];
- p[0].op=OP_TexImage2D;
- p[1].i=target;
- p[2].i=level;
- p[3].i=components;
- p[4].i=width;
- p[5].i=height;
- p[6].i=border;
- p[7].i=format;
- p[8].i=type;
- p[9].p=pixels;
+ p[0].op = OP_TexImage2D;
+ p[1].i = target;
+ p[2].i = level;
+ p[3].i = components;
+ p[4].i = width;
+ p[5].i = height;
+ p[6].i = border;
+ p[7].i = format;
+ p[8].i = type;
+ p[9].p = pixels;
- gl_add_op(p);
+ gl_add_op(p);
}
+void glBindTexture(GLint target, GLint texture) {
+ GLParam p[3];
-void glBindTexture(GLint target,GLint texture)
-{
- GLParam p[3];
+ p[0].op = OP_BindTexture;
+ p[1].i = target;
+ p[2].i = texture;
- p[0].op=OP_BindTexture;
- p[1].i=target;
- p[2].i=texture;
-
- gl_add_op(p);
+ gl_add_op(p);
}
-void glTexEnvi(GLint target,GLint pname,GLint param)
-{
- GLParam p[8];
-
- p[0].op=OP_TexEnv;
- p[1].i=target;
- p[2].i=pname;
- p[3].i=param;
- p[4].f=0;
- p[5].f=0;
- p[6].f=0;
- p[7].f=0;
+void glTexEnvi(GLint target, GLint pname, GLint param) {
+ GLParam p[8];
- gl_add_op(p);
+ p[0].op = OP_TexEnv;
+ p[1].i = target;
+ p[2].i = pname;
+ p[3].i = param;
+ p[4].f = 0;
+ p[5].f = 0;
+ p[6].f = 0;
+ p[7].f = 0;
+
+ gl_add_op(p);
}
-void glTexParameteri(GLint target,GLint pname,GLint param)
-{
- GLParam p[8];
-
- p[0].op=OP_TexParameter;
- p[1].i=target;
- p[2].i=pname;
- p[3].i=param;
- p[4].f=0;
- p[5].f=0;
- p[6].f=0;
- p[7].f=0;
+void glTexParameteri(GLint target, GLint pname, GLint param) {
+ GLParam p[8];
- gl_add_op(p);
+ p[0].op = OP_TexParameter;
+ p[1].i = target;
+ p[2].i = pname;
+ p[3].i = param;
+ p[4].f = 0;
+ p[5].f = 0;
+ p[6].f = 0;
+ p[7].f = 0;
+
+ gl_add_op(p);
}
-void glPixelStorei(GLint pname,GLint param)
-{
- GLParam p[3];
+void glPixelStorei(GLint pname, GLint param) {
+ GLParam p[3];
- p[0].op=OP_PixelStore;
- p[1].i=pname;
- p[2].i=param;
+ p[0].op = OP_PixelStore;
+ p[1].i = pname;
+ p[2].i = param;
- gl_add_op(p);
+ gl_add_op(p);
}
/* selection */
-void glInitNames(void)
-{
- GLParam p[1];
+void glInitNames(void) {
+ GLParam p[1];
- p[0].op=OP_InitNames;
+ p[0].op = OP_InitNames;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glPushName(GLuint name)
-{
- GLParam p[2];
+void glPushName(GLuint name) {
+ GLParam p[2];
- p[0].op=OP_PushName;
- p[1].i=name;
+ p[0].op = OP_PushName;
+ p[1].i = name;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glPopName(void)
-{
- GLParam p[1];
+void glPopName(void) {
+ GLParam p[1];
- p[0].op=OP_PopName;
+ p[0].op = OP_PopName;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glLoadName(GLuint name)
-{
- GLParam p[2];
+void glLoadName(GLuint name) {
+ GLParam p[2];
- p[0].op=OP_LoadName;
- p[1].i=name;
+ p[0].op = OP_LoadName;
+ p[1].i = name;
- gl_add_op(p);
+ gl_add_op(p);
}
-void
-glPolygonOffset(GLfloat factor, GLfloat units)
-{
- GLParam p[3];
- p[0].op = OP_PolygonOffset;
- p[1].f = factor;
- p[2].f = units;
- gl_add_op(p);
+void glPolygonOffset(GLfloat factor, GLfloat units) {
+ GLParam p[3];
+ p[0].op = OP_PolygonOffset;
+ p[1].f = factor;
+ p[2].f = units;
+ gl_add_op(p);
}
/* Special Functions */
-void glCallList(GLuint list)
-{
- GLParam p[2];
+void glCallList(GLuint list) {
+ GLParam p[2];
- p[0].op=OP_CallList;
- p[1].i=list;
+ p[0].op = OP_CallList;
+ p[1].i = list;
- gl_add_op(p);
+ gl_add_op(p);
}
-void glFlush(void)
-{
- /* nothing to do */
-}
+void glFlush(void) { /* nothing to do */ }
-void glHint(GLint target,GLint mode)
-{
- GLParam p[3];
+void glHint(GLint target, GLint mode) {
+ GLParam p[3];
- p[0].op=OP_Hint;
- p[1].i=target;
- p[2].i=mode;
+ p[0].op = OP_Hint;
+ p[1].i = target;
+ p[2].i = mode;
- gl_add_op(p);
+ gl_add_op(p);
}
/* Non standard functions */
-void glDebug(GLint mode)
-{
- GLContext *c=gl_get_context();
- c->print_flag=mode;
+void glDebug(GLint mode) {
+ GLContext* c = gl_get_context();
+ c->print_flag = mode;
}
-
--- a/src/arrays.c
+++ b/src/arrays.c
@@ -2,207 +2,170 @@
#include <assert.h>
#include <stdio.h>
-#define VERTEX_ARRAY 0x0001
-#define COLOR_ARRAY 0x0002
-#define NORMAL_ARRAY 0x0004
+#define VERTEX_ARRAY 0x0001
+#define COLOR_ARRAY 0x0002
+#define NORMAL_ARRAY 0x0004
#define TEXCOORD_ARRAY 0x0008
-void
-glopArrayElement(GLContext *c, GLParam *param)
-{
- GLint i;
- GLint states = c->client_states;
- GLint idx = param[1].i;
-
- if (states & COLOR_ARRAY) {
- GLParam p[5];
- GLint size = c->color_array_size;
- i = idx * (size + c->color_array_stride);
- p[1].f = c->color_array[i];
- p[2].f = c->color_array[i+1];
- p[3].f = c->color_array[i+2];
- p[4].f = size > 3 ? c->color_array[i+3] : 1.0f;
- glopColor(c, p);
- }
- if (states & NORMAL_ARRAY) {
- i = idx * (3 + c->normal_array_stride);
- c->current_normal.X = c->normal_array[i];
- c->current_normal.Y = c->normal_array[i+1];
- c->current_normal.Z = c->normal_array[i+2];
- c->current_normal.Z = 0.0f;
- }
- if (states & TEXCOORD_ARRAY) {
- GLint size = c->texcoord_array_size;
- i = idx * (size + c->texcoord_array_stride);
- c->current_tex_coord.X = c->texcoord_array[i];
- c->current_tex_coord.Y = c->texcoord_array[i+1];
- c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i+2] : 0.0f;
- c->current_tex_coord.W = size > 3 ? c->texcoord_array[i+3] : 1.0f;
- }
- if (states & VERTEX_ARRAY) {
- GLParam p[5];
- GLint size = c->vertex_array_size;
- i = idx * (size + c->vertex_array_stride);
- p[1].f = c->vertex_array[i];
- p[2].f = c->vertex_array[i+1];
- p[3].f = size > 2 ? c->vertex_array[i+2] : 0.0f;
- p[4].f = size > 3 ? c->vertex_array[i+3] : 1.0f;
- glopVertex(c, p);
- }
+void glopArrayElement(GLContext* c, GLParam* param) {
+ GLint i;
+ GLint states = c->client_states;
+ GLint idx = param[1].i;
+
+ if (states & COLOR_ARRAY) {
+ GLParam p[5];
+ GLint size = c->color_array_size;
+ i = idx * (size + c->color_array_stride);
+ p[1].f = c->color_array[i];
+ p[2].f = c->color_array[i + 1];
+ p[3].f = c->color_array[i + 2];
+ p[4].f = size > 3 ? c->color_array[i + 3] : 1.0f;
+ glopColor(c, p);
+ }
+ if (states & NORMAL_ARRAY) {
+ i = idx * (3 + c->normal_array_stride);
+ c->current_normal.X = c->normal_array[i];
+ c->current_normal.Y = c->normal_array[i + 1];
+ c->current_normal.Z = c->normal_array[i + 2];
+ c->current_normal.Z = 0.0f;
+ }
+ if (states & TEXCOORD_ARRAY) {
+ GLint size = c->texcoord_array_size;
+ i = idx * (size + c->texcoord_array_stride);
+ c->current_tex_coord.X = c->texcoord_array[i];
+ c->current_tex_coord.Y = c->texcoord_array[i + 1];
+ c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f;
+ c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
+ }
+ if (states & VERTEX_ARRAY) {
+ GLParam p[5];
+ GLint size = c->vertex_array_size;
+ i = idx * (size + c->vertex_array_stride);
+ p[1].f = c->vertex_array[i];
+ p[2].f = c->vertex_array[i + 1];
+ p[3].f = size > 2 ? c->vertex_array[i + 2] : 0.0f;
+ p[4].f = size > 3 ? c->vertex_array[i + 3] : 1.0f;
+ glopVertex(c, p);
+ }
}
-void
-glArrayElement(GLint i)
-{
- GLParam p[2];
- p[0].op = OP_ArrayElement;
- p[1].i = i;
- gl_add_op(p);
+void glArrayElement(GLint i) {
+ GLParam p[2];
+ p[0].op = OP_ArrayElement;
+ p[1].i = i;
+ gl_add_op(p);
}
+void glopEnableClientState(GLContext* c, GLParam* p) { c->client_states |= p[1].i; }
-void
-glopEnableClientState(GLContext *c, GLParam *p)
-{
- c->client_states |= p[1].i;
-}
+void glEnableClientState(GLenum array) {
+ GLParam p[2];
+ p[0].op = OP_EnableClientState;
-void
-glEnableClientState(GLenum array)
-{
- GLParam p[2];
- p[0].op = OP_EnableClientState;
-
- switch(array) {
- case GL_VERTEX_ARRAY:
- p[1].i = VERTEX_ARRAY;
- break;
- case GL_NORMAL_ARRAY:
- p[1].i = NORMAL_ARRAY;
- break;
- case GL_COLOR_ARRAY:
- p[1].i = COLOR_ARRAY;
- break;
- case GL_TEXTURE_COORD_ARRAY:
- p[1].i = TEXCOORD_ARRAY;
- break;
- default:
- assert(0);
- break;
- }
- gl_add_op(p);
+ switch (array) {
+ case GL_VERTEX_ARRAY:
+ p[1].i = VERTEX_ARRAY;
+ break;
+ case GL_NORMAL_ARRAY:
+ p[1].i = NORMAL_ARRAY;
+ break;
+ case GL_COLOR_ARRAY:
+ p[1].i = COLOR_ARRAY;
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ p[1].i = TEXCOORD_ARRAY;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ gl_add_op(p);
}
-void
-glopDisableClientState(GLContext *c, GLParam *p)
-{
- c->client_states &= p[1].i;
-}
+void glopDisableClientState(GLContext* c, GLParam* p) { c->client_states &= p[1].i; }
-void
-glDisableClientState(GLenum array)
-{
- GLParam p[2];
- p[0].op = OP_DisableClientState;
-
- switch(array) {
- case GL_VERTEX_ARRAY:
- p[1].i = ~VERTEX_ARRAY;
- break;
- case GL_NORMAL_ARRAY:
- p[1].i = ~NORMAL_ARRAY;
- break;
- case GL_COLOR_ARRAY:
- p[1].i = ~COLOR_ARRAY;
- break;
- case GL_TEXTURE_COORD_ARRAY:
- p[1].i = ~TEXCOORD_ARRAY;
- break;
- default:
- assert(0);
- break;
- }
- gl_add_op(p);
+void glDisableClientState(GLenum array) {
+ GLParam p[2];
+ p[0].op = OP_DisableClientState;
+
+ switch (array) {
+ case GL_VERTEX_ARRAY:
+ p[1].i = ~VERTEX_ARRAY;
+ break;
+ case GL_NORMAL_ARRAY:
+ p[1].i = ~NORMAL_ARRAY;
+ break;
+ case GL_COLOR_ARRAY:
+ p[1].i = ~COLOR_ARRAY;
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ p[1].i = ~TEXCOORD_ARRAY;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ gl_add_op(p);
}
-void
-glopVertexPointer(GLContext *c, GLParam *p)
-{
- c->vertex_array_size = p[1].i;
- c->vertex_array_stride = p[2].i;
- c->vertex_array = p[3].p;
+void glopVertexPointer(GLContext* c, GLParam* p) {
+ c->vertex_array_size = p[1].i;
+ c->vertex_array_stride = p[2].i;
+ c->vertex_array = p[3].p;
}
-void
-glVertexPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *pointer)
-{
- GLParam p[4];
- assert(type == GL_FLOAT);
- p[0].op = OP_VertexPointer;
- p[1].i = size;
- p[2].i = stride;
- p[3].p = (void*)pointer;
- gl_add_op(p);
+void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
+ GLParam p[4];
+ assert(type == GL_FLOAT);
+ p[0].op = OP_VertexPointer;
+ p[1].i = size;
+ p[2].i = stride;
+ p[3].p = (void*)pointer;
+ gl_add_op(p);
}
-void
-glopColorPointer(GLContext *c, GLParam *p)
-{
- c->color_array_size = p[1].i;
- c->color_array_stride = p[2].i;
- c->color_array = p[3].p;
+void glopColorPointer(GLContext* c, GLParam* p) {
+ c->color_array_size = p[1].i;
+ c->color_array_stride = p[2].i;
+ c->color_array = p[3].p;
}
-void
-glColorPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *pointer)
-{
- GLParam p[4];
- assert(type == GL_FLOAT);
- p[0].op = OP_ColorPointer;
- p[1].i = size;
- p[2].i = stride;
- p[3].p = (void*)pointer;
- gl_add_op(p);
+void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
+ GLParam p[4];
+ assert(type == GL_FLOAT);
+ p[0].op = OP_ColorPointer;
+ p[1].i = size;
+ p[2].i = stride;
+ p[3].p = (void*)pointer;
+ gl_add_op(p);
}
-void
-glopNormalPointer(GLContext *c, GLParam *p)
-{
- c->normal_array_stride = p[1].i;
- c->normal_array = p[2].p;
+void glopNormalPointer(GLContext* c, GLParam* p) {
+ c->normal_array_stride = p[1].i;
+ c->normal_array = p[2].p;
}
-void
-glNormalPointer(GLenum type, GLsizei stride,
- const GLvoid *pointer)
-{
- GLParam p[3];
- assert(type == GL_FLOAT);
- p[0].op = OP_NormalPointer;
- p[1].i = stride;
- p[2].p = (void*)pointer;
- gl_add_op(p);
+void glNormalPointer(GLenum type, GLsizei stride, const GLvoid* pointer) {
+ GLParam p[3];
+ assert(type == GL_FLOAT);
+ p[0].op = OP_NormalPointer;
+ p[1].i = stride;
+ p[2].p = (void*)pointer;
+ gl_add_op(p);
}
-void
-glopTexCoordPointer(GLContext *c, GLParam *p)
-{
- c->texcoord_array_size = p[1].i;
- c->texcoord_array_stride = p[2].i;
- c->texcoord_array = p[3].p;
+void glopTexCoordPointer(GLContext* c, GLParam* p) {
+ c->texcoord_array_size = p[1].i;
+ c->texcoord_array_stride = p[2].i;
+ c->texcoord_array = p[3].p;
}
-void
-glTexCoordPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *pointer)
-{
- GLParam p[4];
- assert(type == GL_FLOAT);
- p[0].op = OP_TexCoordPointer;
- p[1].i = size;
- p[2].i = stride;
- p[3].p = (void*)pointer;
- gl_add_op(p);
+void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
+ GLParam p[4];
+ assert(type == GL_FLOAT);
+ p[0].op = OP_TexCoordPointer;
+ p[1].i = size;
+ p[2].i = stride;
+ p[3].p = (void*)pointer;
+ gl_add_op(p);
}
--- a/src/clear.c
+++ b/src/clear.c
@@ -1,30 +1,21 @@
#include "zgl.h"
-
-void glopClearColor(GLContext *c,GLParam *p)
-{
- c->clear_color.v[0]=p[1].f;
- c->clear_color.v[1]=p[2].f;
- c->clear_color.v[2]=p[3].f;
- c->clear_color.v[3]=p[4].f;
+void glopClearColor(GLContext* c, GLParam* p) {
+ c->clear_color.v[0] = p[1].f;
+ c->clear_color.v[1] = p[2].f;
+ c->clear_color.v[2] = p[3].f;
+ c->clear_color.v[3] = p[4].f;
}
-void glopClearDepth(GLContext *c,GLParam *p)
-{
- c->clear_depth=p[1].f;
-}
+void glopClearDepth(GLContext* c, GLParam* p) { c->clear_depth = p[1].f; }
+void glopClear(GLContext* c, GLParam* p) {
+ GLint mask = p[1].i;
+ GLint z = 0;
+ GLint r = (GLint)(c->clear_color.v[0] * 65535);
+ GLint g = (GLint)(c->clear_color.v[1] * 65535);
+ GLint b = (GLint)(c->clear_color.v[2] * 65535);
-void glopClear(GLContext *c,GLParam *p)
-{
- GLint mask=p[1].i;
- GLint z=0;
- GLint r=(GLint)(c->clear_color.v[0]*65535);
- GLint g=(GLint)(c->clear_color.v[1]*65535);
- GLint b=(GLint)(c->clear_color.v[2]*65535);
+ /* TODO : correct value of Z */
- /* TODO : correct value of Z */
-
- ZB_clear(c->zb,mask & GL_DEPTH_BUFFER_BIT,z,
- mask & GL_COLOR_BUFFER_BIT,r,g,b);
+ ZB_clear(c->zb, mask & GL_DEPTH_BUFFER_BIT, z, mask & GL_COLOR_BUFFER_BIT, r, g, b);
}
-
--- a/src/clip.c
+++ b/src/clip.c
@@ -3,166 +3,148 @@
/* fill triangle profile */
/* #define PROFILE */
-#define CLIP_XMIN (1<<0)
-#define CLIP_XMAX (1<<1)
-#define CLIP_YMIN (1<<2)
-#define CLIP_YMAX (1<<3)
-#define CLIP_ZMIN (1<<4)
-#define CLIP_ZMAX (1<<5)
+#define CLIP_XMIN (1 << 0)
+#define CLIP_XMAX (1 << 1)
+#define CLIP_YMIN (1 << 2)
+#define CLIP_YMAX (1 << 3)
+#define CLIP_ZMIN (1 << 4)
+#define CLIP_ZMAX (1 << 5)
-void gl_transform_to_viewport(GLContext *c,GLVertex *v)
-{
- GLfloat winv;
+void gl_transform_to_viewport(GLContext* c, GLVertex* v) {
+ GLfloat winv;
- /* coordinates */
- winv=1.0/v->pc.W;
- v->zp.x= (GLint) ( v->pc.X * winv * c->viewport.scale.X
- + c->viewport.trans.X );
- v->zp.y= (GLint) ( v->pc.Y * winv * c->viewport.scale.Y
- + c->viewport.trans.Y );
- v->zp.z= (GLint) ( v->pc.Z * winv * c->viewport.scale.Z
- + c->viewport.trans.Z );
- /* color */
- //if (c->lighting_enabled) {
-
- v->zp.r=(GLuint)(v->color.v[0] * 65535) & 65535;
- v->zp.g=(GLuint)(v->color.v[1] * 65535) & 65535;
- v->zp.b=(GLuint)(v->color.v[2] * 65535) & 65535;
+ /* coordinates */
+ winv = 1.0 / v->pc.W;
+ v->zp.x = (GLint)(v->pc.X * winv * c->viewport.scale.X + c->viewport.trans.X);
+ v->zp.y = (GLint)(v->pc.Y * winv * c->viewport.scale.Y + c->viewport.trans.Y);
+ v->zp.z = (GLint)(v->pc.Z * winv * c->viewport.scale.Z + c->viewport.trans.Z);
+ /* color */
+ v->zp.r = (GLuint)(v->color.v[0] * 65535) & 65535;
+ v->zp.g = (GLuint)(v->color.v[1] * 65535) & 65535;
+ v->zp.b = (GLuint)(v->color.v[2] * 65535) & 65535;
- //} else {
- //printf("\nRECEIVED COLOR %f, %f, %f, %f", v->color.v[0], v->color.v[1], v->color.v[2], v->color.v[3]);
- // v->zp.r=(GLuint)(v->color.v[0] * 65535) & 65535;
- // v->zp.g=(GLuint)(v->color.v[1] * 65535) & 65535;
- // v->zp.b=(GLuint)(v->color.v[2] * 65535) & 65535;
- //printf("\nCOLORS ARE %d, %d, %d", v->zp.r,v->zp.g,v->zp.b);
- // }
-
- /* texture */
+ /* texture */
- if (c->texture_2d_enabled) {
- v->zp.s=(GLint)(v->tex_coord.X * (ZB_POINT_S_MAX - ZB_POINT_S_MIN)
- + ZB_POINT_S_MIN);
- v->zp.t=(GLint)(v->tex_coord.Y * (ZB_POINT_T_MAX - ZB_POINT_T_MIN)
- + ZB_POINT_T_MIN);
- }
+ if (c->texture_2d_enabled) {
+ v->zp.s = (GLint)(v->tex_coord.X * (ZB_POINT_S_MAX - ZB_POINT_S_MIN) + ZB_POINT_S_MIN);
+ v->zp.t = (GLint)(v->tex_coord.Y * (ZB_POINT_T_MAX - ZB_POINT_T_MIN) + ZB_POINT_T_MIN);
+ }
}
+static void gl_add_select1(GLContext* c, GLint z1, GLint z2, GLint z3) {
+ GLuint min, max;
+ min = max = z1;
+ if (z2 < min)
+ min = z2;
+ if (z3 < min)
+ min = z3;
+ if (z2 > max)
+ max = z2;
+ if (z3 > max)
+ max = z3;
-static void gl_add_select1(GLContext *c,GLint z1,GLint z2,GLint z3)
-{
- GLuint min,max;
- min=max=z1;
- if (z2<min) min=z2;
- if (z3<min) min=z3;
- if (z2>max) max=z2;
- if (z3>max) max=z3;
-
- gl_add_select(c,0xffffffff-min,0xffffffff-max);
+ gl_add_select(c, 0xffffffff - min, 0xffffffff - max);
}
/* point */
-void gl_draw_point(GLContext *c,GLVertex *p0)
-{
- if (p0->clip_code == 0) {
- if (c->render_mode == GL_SELECT) {
- gl_add_select(c,p0->zp.z,p0->zp.z);
- } else {
- ZB_plot(c->zb,&p0->zp);
- }
- }
+void gl_draw_point(GLContext* c, GLVertex* p0) {
+ if (p0->clip_code == 0) {
+ if (c->render_mode == GL_SELECT) {
+ gl_add_select(c, p0->zp.z, p0->zp.z);
+ } else {
+ ZB_plot(c->zb, &p0->zp);
+ }
+ }
}
/* line */
-static inline void GLinterpolate(GLVertex *q,GLVertex *p0,GLVertex *p1,GLfloat t)
-{
- q->pc.X=p0->pc.X+(p1->pc.X-p0->pc.X)*t;
- q->pc.Y=p0->pc.Y+(p1->pc.Y-p0->pc.Y)*t;
- q->pc.Z=p0->pc.Z+(p1->pc.Z-p0->pc.Z)*t;
- q->pc.W=p0->pc.W+(p1->pc.W-p0->pc.W)*t;
+static inline void GLinterpolate(GLVertex* q, GLVertex* p0, GLVertex* p1, GLfloat t) {
+ q->pc.X = p0->pc.X + (p1->pc.X - p0->pc.X) * t;
+ q->pc.Y = p0->pc.Y + (p1->pc.Y - p0->pc.Y) * t;
+ q->pc.Z = p0->pc.Z + (p1->pc.Z - p0->pc.Z) * t;
+ q->pc.W = p0->pc.W + (p1->pc.W - p0->pc.W) * t;
- q->color.v[0]=p0->color.v[0] + (p1->color.v[0]-p0->color.v[0])*t;
- q->color.v[1]=p0->color.v[1] + (p1->color.v[1]-p0->color.v[1])*t;
- q->color.v[2]=p0->color.v[2] + (p1->color.v[2]-p0->color.v[2])*t;
+ q->color.v[0] = p0->color.v[0] + (p1->color.v[0] - p0->color.v[0]) * t;
+ q->color.v[1] = p0->color.v[1] + (p1->color.v[1] - p0->color.v[1]) * t;
+ q->color.v[2] = p0->color.v[2] + (p1->color.v[2] - p0->color.v[2]) * t;
}
/*
- * Line Clipping
+ * Line Clipping
*/
/* Line Clipping algorithm from 'Computer Graphics', Principles and
Practice */
-static inline GLint ClipLine1(GLfloat denom,GLfloat num,GLfloat *tmin,GLfloat *tmax)
-{
- GLfloat t;
-
- if (denom>0) {
- t=num/denom;
- if (t>*tmax) return 0;
- if (t>*tmin) *tmin=t;
- } else if (denom<0) {
- t=num/denom;
- if (t<*tmin) return 0;
- if (t<*tmax) *tmax=t;
- } else if (num>0) return 0;
- return 1;
+static inline GLint ClipLine1(GLfloat denom, GLfloat num, GLfloat* tmin, GLfloat* tmax) {
+ GLfloat t;
+
+ if (denom > 0) {
+ t = num / denom;
+ if (t > *tmax)
+ return 0;
+ if (t > *tmin)
+ *tmin = t;
+ } else if (denom < 0) {
+ t = num / denom;
+ if (t < *tmin)
+ return 0;
+ if (t < *tmax)
+ *tmax = t;
+ } else if (num > 0)
+ return 0;
+ return 1;
}
-void gl_draw_line(GLContext *c,GLVertex *p1,GLVertex *p2)
-{
- GLfloat dx,dy,dz,dw,x1,y1,z1,w1;
- GLfloat tmin,tmax;
- GLVertex q1,q2;
- GLint cc1,cc2;
-
- cc1=p1->clip_code;
- cc2=p2->clip_code;
+void gl_draw_line(GLContext* c, GLVertex* p1, GLVertex* p2) {
+ GLfloat dx, dy, dz, dw, x1, y1, z1, w1;
+ GLfloat tmin, tmax;
+ GLVertex q1, q2;
+ GLint cc1, cc2;
- if ( (cc1 | cc2) == 0) {
- if (c->render_mode == GL_SELECT) {
- gl_add_select1(c,p1->zp.z,p2->zp.z,p2->zp.z);
- } else {
- if (c->depth_test)
- ZB_line_z(c->zb,&p1->zp,&p2->zp);
- else
- ZB_line(c->zb,&p1->zp,&p2->zp);
- }
- } else if ( (cc1&cc2) != 0 ) {
- return;
- } else {
- dx=p2->pc.X-p1->pc.X;
- dy=p2->pc.Y-p1->pc.Y;
- dz=p2->pc.Z-p1->pc.Z;
- dw=p2->pc.W-p1->pc.W;
- x1=p1->pc.X;
- y1=p1->pc.Y;
- z1=p1->pc.Z;
- w1=p1->pc.W;
-
- tmin=0;
- tmax=1;
- if (ClipLine1(dx+dw,-x1-w1,&tmin,&tmax) &&
- ClipLine1(-dx+dw,x1-w1,&tmin,&tmax) &&
- ClipLine1(dy+dw,-y1-w1,&tmin,&tmax) &&
- ClipLine1(-dy+dw,y1-w1,&tmin,&tmax) &&
- ClipLine1(dz+dw,-z1-w1,&tmin,&tmax) &&
- ClipLine1(-dz+dw,z1-w1,&tmin,&tmax)) {
+ cc1 = p1->clip_code;
+ cc2 = p2->clip_code;
- GLinterpolate(&q1,p1,p2,tmin);
- GLinterpolate(&q2,p1,p2,tmax);
- gl_transform_to_viewport(c,&q1);
- gl_transform_to_viewport(c,&q2);
+ if ((cc1 | cc2) == 0) {
+ if (c->render_mode == GL_SELECT) {
+ gl_add_select1(c, p1->zp.z, p2->zp.z, p2->zp.z);
+ } else {
+ if (c->depth_test)
+ ZB_line_z(c->zb, &p1->zp, &p2->zp);
+ else
+ ZB_line(c->zb, &p1->zp, &p2->zp);
+ }
+ } else if ((cc1 & cc2) != 0) {
+ return;
+ } else {
+ dx = p2->pc.X - p1->pc.X;
+ dy = p2->pc.Y - p1->pc.Y;
+ dz = p2->pc.Z - p1->pc.Z;
+ dw = p2->pc.W - p1->pc.W;
+ x1 = p1->pc.X;
+ y1 = p1->pc.Y;
+ z1 = p1->pc.Z;
+ w1 = p1->pc.W;
- if (c->depth_test)
- ZB_line_z(c->zb,&q1.zp,&q2.zp);
- else
- ZB_line(c->zb,&q1.zp,&q2.zp);
- }
- }
+ tmin = 0;
+ tmax = 1;
+ if (ClipLine1(dx + dw, -x1 - w1, &tmin, &tmax) && ClipLine1(-dx + dw, x1 - w1, &tmin, &tmax) && ClipLine1(dy + dw, -y1 - w1, &tmin, &tmax) &&
+ ClipLine1(-dy + dw, y1 - w1, &tmin, &tmax) && ClipLine1(dz + dw, -z1 - w1, &tmin, &tmax) && ClipLine1(-dz + dw, z1 - w1, &tmin, &tmax)) {
+
+ GLinterpolate(&q1, p1, p2, tmin);
+ GLinterpolate(&q2, p1, p2, tmax);
+ gl_transform_to_viewport(c, &q1);
+ gl_transform_to_viewport(c, &q2);
+
+ if (c->depth_test)
+ ZB_line_z(c->zb, &q1.zp, &q2.zp);
+ else
+ ZB_line(c->zb, &q1.zp, &q2.zp);
+ }
+ }
}
-
/* triangle */
/*
@@ -171,162 +153,153 @@
/* We clip the segment [a,b] against the 6 planes of the normal volume.
* We compute the point 'c' of GLintersection and the value of the parameter 't'
- * of the GLintersection if x=a+t(b-a).
+ * of the GLintersection if x=a+t(b-a).
*/
-
-#define clip_func(name,sign,dir,dir1,dir2) \
-static GLfloat name(V4 *c,V4 *a,V4 *b) \
-{\
- GLfloat t,dX,dY,dZ,dW,den;\
- dX = (b->X - a->X);\
- dY = (b->Y - a->Y);\
- dZ = (b->Z - a->Z);\
- dW = (b->W - a->W);\
- den = -(sign d ## dir) + dW;\
- if (den == 0) t=0;\
- else t = ( sign a->dir - a->W) / den;\
- c->dir1 = a->dir1 + t * d ## dir1;\
- c->dir2 = a->dir2 + t * d ## dir2;\
- c->W = a->W + t * dW;\
- c->dir = sign c->W;\
- return t;\
-}
+#define clip_func(name, sign, dir, dir1, dir2) \
+ static GLfloat name(V4* c, V4* a, V4* b) { \
+ GLfloat t, dX, dY, dZ, dW, den; \
+ dX = (b->X - a->X); \
+ dY = (b->Y - a->Y); \
+ dZ = (b->Z - a->Z); \
+ dW = (b->W - a->W); \
+ den = -(sign d##dir) + dW; \
+ if (den == 0) \
+ t = 0; \
+ else \
+ t = (sign a->dir - a->W) / den; \
+ c->dir1 = a->dir1 + t * d##dir1; \
+ c->dir2 = a->dir2 + t * d##dir2; \
+ c->W = a->W + t * dW; \
+ c->dir = sign c->W; \
+ return t; \
+ }
-clip_func(clip_xmin,-,X,Y,Z)
+clip_func(clip_xmin, -, X, Y, Z)
-clip_func(clip_xmax,+,X,Y,Z)
+ clip_func(clip_xmax, +, X, Y, Z)
-clip_func(clip_ymin,-,Y,X,Z)
+ clip_func(clip_ymin, -, Y, X, Z)
-clip_func(clip_ymax,+,Y,X,Z)
+ clip_func(clip_ymax, +, Y, X, Z)
-clip_func(clip_zmin,-,Z,X,Y)
+ clip_func(clip_zmin, -, Z, X, Y)
-clip_func(clip_zmax,+,Z,X,Y)
+ clip_func(clip_zmax, +, Z, X, Y)
+ GLfloat (*clip_proc[6])(V4*, V4*, V4*) = {clip_xmin, clip_xmax, clip_ymin, clip_ymax, clip_zmin, clip_zmax};
-GLfloat (*clip_proc[6])(V4 *,V4 *,V4 *)= {
- clip_xmin,clip_xmax,
- clip_ymin,clip_ymax,
- clip_zmin,clip_zmax
-};
-
-static inline void updateTmp(GLContext *c,
- GLVertex *q,GLVertex *p0,GLVertex *p1,GLfloat t)
-{
- if (c->current_shade_model == GL_SMOOTH) {
- q->color.v[0]=p0->color.v[0] + (p1->color.v[0] - p0->color.v[0])*t;
- q->color.v[1]=p0->color.v[1] + (p1->color.v[1] - p0->color.v[1])*t;
- q->color.v[2]=p0->color.v[2] + (p1->color.v[2] - p0->color.v[2])*t;
- q->zp.r = p0->zp.r + (p1->zp.r - p0->zp.r)*t;
- q->zp.g = p0->zp.g + (p1->zp.g - p0->zp.g)*t;
- q->zp.b = p0->zp.b + (p1->zp.b - p0->zp.b)*t;
- //q->color.v[3]=p0->color.v[3] + (p1->color.v[3] - p0->color.v[3])*t;
- //printf("\np0 Components are %f, %f, %f", p0->color.v[0], p0->color.v[1], p0->color.v[2]);
- //printf("\nZbuffer point r,g,b for p0 are: %d %d %d",p0->zp.r, p0->zp.g,p0->zp.b);
- //printf("\n~\nNew Components are %f, %f, %f", q->color.v[0], q->color.v[1], q->color.v[2]);
- //printf("\nZbuffer point r,g,b for new point are: %d %d %d",q->zp.r, q->zp.g,q->zp.b);
- /// *
- } else {
- q->color.v[0]=p0->color.v[0];
- q->color.v[1]=p0->color.v[1];
- q->color.v[2]=p0->color.v[2];
- q->zp.r = p0->zp.r;
- q->zp.g = p0->zp.g;
- q->zp.b = p0->zp.b;
- }
+static inline void updateTmp(GLContext* c, GLVertex* q, GLVertex* p0, GLVertex* p1, GLfloat t) {
+ if (c->current_shade_model == GL_SMOOTH) {
+ q->color.v[0] = p0->color.v[0] + (p1->color.v[0] - p0->color.v[0]) * t;
+ q->color.v[1] = p0->color.v[1] + (p1->color.v[1] - p0->color.v[1]) * t;
+ q->color.v[2] = p0->color.v[2] + (p1->color.v[2] - p0->color.v[2]) * t;
+ q->zp.r = p0->zp.r + (p1->zp.r - p0->zp.r) * t;
+ q->zp.g = p0->zp.g + (p1->zp.g - p0->zp.g) * t;
+ q->zp.b = p0->zp.b + (p1->zp.b - p0->zp.b) * t;
+ // q->color.v[3]=p0->color.v[3] + (p1->color.v[3] - p0->color.v[3])*t;
+ // printf("\np0 Components are %f, %f, %f", p0->color.v[0], p0->color.v[1], p0->color.v[2]);
+ // printf("\nZbuffer point r,g,b for p0 are: %d %d %d",p0->zp.r, p0->zp.g,p0->zp.b);
+ // printf("\n~\nNew Components are %f, %f, %f", q->color.v[0], q->color.v[1], q->color.v[2]);
+ // printf("\nZbuffer point r,g,b for new point are: %d %d %d",q->zp.r, q->zp.g,q->zp.b);
+ /// *
+ } else {
+ q->color.v[0] = p0->color.v[0];
+ q->color.v[1] = p0->color.v[1];
+ q->color.v[2] = p0->color.v[2];
+ q->zp.r = p0->zp.r;
+ q->zp.g = p0->zp.g;
+ q->zp.b = p0->zp.b;
+ }
// */
- if (c->texture_2d_enabled) {
- q->tex_coord.X = p0->tex_coord.X + (p1->tex_coord.X-p0->tex_coord.X)*t;
- q->tex_coord.Y = p0->tex_coord.Y + (p1->tex_coord.Y-p0->tex_coord.Y)*t;
- }
+ if (c->texture_2d_enabled) {
+ q->tex_coord.X = p0->tex_coord.X + (p1->tex_coord.X - p0->tex_coord.X) * t;
+ q->tex_coord.Y = p0->tex_coord.Y + (p1->tex_coord.Y - p0->tex_coord.Y) * t;
+ }
- q->clip_code=gl_clipcode(q->pc.X,q->pc.Y,q->pc.Z,q->pc.W);
- if (q->clip_code==0)
- gl_transform_to_viewport(c,q);
+ q->clip_code = gl_clipcode(q->pc.X, q->pc.Y, q->pc.Z, q->pc.W);
+ if (q->clip_code == 0)
+ gl_transform_to_viewport(c, q);
}
-static void gl_draw_triangle_clip(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2,GLint clip_bit);
+static void gl_draw_triangle_clip(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit);
-void gl_draw_triangle(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2)
-{
- GLint co,c_and,cc[3],front;
- GLfloat norm;
-
- cc[0]=p0->clip_code;
- cc[1]=p1->clip_code;
- cc[2]=p2->clip_code;
-
- co=cc[0] | cc[1] | cc[2];
+void gl_draw_triangle(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+ GLint co, c_and, cc[3], front;
+ GLfloat norm;
- /* we handle the non clipped case here to go faster */
- if (co==0) {
-
- norm=(GLfloat)(p1->zp.x-p0->zp.x)*(GLfloat)(p2->zp.y-p0->zp.y)-
- (GLfloat)(p2->zp.x-p0->zp.x)*(GLfloat)(p1->zp.y-p0->zp.y);
-
- if (norm == 0) return;
+ cc[0] = p0->clip_code;
+ cc[1] = p1->clip_code;
+ cc[2] = p2->clip_code;
- front = norm < 0.0;
- front = front ^ c->current_front_face;
-
- /* back face culling */
- if (c->cull_face_enabled) {
- /* most used case first */
- if (c->current_cull_face == GL_BACK) {
- if (front == 0) return;
- c->draw_triangle_front(c,p0,p1,p2);
- } else if (c->current_cull_face == GL_FRONT) {
- if (front != 0) return;
- c->draw_triangle_back(c,p0,p1,p2);
- } else {
- return;
- }
- } else {
- /* no culling */
- if (front) {
- c->draw_triangle_front(c,p0,p1,p2);
- } else {
- c->draw_triangle_back(c,p0,p1,p2);
- }
- }
- } else {
- c_and=cc[0] & cc[1] & cc[2];
- if (c_and==0) { //Don't draw a triangle with no points
- gl_draw_triangle_clip(c,p0,p1,p2,0);
- }
- }
+ co = cc[0] | cc[1] | cc[2];
+
+ /* we handle the non clipped case here to go faster */
+ if (co == 0) {
+
+ norm = (GLfloat)(p1->zp.x - p0->zp.x) * (GLfloat)(p2->zp.y - p0->zp.y) - (GLfloat)(p2->zp.x - p0->zp.x) * (GLfloat)(p1->zp.y - p0->zp.y);
+
+ if (norm == 0)
+ return;
+
+ front = norm < 0.0;
+ front = front ^ c->current_front_face;
+
+ /* back face culling */
+ if (c->cull_face_enabled) {
+ /* most used case first */
+ if (c->current_cull_face == GL_BACK) {
+ if (front == 0)
+ return;
+ c->draw_triangle_front(c, p0, p1, p2);
+ } else if (c->current_cull_face == GL_FRONT) {
+ if (front != 0)
+ return;
+ c->draw_triangle_back(c, p0, p1, p2);
+ } else {
+ return;
+ }
+ } else {
+ /* no culling */
+ if (front) {
+ c->draw_triangle_front(c, p0, p1, p2);
+ } else {
+ c->draw_triangle_back(c, p0, p1, p2);
+ }
+ }
+ } else {
+ c_and = cc[0] & cc[1] & cc[2];
+ if (c_and == 0) { // Don't draw a triangle with no points
+ gl_draw_triangle_clip(c, p0, p1, p2, 0);
+ }
+ }
}
-static void gl_draw_triangle_clip(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2,GLint clip_bit)
-{
- GLint co,c_and,co1,cc[3],edge_flag_tmp,clip_mask;
- GLVertex tmp1,tmp2,*q[3];
- GLfloat tt;
-
- cc[0]=p0->clip_code;
- cc[1]=p1->clip_code;
- cc[2]=p2->clip_code;
-
- co=cc[0] | cc[1] | cc[2];
- if (co == 0) {
- gl_draw_triangle(c,p0,p1,p2);
- } else {
- c_and=cc[0] & cc[1] & cc[2];
- /* the triangle is completely outside */
- if (c_and!=0) return;
+static void gl_draw_triangle_clip(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit) {
+ GLint co, c_and, co1, cc[3], edge_flag_tmp, clip_mask;
+ GLVertex tmp1, tmp2, *q[3];
+ GLfloat tt;
- /* find the next direction to clip */
- while (clip_bit < 6 && (co & (1 << clip_bit)) == 0) {
- clip_bit++;
- }
+ cc[0] = p0->clip_code;
+ cc[1] = p1->clip_code;
+ cc[2] = p2->clip_code;
- /* this test can be true only in case of rounding errors */
- if (clip_bit == 6) {
+ co = cc[0] | cc[1] | cc[2];
+ if (co == 0) {
+ gl_draw_triangle(c, p0, p1, p2);
+ } else {
+ c_and = cc[0] & cc[1] & cc[2];
+ /* the triangle is completely outside */
+ if (c_and != 0)
+ return;
+
+ /* find the next direction to clip */
+ while (clip_bit < 6 && (co & (1 << clip_bit)) == 0) {
+ clip_bit++;
+ }
+
+ /* this test can be true only in case of rounding errors */
+ if (clip_bit == 6) {
#if 0
printf("Error:\n");
printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
@@ -333,126 +306,137 @@
printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
#endif
- return;
- }
-
- clip_mask = 1 << clip_bit;
- co1=(cc[0] ^ cc[1] ^ cc[2]) & clip_mask;
-
- if (co1) {
- /* one point outside */
+ return;
+ }
- if (cc[0] & clip_mask) { q[0]=p0; q[1]=p1; q[2]=p2; }
- else if (cc[1] & clip_mask) { q[0]=p1; q[1]=p2; q[2]=p0; }
- else { q[0]=p2; q[1]=p0; q[2]=p1; }
-
- tt=clip_proc[clip_bit](&tmp1.pc,&q[0]->pc,&q[1]->pc);
- updateTmp(c,&tmp1,q[0],q[1],tt);
+ clip_mask = 1 << clip_bit;
+ co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask;
- tt=clip_proc[clip_bit](&tmp2.pc,&q[0]->pc,&q[2]->pc);
- updateTmp(c,&tmp2,q[0],q[2],tt);
+ if (co1) {
+ /* one point outside */
- tmp1.edge_flag=q[0]->edge_flag;
- edge_flag_tmp=q[2]->edge_flag;
- q[2]->edge_flag=0;
- gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1);
+ if (cc[0] & clip_mask) {
+ q[0] = p0;
+ q[1] = p1;
+ q[2] = p2;
+ } else if (cc[1] & clip_mask) {
+ q[0] = p1;
+ q[1] = p2;
+ q[2] = p0;
+ } else {
+ q[0] = p2;
+ q[1] = p0;
+ q[2] = p1;
+ }
- tmp2.edge_flag=1;
- tmp1.edge_flag=0;
- q[2]->edge_flag=edge_flag_tmp;
- gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1);
- } else {
- /* two points outside */
+ tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
+ updateTmp(c, &tmp1, q[0], q[1], tt);
- if ((cc[0] & clip_mask)==0) { q[0]=p0; q[1]=p1; q[2]=p2; }
- else if ((cc[1] & clip_mask)==0) { q[0]=p1; q[1]=p2; q[2]=p0; }
- else { q[0]=p2; q[1]=p0; q[2]=p1; }
-
- tt=clip_proc[clip_bit](&tmp1.pc,&q[0]->pc,&q[1]->pc);
- updateTmp(c,&tmp1,q[0],q[1],tt);
+ tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
+ updateTmp(c, &tmp2, q[0], q[2], tt);
- tt=clip_proc[clip_bit](&tmp2.pc,&q[0]->pc,&q[2]->pc);
- updateTmp(c,&tmp2,q[0],q[2],tt);
-
- tmp1.edge_flag=1;
- tmp2.edge_flag=q[2]->edge_flag;
- gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1);
- }
- }
-}
+ tmp1.edge_flag = q[0]->edge_flag;
+ edge_flag_tmp = q[2]->edge_flag;
+ q[2]->edge_flag = 0;
+ gl_draw_triangle_clip(c, &tmp1, q[1], q[2], clip_bit + 1);
+ tmp2.edge_flag = 1;
+ tmp1.edge_flag = 0;
+ q[2]->edge_flag = edge_flag_tmp;
+ gl_draw_triangle_clip(c, &tmp2, &tmp1, q[2], clip_bit + 1);
+ } else {
+ /* two points outside */
-void gl_draw_triangle_select(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2)
-{
- gl_add_select1(c,p0->zp.z,p1->zp.z,p2->zp.z);
+ if ((cc[0] & clip_mask) == 0) {
+ q[0] = p0;
+ q[1] = p1;
+ q[2] = p2;
+ } else if ((cc[1] & clip_mask) == 0) {
+ q[0] = p1;
+ q[1] = p2;
+ q[2] = p0;
+ } else {
+ q[0] = p2;
+ q[1] = p0;
+ q[2] = p1;
+ }
+
+ tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
+ updateTmp(c, &tmp1, q[0], q[1], tt);
+
+ tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
+ updateTmp(c, &tmp2, q[0], q[2], tt);
+
+ tmp1.edge_flag = 1;
+ tmp2.edge_flag = q[2]->edge_flag;
+ gl_draw_triangle_clip(c, q[0], &tmp1, &tmp2, clip_bit + 1);
+ }
+ }
}
+void gl_draw_triangle_select(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) { gl_add_select1(c, p0->zp.z, p1->zp.z, p2->zp.z); }
+
#ifdef PROFILE
-int count_triangles,count_triangles_textured,count_pixels;
+int count_triangles, count_triangles_textured, count_pixels;
#endif
-void gl_draw_triangle_fill(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2)
-{
- //puts("\n <yes, it's draw_triangle_fill>");
+void gl_draw_triangle_fill(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+ // puts("\n <yes, it's draw_triangle_fill>");
#ifdef PROFILE
- {
- GLint norm;
- assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
- assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
- assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
- assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
- assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
- assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
-
- norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)-
- (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y);
- count_pixels+=abs(norm)/2;
- count_triangles++;
- }
+ {
+ GLint norm;
+ assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
+ assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
+ assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
+ assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
+ assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
+ assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
+
+ norm = (p1->zp.x - p0->zp.x) * (p2->zp.y - p0->zp.y) - (p2->zp.x - p0->zp.x) * (p1->zp.y - p0->zp.y);
+ count_pixels += abs(norm) / 2;
+ count_triangles++;
+ }
#endif
-
- if (c->texture_2d_enabled) {
+
+ if (c->texture_2d_enabled) {
#ifdef PROFILE
- count_triangles_textured++;
+ count_triangles_textured++;
#endif
- ZB_setTexture(c->zb,c->current_texture->images[0].pixmap);
- ZB_fillTriangleMappingPerspective(c->zb,&p0->zp,&p1->zp,&p2->zp);
- } else if (c->current_shade_model == GL_SMOOTH) {
- ZB_fillTriangleSmooth(c->zb,&p0->zp,&p1->zp,&p2->zp);
- } else {
- ZB_fillTriangleFlat(c->zb,&p0->zp,&p1->zp,&p2->zp);
- }
+ ZB_setTexture(c->zb, c->current_texture->images[0].pixmap);
+ ZB_fillTriangleMappingPerspective(c->zb, &p0->zp, &p1->zp, &p2->zp);
+ } else if (c->current_shade_model == GL_SMOOTH) {
+ ZB_fillTriangleSmooth(c->zb, &p0->zp, &p1->zp, &p2->zp);
+ } else {
+ ZB_fillTriangleFlat(c->zb, &p0->zp, &p1->zp, &p2->zp);
+ }
}
-/* Render a clipped triangle in line mode */
+/* Render a clipped triangle in line mode */
-void gl_draw_triangle_line(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2)
-{
- if (c->depth_test) {
- if (p0->edge_flag) ZB_line_z(c->zb,&p0->zp,&p1->zp);
- if (p1->edge_flag) ZB_line_z(c->zb,&p1->zp,&p2->zp);
- if (p2->edge_flag) ZB_line_z(c->zb,&p2->zp,&p0->zp);
- } else {
- if (p0->edge_flag) ZB_line(c->zb,&p0->zp,&p1->zp);
- if (p1->edge_flag) ZB_line(c->zb,&p1->zp,&p2->zp);
- if (p2->edge_flag) ZB_line(c->zb,&p2->zp,&p0->zp);
- }
+void gl_draw_triangle_line(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+ if (c->depth_test) {
+ if (p0->edge_flag)
+ ZB_line_z(c->zb, &p0->zp, &p1->zp);
+ if (p1->edge_flag)
+ ZB_line_z(c->zb, &p1->zp, &p2->zp);
+ if (p2->edge_flag)
+ ZB_line_z(c->zb, &p2->zp, &p0->zp);
+ } else {
+ if (p0->edge_flag)
+ ZB_line(c->zb, &p0->zp, &p1->zp);
+ if (p1->edge_flag)
+ ZB_line(c->zb, &p1->zp, &p2->zp);
+ if (p2->edge_flag)
+ ZB_line(c->zb, &p2->zp, &p0->zp);
+ }
}
-
-
/* Render a clipped triangle in point mode */
-void gl_draw_triangle_point(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2)
-{
- if (p0->edge_flag) ZB_plot(c->zb,&p0->zp);
- if (p1->edge_flag) ZB_plot(c->zb,&p1->zp);
- if (p2->edge_flag) ZB_plot(c->zb,&p2->zp);
+void gl_draw_triangle_point(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+ if (p0->edge_flag)
+ ZB_plot(c->zb, &p0->zp);
+ if (p1->edge_flag)
+ ZB_plot(c->zb, &p1->zp);
+ if (p2->edge_flag)
+ ZB_plot(c->zb, &p2->zp);
}
-
-
-
-
--- /dev/null
+++ b/src/code_format.sh
@@ -1,0 +1,1 @@
+clang-format-8 -i *.c *.h --style=file
--- a/src/error.c
+++ b/src/error.c
@@ -1,16 +1,15 @@
-#include <stdarg.h>
#include "zgl.h"
+#include <stdarg.h>
-void gl_fatal_error(char *format, ...)
-{
- va_list ap;
+void gl_fatal_error(char* format, ...) {
+ va_list ap;
- va_start(ap,format);
+ va_start(ap, format);
- fprintf(stderr,"TinyGL: fatal error: ");
- vfprintf(stderr,format,ap);
- fprintf(stderr,"\n");
- exit(1);
+ fprintf(stderr, "TinyGL: fatal error: ");
+ vfprintf(stderr, format, ap);
+ fprintf(stderr, "\n");
+ exit(1);
- va_end(ap);
+ va_end(ap);
}
--- a/src/font8x8_basic.h
+++ b/src/font8x8_basic.h
@@ -21,132 +21,132 @@
// Constant: font8x8_basic
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
GLbyte font8x8_basic[128][8] = {
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul)
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space)
- { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!)
- { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (")
- { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#)
- { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($)
- { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%)
- { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&)
- { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (')
- { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (()
- { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ())
- { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*)
- { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+)
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,)
- { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-)
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.)
- { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/)
- { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0)
- { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1)
- { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2)
- { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3)
- { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4)
- { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5)
- { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6)
- { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7)
- { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8)
- { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9)
- { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:)
- { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (;)
- { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<)
- { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=)
- { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>)
- { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?)
- { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@)
- { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A)
- { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B)
- { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C)
- { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D)
- { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E)
- { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F)
- { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G)
- { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H)
- { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I)
- { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J)
- { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K)
- { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L)
- { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M)
- { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N)
- { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O)
- { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P)
- { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q)
- { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R)
- { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S)
- { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T)
- { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U)
- { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V)
- { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W)
- { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X)
- { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y)
- { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z)
- { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([)
- { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\)
- { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (])
- { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^)
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_)
- { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`)
- { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a)
- { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b)
- { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c)
- { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d)
- { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e)
- { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f)
- { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g)
- { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h)
- { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i)
- { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j)
- { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k)
- { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l)
- { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m)
- { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n)
- { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o)
- { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p)
- { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q)
- { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r)
- { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s)
- { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t)
- { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u)
- { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v)
- { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w)
- { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x)
- { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y)
- { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z)
- { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({)
- { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|)
- { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (})
- { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~)
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space)
+ {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!)
+ {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (")
+ {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#)
+ {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($)
+ {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%)
+ {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&)
+ {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (')
+ {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (()
+ {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ())
+ {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*)
+ {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,)
+ {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.)
+ {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/)
+ {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0)
+ {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1)
+ {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2)
+ {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3)
+ {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4)
+ {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5)
+ {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6)
+ {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7)
+ {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8)
+ {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9)
+ {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:)
+ {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (;)
+ {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<)
+ {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=)
+ {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>)
+ {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?)
+ {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@)
+ {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A)
+ {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B)
+ {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C)
+ {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D)
+ {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E)
+ {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F)
+ {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G)
+ {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H)
+ {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I)
+ {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J)
+ {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K)
+ {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L)
+ {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M)
+ {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N)
+ {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O)
+ {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P)
+ {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q)
+ {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R)
+ {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S)
+ {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T)
+ {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U)
+ {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V)
+ {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W)
+ {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X)
+ {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y)
+ {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z)
+ {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([)
+ {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\)
+ {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (])
+ {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_)
+ {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`)
+ {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a)
+ {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b)
+ {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c)
+ {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d)
+ {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e)
+ {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f)
+ {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g)
+ {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h)
+ {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i)
+ {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j)
+ {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k)
+ {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l)
+ {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m)
+ {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n)
+ {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o)
+ {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p)
+ {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q)
+ {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r)
+ {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s)
+ {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v)
+ {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w)
+ {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y)
+ {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z)
+ {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({)
+ {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|)
+ {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (})
+ {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F
};
--- a/src/get.c
+++ b/src/get.c
@@ -1,72 +1,69 @@
#include "zgl.h"
-void glGetIntegerv(GLint pname,GLint *params)
-{
- GLContext *c=gl_get_context();
+void glGetIntegerv(GLint pname, GLint* params) {
+ GLContext* c = gl_get_context();
- switch(pname) {
- case GL_VIEWPORT:
- params[0]=c->viewport.xmin;
- params[1]=c->viewport.ymin;
- params[2]=c->viewport.xsize;
- params[3]=c->viewport.ysize;
- break;
- case GL_MAX_MODELVIEW_STACK_DEPTH:
- *params = MAX_MODELVIEW_STACK_DEPTH;
- break;
- case GL_MAX_PROJECTION_STACK_DEPTH:
- *params = MAX_PROJECTION_STACK_DEPTH;
- break;
- case GL_MAX_LIGHTS:
- *params = MAX_LIGHTS;
- break;
- case GL_MAX_TEXTURE_SIZE:
- *params = 256; /* not completely true, but... */
- break;
- case GL_MAX_TEXTURE_STACK_DEPTH:
- *params = MAX_TEXTURE_STACK_DEPTH;
- break;
- default:
- gl_fatal_error("glGet: option not implemented");
- break;
- }
+ switch (pname) {
+ case GL_VIEWPORT:
+ params[0] = c->viewport.xmin;
+ params[1] = c->viewport.ymin;
+ params[2] = c->viewport.xsize;
+ params[3] = c->viewport.ysize;
+ break;
+ case GL_MAX_MODELVIEW_STACK_DEPTH:
+ *params = MAX_MODELVIEW_STACK_DEPTH;
+ break;
+ case GL_MAX_PROJECTION_STACK_DEPTH:
+ *params = MAX_PROJECTION_STACK_DEPTH;
+ break;
+ case GL_MAX_LIGHTS:
+ *params = MAX_LIGHTS;
+ break;
+ case GL_MAX_TEXTURE_SIZE:
+ *params = 256; /* not completely true, but... */
+ break;
+ case GL_MAX_TEXTURE_STACK_DEPTH:
+ *params = MAX_TEXTURE_STACK_DEPTH;
+ break;
+ default:
+ gl_fatal_error("glGet: option not implemented");
+ break;
+ }
}
-void glGetFloatv(GLint pname, GLfloat *v)
-{
- GLint i;
- GLint mnr = 0; /* just a trick to return the correct matrix */
- GLContext *c = gl_get_context();
- switch (pname) {
- case GL_TEXTURE_MATRIX:
- mnr++;
- case GL_PROJECTION_MATRIX:
- mnr++;
- case GL_MODELVIEW_MATRIX:
- {
- GLfloat *p = &c->matrix_stack_ptr[mnr]->m[0][0];;
- for (i = 0; i < 4; i++) {
- *v++ = p[0];
- *v++ = p[4];
- *v++ = p[8];
- *v++ = p[12];
- p++;
- }
- }
- break;
- case GL_LINE_WIDTH:
- *v = 1.0f;
- break;
- case GL_LINE_WIDTH_RANGE:
- v[0] = v[1] = 1.0f;
- break;
- case GL_POINT_SIZE:
- *v = 1.0f;
- break;
- case GL_POINT_SIZE_RANGE:
- v[0] = v[1] = 1.0f;
- default:
- fprintf(stderr,"warning: unknown pname in glGetFloatv()\n");
- break;
- }
+void glGetFloatv(GLint pname, GLfloat* v) {
+ GLint i;
+ GLint mnr = 0; /* just a trick to return the correct matrix */
+ GLContext* c = gl_get_context();
+ switch (pname) {
+ case GL_TEXTURE_MATRIX:
+ mnr++;
+ case GL_PROJECTION_MATRIX:
+ mnr++;
+ case GL_MODELVIEW_MATRIX: {
+ GLfloat* p = &c->matrix_stack_ptr[mnr]->m[0][0];
+ ;
+ for (i = 0; i < 4; i++) {
+ *v++ = p[0];
+ *v++ = p[4];
+ *v++ = p[8];
+ *v++ = p[12];
+ p++;
+ }
+ } break;
+ case GL_LINE_WIDTH:
+ *v = 1.0f;
+ break;
+ case GL_LINE_WIDTH_RANGE:
+ v[0] = v[1] = 1.0f;
+ break;
+ case GL_POINT_SIZE:
+ *v = 1.0f;
+ break;
+ case GL_POINT_SIZE_RANGE:
+ v[0] = v[1] = 1.0f;
+ default:
+ fprintf(stderr, "warning: unknown pname in glGetFloatv()\n");
+ break;
+ }
}
--- a/src/image_util.c
+++ b/src/image_util.c
@@ -4,36 +4,30 @@
* image conversion
*/
-void gl_convertRGB_to_5R6G5B(GLushort *pixmap,GLubyte *rgb,
- GLint xsize,GLint ysize)
-{
- GLint i,n;
- GLubyte *p;
+void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize) {
+ GLint i, n;
+ GLubyte* p;
- p=rgb;
- n=xsize*ysize;
- for(i=0;i<n;i++) {
- pixmap[i]=((p[0]&0xF8)<<8) | ((p[1]&0xFC)<<3) | ((p[2]&0xF8)>>3);
- p+=3;
- }
+ p = rgb;
+ n = xsize * ysize;
+ for (i = 0; i < n; i++) {
+ pixmap[i] = ((p[0] & 0xF8) << 8) | ((p[1] & 0xFC) << 3) | ((p[2] & 0xF8) >> 3);
+ p += 3;
+ }
}
-//This actually converts to ABGR!!!
-//This is the format of the entire engine!!!
-void gl_convertRGB_to_8A8R8G8B(GLuint *pixmap, GLubyte *rgb,
- GLint xsize, GLint ysize)
-{
- GLint i,n;
- GLubyte *p;
-
- p=rgb;
- n=xsize*ysize;
- for(i=0;i<n;i++) {
- pixmap[i]=(((GLuint)p[0])<<16) |
- (((GLuint)p[1])<<8) |
- (((GLuint)p[2]) );
- p+=3;
- }
+// This actually converts to ABGR!!!
+// This is the format of the entire engine!!!
+void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize) {
+ GLint i, n;
+ GLubyte* p;
+
+ p = rgb;
+ n = xsize * ysize;
+ for (i = 0; i < n; i++) {
+ pixmap[i] = (((GLuint)p[0]) << 16) | (((GLuint)p[1]) << 8) | (((GLuint)p[2]));
+ p += 3;
+ }
}
/*
@@ -40,64 +34,56 @@
* linear GLinterpolation with xf,yf normalized to 2^16
*/
-#define INTERP_NORM_BITS 16
-#define INTERP_NORM (1 << INTERP_NORM_BITS)
+#define INTERP_NORM_BITS 16
+#define INTERP_NORM (1 << INTERP_NORM_BITS)
-static inline GLint GLinterpolate(GLint v00,GLint v01,GLint v10,GLint xf,GLint yf)
-{
- return v00+(((v01-v00)*xf + (v10-v00)*yf) >> INTERP_NORM_BITS);
+static inline GLint GLinterpolate(GLint v00, GLint v01, GLint v10, GLint xf, GLint yf) {
+ return v00 + (((v01 - v00) * xf + (v10 - v00) * yf) >> INTERP_NORM_BITS);
}
-
-/*
- * TODO: more accurate resampling
+/*
+ * TODO: more accurate resampling
*/
-void gl_resizeImage(GLubyte *dest,GLint xsize_dest,GLint ysize_dest,
- GLubyte *src,GLint xsize_src,GLint ysize_src)
-{
- GLubyte *pix,*pix_src;
- GLfloat x1,y1,x1inc,y1inc;
- GLint xi,yi,j,xf,yf,x,y;
+void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src) {
+ GLubyte *pix, *pix_src;
+ GLfloat x1, y1, x1inc, y1inc;
+ GLint xi, yi, j, xf, yf, x, y;
- pix=dest;
- pix_src=src;
-
- x1inc=(GLfloat) (xsize_src - 1) / (GLfloat) (xsize_dest - 1);
- y1inc=(GLfloat) (ysize_src - 1) / (GLfloat) (ysize_dest - 1);
+ pix = dest;
+ pix_src = src;
- y1=0;
- for(y=0;y<ysize_dest;y++) {
- x1=0;
- for(x=0;x<xsize_dest;x++) {
- xi=(GLint) x1;
- yi=(GLint) y1;
- xf=(GLint) ((x1 - floor(x1)) * INTERP_NORM);
- yf=(GLint) ((y1 - floor(y1)) * INTERP_NORM);
-
- if ((xf+yf) <= INTERP_NORM) {
- for(j=0;j<3;j++) {
- pix[j]=GLinterpolate(pix_src[(yi*xsize_src+xi)*3+j],
- pix_src[(yi*xsize_src+xi+1)*3+j],
- pix_src[((yi+1)*xsize_src+xi)*3+j],
- xf,yf);
+ x1inc = (GLfloat)(xsize_src - 1) / (GLfloat)(xsize_dest - 1);
+ y1inc = (GLfloat)(ysize_src - 1) / (GLfloat)(ysize_dest - 1);
+
+ y1 = 0;
+ for (y = 0; y < ysize_dest; y++) {
+ x1 = 0;
+ for (x = 0; x < xsize_dest; x++) {
+ xi = (GLint)x1;
+ yi = (GLint)y1;
+ xf = (GLint)((x1 - floor(x1)) * INTERP_NORM);
+ yf = (GLint)((y1 - floor(y1)) * INTERP_NORM);
+
+ if ((xf + yf) <= INTERP_NORM) {
+ for (j = 0; j < 3; j++) {
+ pix[j] = GLinterpolate(pix_src[(yi * xsize_src + xi) * 3 + j], pix_src[(yi * xsize_src + xi + 1) * 3 + j],
+ pix_src[((yi + 1) * xsize_src + xi) * 3 + j], xf, yf);
+ }
+ } else {
+ xf = INTERP_NORM - xf;
+ yf = INTERP_NORM - yf;
+ for (j = 0; j < 3; j++) {
+ pix[j] = GLinterpolate(pix_src[((yi + 1) * xsize_src + xi + 1) * 3 + j], pix_src[((yi + 1) * xsize_src + xi) * 3 + j],
+ pix_src[(yi * xsize_src + xi + 1) * 3 + j], xf, yf);
+ }
+ }
+
+ pix += 3;
+ x1 += x1inc;
+ }
+ y1 += y1inc;
}
- } else {
- xf=INTERP_NORM - xf;
- yf=INTERP_NORM - yf;
- for(j=0;j<3;j++) {
- pix[j]=GLinterpolate(pix_src[((yi+1)*xsize_src+xi+1)*3+j],
- pix_src[((yi+1)*xsize_src+xi)*3+j],
- pix_src[(yi*xsize_src+xi+1)*3+j],
- xf,yf);
- }
- }
-
- pix+=3;
- x1+=x1inc;
- }
- y1+=y1inc;
- }
}
#define FRAC_BITS 16
@@ -104,35 +90,32 @@
/* resizing with no GLinterlating nor nearest pixel */
-void gl_resizeImageNoInterpolate(GLubyte *dest,GLint xsize_dest,GLint ysize_dest,
- GLubyte *src,GLint xsize_src,GLint ysize_src)
-{
- GLubyte *pix,*pix_src,*pix1;
- GLint x1,y1,x1inc,y1inc;
- GLint xi,yi,x,y;
+void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src) {
+ GLubyte *pix, *pix_src, *pix1;
+ GLint x1, y1, x1inc, y1inc;
+ GLint xi, yi, x, y;
- pix=dest;
- pix_src=src;
-
- x1inc=(GLint)((GLfloat) ((xsize_src)<<FRAC_BITS) / (GLfloat) (xsize_dest));
- y1inc=(GLint)((GLfloat) ((ysize_src)<<FRAC_BITS) / (GLfloat) (ysize_dest));
+ pix = dest;
+ pix_src = src;
- y1=0;
- for(y=0;y<ysize_dest;y++) {
- x1=0;
- for(x=0;x<xsize_dest;x++) {
- xi=x1 >> FRAC_BITS;
- yi=y1 >> FRAC_BITS;
- pix1=pix_src+(yi*xsize_src+xi)*3;
+ x1inc = (GLint)((GLfloat)((xsize_src) << FRAC_BITS) / (GLfloat)(xsize_dest));
+ y1inc = (GLint)((GLfloat)((ysize_src) << FRAC_BITS) / (GLfloat)(ysize_dest));
- pix[0]=pix1[0];
- pix[1]=pix1[1];
- pix[2]=pix1[2];
+ y1 = 0;
+ for (y = 0; y < ysize_dest; y++) {
+ x1 = 0;
+ for (x = 0; x < xsize_dest; x++) {
+ xi = x1 >> FRAC_BITS;
+ yi = y1 >> FRAC_BITS;
+ pix1 = pix_src + (yi * xsize_src + xi) * 3;
- pix+=3;
- x1+=x1inc;
- }
- y1+=y1inc;
- }
-}
+ pix[0] = pix1[0];
+ pix[1] = pix1[1];
+ pix[2] = pix1[2];
+ pix += 3;
+ x1 += x1inc;
+ }
+ y1 += y1inc;
+ }
+}
--- a/src/init.c
+++ b/src/init.c
@@ -1,194 +1,187 @@
#include "zgl.h"
-GLContext *gl_ctx;
+GLContext* gl_ctx;
+void initSharedState(GLContext* c) {
+ GLSharedState* s = &c->shared_state;
+ s->lists = gl_zalloc(sizeof(GLList*) * MAX_DISPLAY_LISTS);
+ s->texture_hash_table = gl_zalloc(sizeof(GLTexture*) * TEXTURE_HASH_TABLE_SIZE);
-void initSharedState(GLContext *c)
-{
- GLSharedState *s=&c->shared_state;
- s->lists=gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS);
- s->texture_hash_table=
- gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE);
-
- alloc_texture(c,0);
+ alloc_texture(c, 0);
}
-void endSharedState(GLContext *c)
-{
- GLSharedState *s=&c->shared_state;
- GLint i;
+void endSharedState(GLContext* c) {
+ GLSharedState* s = &c->shared_state;
+ GLint i;
- for(i=0;i<MAX_DISPLAY_LISTS;i++) {
- /* TODO */
- }
- gl_free(s->lists);
+ for (i = 0; i < MAX_DISPLAY_LISTS; i++) {
+ /* TODO */
+ }
+ gl_free(s->lists);
- gl_free(s->texture_hash_table);
+ gl_free(s->texture_hash_table);
}
+void glInit(void* zbuffer1) {
+ ZBuffer* zbuffer = (ZBuffer*)zbuffer1;
+ GLContext* c;
+ GLViewport* v;
+ GLint i;
-void glInit(void *zbuffer1)
-{
- ZBuffer *zbuffer=(ZBuffer *)zbuffer1;
- GLContext *c;
- GLViewport *v;
- GLint i;
+ c = gl_zalloc(sizeof(GLContext));
+ gl_ctx = c;
- c=gl_zalloc(sizeof(GLContext));
- gl_ctx=c;
+ c->zb = zbuffer;
- c->zb=zbuffer;
+ /* allocate GLVertex array */
+ c->vertex_max = POLYGON_MAX_VERTEX;
+ c->vertex = gl_malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));
- /* allocate GLVertex array */
- c->vertex_max = POLYGON_MAX_VERTEX;
- c->vertex = gl_malloc(POLYGON_MAX_VERTEX*sizeof(GLVertex));
-
- /* viewport */
- v=&c->viewport;
- v->xmin=0;
- v->ymin=0;
- v->xsize=zbuffer->xsize;
- v->ysize=zbuffer->ysize;
- v->updated=1;
+ /* viewport */
+ v = &c->viewport;
+ v->xmin = 0;
+ v->ymin = 0;
+ v->xsize = zbuffer->xsize;
+ v->ysize = zbuffer->ysize;
+ v->updated = 1;
- /* shared state */
- initSharedState(c);
+ /* shared state */
+ initSharedState(c);
- /* lists */
+ /* lists */
- c->exec_flag=1;
- c->compile_flag=0;
- c->print_flag=0;
+ c->exec_flag = 1;
+ c->compile_flag = 0;
+ c->print_flag = 0;
- c->in_begin=0;
+ c->in_begin = 0;
- /* lights */
- for(i=0;i<MAX_LIGHTS;i++) {
- GLLight *l=&c->lights[i];
- l->ambient=gl_V4_New(0,0,0,1);
- l->diffuse=gl_V4_New(1,1,1,1);
- l->specular=gl_V4_New(1,1,1,1);
- l->position=gl_V4_New(0,0,1,0);
- l->norm_position=gl_V3_New(0,0,1);
- l->spot_direction=gl_V3_New(0,0,-1);
- l->norm_spot_direction=gl_V3_New(0,0,-1);
- l->spot_exponent=0;
- l->spot_cutoff=180;
- l->attenuation[0]=1;
- l->attenuation[1]=0;
- l->attenuation[2]=0;
- l->enabled=0;
- }
- c->first_light=NULL;
- c->ambient_light_model=gl_V4_New(0.2,0.2,0.2,1);
- c->local_light_model=0;
- c->lighting_enabled=0;
- c->light_model_two_side = 0;
+ /* lights */
+ for (i = 0; i < MAX_LIGHTS; i++) {
+ GLLight* l = &c->lights[i];
+ l->ambient = gl_V4_New(0, 0, 0, 1);
+ l->diffuse = gl_V4_New(1, 1, 1, 1);
+ l->specular = gl_V4_New(1, 1, 1, 1);
+ l->position = gl_V4_New(0, 0, 1, 0);
+ l->norm_position = gl_V3_New(0, 0, 1);
+ l->spot_direction = gl_V3_New(0, 0, -1);
+ l->norm_spot_direction = gl_V3_New(0, 0, -1);
+ l->spot_exponent = 0;
+ l->spot_cutoff = 180;
+ l->attenuation[0] = 1;
+ l->attenuation[1] = 0;
+ l->attenuation[2] = 0;
+ l->enabled = 0;
+ }
+ c->first_light = NULL;
+ c->ambient_light_model = gl_V4_New(0.2, 0.2, 0.2, 1);
+ c->local_light_model = 0;
+ c->lighting_enabled = 0;
+ c->light_model_two_side = 0;
- /* default materials */
- for(i=0;i<2;i++) {
- GLMaterial *m=&c->materials[i];
- m->emission=gl_V4_New(0,0,0,1);
- m->ambient=gl_V4_New(0.2,0.2,0.2,1);
- m->diffuse=gl_V4_New(0.8,0.8,0.8,1);
- m->specular=gl_V4_New(0,0,0,1);
- m->shininess=0;
- }
- c->current_color_material_mode=GL_FRONT_AND_BACK;
- c->current_color_material_type=GL_AMBIENT_AND_DIFFUSE;
- c->color_material_enabled=0;
+ /* default materials */
+ for (i = 0; i < 2; i++) {
+ GLMaterial* m = &c->materials[i];
+ m->emission = gl_V4_New(0, 0, 0, 1);
+ m->ambient = gl_V4_New(0.2, 0.2, 0.2, 1);
+ m->diffuse = gl_V4_New(0.8, 0.8, 0.8, 1);
+ m->specular = gl_V4_New(0, 0, 0, 1);
+ m->shininess = 0;
+ }
+ c->current_color_material_mode = GL_FRONT_AND_BACK;
+ c->current_color_material_type = GL_AMBIENT_AND_DIFFUSE;
+ c->color_material_enabled = 0;
- /* textures */
- glInitTextures(c);
+ /* textures */
+ glInitTextures(c);
- /* default state */
- c->current_color.X=1.0;
- c->current_color.Y=1.0;
- c->current_color.Z=1.0;
- c->current_color.W=0.0;
- //Shouldn't ever be used.
- //c->longcurrent_color[0] = 65280;
- //c->longcurrent_color[1] = 65280;
- //c->longcurrent_color[2] = 65280;
+ /* default state */
+ c->current_color.X = 1.0;
+ c->current_color.Y = 1.0;
+ c->current_color.Z = 1.0;
+ c->current_color.W = 0.0;
+ // Shouldn't ever be used.
+ // c->longcurrent_color[0] = 65280;
+ // c->longcurrent_color[1] = 65280;
+ // c->longcurrent_color[2] = 65280;
- c->current_normal.X=1.0;
- c->current_normal.Y=0.0;
- c->current_normal.Z=0.0;
- c->current_normal.W=0.0;
+ c->current_normal.X = 1.0;
+ c->current_normal.Y = 0.0;
+ c->current_normal.Z = 0.0;
+ c->current_normal.W = 0.0;
- c->current_edge_flag=1;
-
- c->current_tex_coord.X=0;
- c->current_tex_coord.Y=0;
- c->current_tex_coord.Z=0;
- c->current_tex_coord.W=1;
+ c->current_edge_flag = 1;
- c->polygon_mode_front=GL_FILL;
- c->polygon_mode_back=GL_FILL;
+ c->current_tex_coord.X = 0;
+ c->current_tex_coord.Y = 0;
+ c->current_tex_coord.Z = 0;
+ c->current_tex_coord.W = 1;
- c->current_front_face=0; /* 0 = GL_CCW 1 = GL_CW */
- c->current_cull_face=GL_BACK;
- c->current_shade_model=GL_SMOOTH;
- c->cull_face_enabled=0;
- c->zb->dostipple = 0;
+ c->polygon_mode_front = GL_FILL;
+ c->polygon_mode_back = GL_FILL;
+
+ c->current_front_face = 0; /* 0 = GL_CCW 1 = GL_CW */
+ c->current_cull_face = GL_BACK;
+ c->current_shade_model = GL_SMOOTH;
+ c->cull_face_enabled = 0;
+ c->zb->dostipple = 0;
#if TGL_FEATURE_POLYGON_STIPPLE == 1
- for(GLint i = 0; i < 128; i++)
- c->zb->stipplepattern[i] = 0xFF;
+ for (GLint i = 0; i < 128; i++)
+ c->zb->stipplepattern[i] = 0xFF;
#endif
- /* clear */
- c->clear_color.v[0]=0;
- c->clear_color.v[1]=0;
- c->clear_color.v[2]=0;
- c->clear_color.v[3]=0;
- c->clear_depth=0;
+ /* clear */
+ c->clear_color.v[0] = 0;
+ c->clear_color.v[1] = 0;
+ c->clear_color.v[2] = 0;
+ c->clear_color.v[3] = 0;
+ c->clear_depth = 0;
- /* selection */
- c->render_mode=GL_RENDER;
- c->select_buffer=NULL;
- c->name_stack_size=0;
-
- /* matrix */
- c->matrix_mode=0;
-
- c->matrix_stack_depth_max[0]=MAX_MODELVIEW_STACK_DEPTH;
- c->matrix_stack_depth_max[1]=MAX_PROJECTION_STACK_DEPTH;
- c->matrix_stack_depth_max[2]=MAX_TEXTURE_STACK_DEPTH;
+ /* selection */
+ c->render_mode = GL_RENDER;
+ c->select_buffer = NULL;
+ c->name_stack_size = 0;
- for(i=0;i<3;i++) {
- c->matrix_stack[i]=gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(M4));
- c->matrix_stack_ptr[i]=c->matrix_stack[i];
- }
+ /* matrix */
+ c->matrix_mode = 0;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ c->matrix_stack_depth_max[0] = MAX_MODELVIEW_STACK_DEPTH;
+ c->matrix_stack_depth_max[1] = MAX_PROJECTION_STACK_DEPTH;
+ c->matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH;
- c->matrix_model_projection_updated=1;
+ for (i = 0; i < 3; i++) {
+ c->matrix_stack[i] = gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(M4));
+ c->matrix_stack_ptr[i] = c->matrix_stack[i];
+ }
- /* opengl 1.1 arrays */
- c->client_states = 0;
-
- /* opengl 1.1 polygon offset */
- c->offset_states = 0;
-
- /* clear the resize callback function pointer */
- c->gl_resize_viewport = NULL;
-
- /* specular buffer */
- c->specbuf_first = NULL;
- c->specbuf_used_counter = 0;
- c->specbuf_num_buffers = 0;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
- /* depth test */
- c->depth_test = 0;
+ c->matrix_model_projection_updated = 1;
+
+ /* opengl 1.1 arrays */
+ c->client_states = 0;
+
+ /* opengl 1.1 polygon offset */
+ c->offset_states = 0;
+
+ /* clear the resize callback function pointer */
+ c->gl_resize_viewport = NULL;
+
+ /* specular buffer */
+ c->specbuf_first = NULL;
+ c->specbuf_used_counter = 0;
+ c->specbuf_num_buffers = 0;
+
+ /* depth test */
+ c->depth_test = 0;
}
-void glClose(void)
-{
- GLContext *c=gl_get_context();
- endSharedState(c);
- gl_free(c);
+void glClose(void) {
+ GLContext* c = gl_get_context();
+ endSharedState(c);
+ gl_free(c);
}
--- a/src/light.c
+++ b/src/light.c
@@ -1,337 +1,332 @@
-#include "zgl.h"
#include "msghandling.h"
+#include "zgl.h"
-void glopMaterial(GLContext *c,GLParam *p)
-{
- GLint mode=p[1].i;
- GLint type=p[2].i;
- GLfloat v[4];
- v[0]= p[3].f;
- v[1]= p[4].f;
- v[2]= p[5].f;
- v[3]= p[6].f;
- GLint i;
- GLMaterial *m;
+void glopMaterial(GLContext* c, GLParam* p) {
+ GLint mode = p[1].i;
+ GLint type = p[2].i;
+ GLfloat v[4];
+ v[0] = p[3].f;
+ v[1] = p[4].f;
+ v[2] = p[5].f;
+ v[3] = p[6].f;
+ GLint i;
+ GLMaterial* m;
- if (mode == GL_FRONT_AND_BACK) {
- p[1].i=GL_FRONT;
- glopMaterial(c,p);
- mode=GL_BACK;
- }
- if (mode == GL_FRONT) m=&c->materials[0];
- else m=&c->materials[1];
+ if (mode == GL_FRONT_AND_BACK) {
+ p[1].i = GL_FRONT;
+ glopMaterial(c, p);
+ mode = GL_BACK;
+ }
+ if (mode == GL_FRONT)
+ m = &c->materials[0];
+ else
+ m = &c->materials[1];
- switch(type) {
- case GL_EMISSION:
- for(i=0;i<4;i++)
- m->emission.v[i]=v[i];
- break;
- case GL_AMBIENT:
- for(i=0;i<4;i++)
- m->ambient.v[i]=v[i];
- //c->current_color.X=v[0];
- //c->current_color.Y=v[1];
- //c->current_color.Z=v[2];
- //c->current_color.W=v[3];
- break;
- case GL_DIFFUSE:
- for(i=0;i<4;i++)
- m->diffuse.v[i]=v[i];
+ switch (type) {
+ case GL_EMISSION:
+ for (i = 0; i < 4; i++)
+ m->emission.v[i] = v[i];
+ break;
+ case GL_AMBIENT:
+ for (i = 0; i < 4; i++)
+ m->ambient.v[i] = v[i];
+ // c->current_color.X=v[0];
+ // c->current_color.Y=v[1];
+ // c->current_color.Z=v[2];
+ // c->current_color.W=v[3];
+ break;
+ case GL_DIFFUSE:
+ for (i = 0; i < 4; i++)
+ m->diffuse.v[i] = v[i];
- //c->current_color.X=v[0];
- //c->current_color.Y=v[1];
- //c->current_color.Z=v[2];
- //c->current_color.W=v[3];
- break;
- case GL_SPECULAR:
- for(i=0;i<4;i++)
- m->specular.v[i]=v[i];
- break;
- case GL_SHININESS:
- m->shininess=v[0];
- m->shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION;
- break;
- case GL_AMBIENT_AND_DIFFUSE:
- //printf("\nRECEIVED AMBIENT AND DIFFUSE COLOR %f, %f, %f, %f", v[0], v[1], v[2], v[3]);
- for(i=0;i<4;i++)
- m->diffuse.v[i]=v[i];
- //c->current_color.X=v[0];
- //c->current_color.Y=v[1];
- //c->current_color.Z=v[2];
- //c->current_color.W=v[3];
-
- for(i=0;i<4;i++)
- m->ambient.v[i]=v[i];
- break;
- default:
- c->current_color.X=v[0];
- c->current_color.Y=v[1];
- c->current_color.Z=v[2];
- c->current_color.W=v[3];
- assert(0);
- }
+ // c->current_color.X=v[0];
+ // c->current_color.Y=v[1];
+ // c->current_color.Z=v[2];
+ // c->current_color.W=v[3];
+ break;
+ case GL_SPECULAR:
+ for (i = 0; i < 4; i++)
+ m->specular.v[i] = v[i];
+ break;
+ case GL_SHININESS:
+ m->shininess = v[0];
+ m->shininess_i = (v[0] / 128.0f) * SPECULAR_BUFFER_RESOLUTION;
+ break;
+ case GL_AMBIENT_AND_DIFFUSE:
+ // printf("\nRECEIVED AMBIENT AND DIFFUSE COLOR %f, %f, %f, %f", v[0], v[1], v[2], v[3]);
+ for (i = 0; i < 4; i++)
+ m->diffuse.v[i] = v[i];
+ // c->current_color.X=v[0];
+ // c->current_color.Y=v[1];
+ // c->current_color.Z=v[2];
+ // c->current_color.W=v[3];
+
+ for (i = 0; i < 4; i++)
+ m->ambient.v[i] = v[i];
+ break;
+ default:
+ c->current_color.X = v[0];
+ c->current_color.Y = v[1];
+ c->current_color.Z = v[2];
+ c->current_color.W = v[3];
+ assert(0);
+ }
}
-void glopColorMaterial(GLContext *c,GLParam *p)
-{
- GLint mode=p[1].i;
- GLint type=p[2].i;
+void glopColorMaterial(GLContext* c, GLParam* p) {
+ GLint mode = p[1].i;
+ GLint type = p[2].i;
- c->current_color_material_mode=mode;
- c->current_color_material_type=type;
+ c->current_color_material_mode = mode;
+ c->current_color_material_type = type;
}
-void glopLight(GLContext *c,GLParam *p)
-{
- GLint light=p[1].i;
- GLint type=p[2].i;
- V4 v;
- GLLight *l;
- GLint i;
-
- assert(light >= GL_LIGHT0 && light < GL_LIGHT0+MAX_LIGHTS );
+void glopLight(GLContext* c, GLParam* p) {
+ GLint light = p[1].i;
+ GLint type = p[2].i;
+ V4 v;
+ GLLight* l;
+ GLint i;
- l=&c->lights[light-GL_LIGHT0];
+ assert(light >= GL_LIGHT0 && light < GL_LIGHT0 + MAX_LIGHTS);
- for(i=0;i<4;i++) v.v[i]=p[3+i].f;
+ l = &c->lights[light - GL_LIGHT0];
- switch(type) {
- case GL_AMBIENT:
- l->ambient=v;
- break;
- case GL_DIFFUSE:
- l->diffuse=v;
- break;
- case GL_SPECULAR:
- l->specular=v;
- break;
- case GL_POSITION:
- {
- V4 pos;
- gl_M4_MulV4(&pos,c->matrix_stack_ptr[0],&v);
+ for (i = 0; i < 4; i++)
+ v.v[i] = p[3 + i].f;
- l->position=pos;
+ switch (type) {
+ case GL_AMBIENT:
+ l->ambient = v;
+ break;
+ case GL_DIFFUSE:
+ l->diffuse = v;
+ break;
+ case GL_SPECULAR:
+ l->specular = v;
+ break;
+ case GL_POSITION: {
+ V4 pos;
+ gl_M4_MulV4(&pos, c->matrix_stack_ptr[0], &v);
- if (l->position.v[3] == 0) {
- l->norm_position.X=pos.X;
- l->norm_position.Y=pos.Y;
- l->norm_position.Z=pos.Z;
- gl_V3_Norm(&l->norm_position);
- }
- }
- break;
- case GL_SPOT_DIRECTION:
- for(i=0;i<3;i++) {
- l->spot_direction.v[i]=v.v[i];
- l->norm_spot_direction.v[i]=v.v[i];
- }
- gl_V3_Norm(&l->norm_spot_direction);
- break;
- case GL_SPOT_EXPONENT:
- l->spot_exponent=v.v[0];
- break;
- case GL_SPOT_CUTOFF:
- {
- GLfloat a=v.v[0];
- assert(a == 180 || (a>=0 && a<=90));
- l->spot_cutoff=a;
- if (a != 180) l->cos_spot_cutoff=cos(a * M_PI / 180.0);
- }
- break;
- case GL_CONSTANT_ATTENUATION:
- l->attenuation[0]=v.v[0];
- break;
- case GL_LINEAR_ATTENUATION:
- l->attenuation[1]=v.v[0];
- break;
- case GL_QUADRATIC_ATTENUATION:
- l->attenuation[2]=v.v[0];
- break;
- default:
- assert(0);
- }
-}
-
+ l->position = pos;
-void glopLightModel(GLContext *c,GLParam *p)
-{
- GLint pname=p[1].i;
- GLfloat *v=&p[2].f;
- GLint i;
-
- switch(pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- for(i=0;i<4;i++)
- c->ambient_light_model.v[i] = p[2+i].f;
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- c->local_light_model=(GLint)v[0];
- break;
- case GL_LIGHT_MODEL_TWO_SIDE:
- c->light_model_two_side = (GLint)v[0];
- break;
- default:
- tgl_warning("glopLightModel: illegal pname: 0x%x\n", pname);
- //assert(0);
- break;
- }
+ if (l->position.v[3] == 0) {
+ l->norm_position.X = pos.X;
+ l->norm_position.Y = pos.Y;
+ l->norm_position.Z = pos.Z;
+ gl_V3_Norm(&l->norm_position);
+ }
+ } break;
+ case GL_SPOT_DIRECTION:
+ for (i = 0; i < 3; i++) {
+ l->spot_direction.v[i] = v.v[i];
+ l->norm_spot_direction.v[i] = v.v[i];
+ }
+ gl_V3_Norm(&l->norm_spot_direction);
+ break;
+ case GL_SPOT_EXPONENT:
+ l->spot_exponent = v.v[0];
+ break;
+ case GL_SPOT_CUTOFF: {
+ GLfloat a = v.v[0];
+ assert(a == 180 || (a >= 0 && a <= 90));
+ l->spot_cutoff = a;
+ if (a != 180)
+ l->cos_spot_cutoff = cos(a * M_PI / 180.0);
+ } break;
+ case GL_CONSTANT_ATTENUATION:
+ l->attenuation[0] = v.v[0];
+ break;
+ case GL_LINEAR_ATTENUATION:
+ l->attenuation[1] = v.v[0];
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ l->attenuation[2] = v.v[0];
+ break;
+ default:
+ assert(0);
+ }
}
+void glopLightModel(GLContext* c, GLParam* p) {
+ GLint pname = p[1].i;
+ GLfloat* v = &p[2].f;
+ GLint i;
-static inline GLfloat clampf(GLfloat a,GLfloat min,GLfloat max)
-{
- if (a<min) return min;
- else if (a>max) return max;
- else return a;
+ switch (pname) {
+ case GL_LIGHT_MODEL_AMBIENT:
+ for (i = 0; i < 4; i++)
+ c->ambient_light_model.v[i] = p[2 + i].f;
+ break;
+ case GL_LIGHT_MODEL_LOCAL_VIEWER:
+ c->local_light_model = (GLint)v[0];
+ break;
+ case GL_LIGHT_MODEL_TWO_SIDE:
+ c->light_model_two_side = (GLint)v[0];
+ break;
+ default:
+ tgl_warning("glopLightModel: illegal pname: 0x%x\n", pname);
+ // assert(0);
+ break;
+ }
}
-void gl_enable_disable_light(GLContext *c,GLint light,GLint v)
-{
- GLLight *l=&c->lights[light];
- if (v && !l->enabled) {
- l->enabled=1;
- l->next=c->first_light;
- c->first_light=l;
- l->prev=NULL;
- } else if (!v && l->enabled) {
- l->enabled=0;
- if (l->prev == NULL) c->first_light=l->next;
- else l->prev->next=l->next;
- if (l->next != NULL) l->next->prev=l->prev;
- }
+static inline GLfloat clampf(GLfloat a, GLfloat min, GLfloat max) {
+ if (a < min)
+ return min;
+ else if (a > max)
+ return max;
+ else
+ return a;
}
-//FEATURES
-int zEnableSpecular = 1; //Enable specular lighting
-void glSetEnableSpecular(GLint s){
- zEnableSpecular = s;
+void gl_enable_disable_light(GLContext* c, GLint light, GLint v) {
+ GLLight* l = &c->lights[light];
+ if (v && !l->enabled) {
+ l->enabled = 1;
+ l->next = c->first_light;
+ c->first_light = l;
+ l->prev = NULL;
+ } else if (!v && l->enabled) {
+ l->enabled = 0;
+ if (l->prev == NULL)
+ c->first_light = l->next;
+ else
+ l->prev->next = l->next;
+ if (l->next != NULL)
+ l->next->prev = l->prev;
+ }
}
+
+// FEATURES
+int zEnableSpecular = 1; // Enable specular lighting
+void glSetEnableSpecular(GLint s) { zEnableSpecular = s; }
/* non optimized lightening model */
-void gl_shade_vertex(GLContext *c,GLVertex *v)
-{
- GLfloat R,G,B,A;
- GLMaterial *m;
- GLLight *l;
- V3 n,s,d;
- GLfloat dist,tmp,att,dot,dot_spot,dot_spec;
- GLint twoside = c->light_model_two_side;
+void gl_shade_vertex(GLContext* c, GLVertex* v) {
+ GLfloat R, G, B, A;
+ GLMaterial* m;
+ GLLight* l;
+ V3 n, s, d;
+ GLfloat dist, tmp, att, dot, dot_spot, dot_spec;
+ GLint twoside = c->light_model_two_side;
- m=&c->materials[0];
+ m = &c->materials[0];
- n.X=v->normal.X;
- n.Y=v->normal.Y;
- n.Z=v->normal.Z;
+ n.X = v->normal.X;
+ n.Y = v->normal.Y;
+ n.Z = v->normal.Z;
- R=m->emission.v[0]+m->ambient.v[0]*c->ambient_light_model.v[0];
- G=m->emission.v[1]+m->ambient.v[1]*c->ambient_light_model.v[1];
- B=m->emission.v[2]+m->ambient.v[2]*c->ambient_light_model.v[2];
- A=clampf(m->diffuse.v[3],0,1);
+ R = m->emission.v[0] + m->ambient.v[0] * c->ambient_light_model.v[0];
+ G = m->emission.v[1] + m->ambient.v[1] * c->ambient_light_model.v[1];
+ B = m->emission.v[2] + m->ambient.v[2] * c->ambient_light_model.v[2];
+ A = clampf(m->diffuse.v[3], 0, 1);
- for(l=c->first_light;l!=NULL;l=l->next) {
- GLfloat lR,lB,lG;
-
- /* ambient */
- lR=l->ambient.v[0] * m->ambient.v[0];
- lG=l->ambient.v[1] * m->ambient.v[1];
- lB=l->ambient.v[2] * m->ambient.v[2];
+ for (l = c->first_light; l != NULL; l = l->next) {
+ GLfloat lR, lB, lG;
- if (l->position.v[3] == 0) {
- /* light at infinity */
- //Fixed by Gek, it used to use the unnormalized position?
- d.X=l->norm_position.v[0];
- d.Y=l->norm_position.v[1];
- d.Z=l->norm_position.v[2];
- att=1;
- } else {
- /* distance attenuation */
- d.X=l->position.v[0]-v->ec.v[0];
- d.Y=l->position.v[1]-v->ec.v[1];
- d.Z=l->position.v[2]-v->ec.v[2];
- dist=sqrt(d.X*d.X+d.Y*d.Y+d.Z*d.Z);
- if (dist>1E-3) {
- tmp=1/dist;
- d.X*=tmp;
- d.Y*=tmp;
- d.Z*=tmp;
- }
- att=1.0f/(l->attenuation[0]+dist*(l->attenuation[1]+
- dist*l->attenuation[2]));
- }
- dot=d.X*n.X+d.Y*n.Y+d.Z*n.Z;
- if (twoside && dot < 0) dot = -dot;
- if (dot>0) {
- /* diffuse light */
- lR+=dot * l->diffuse.v[0] * m->diffuse.v[0];
- lG+=dot * l->diffuse.v[1] * m->diffuse.v[1];
- lB+=dot * l->diffuse.v[2] * m->diffuse.v[2];
+ /* ambient */
+ lR = l->ambient.v[0] * m->ambient.v[0];
+ lG = l->ambient.v[1] * m->ambient.v[1];
+ lB = l->ambient.v[2] * m->ambient.v[2];
- /* spot light */
- if (l->spot_cutoff != 180) {
- dot_spot=-(d.X*l->norm_spot_direction.v[0]+
- d.Y*l->norm_spot_direction.v[1]+
- d.Z*l->norm_spot_direction.v[2]);
- if (twoside && dot_spot < 0) dot_spot = -dot_spot;
- if (dot_spot < l->cos_spot_cutoff) {
- /* no contribution */
- continue;
- } else {
- /* TODO: optimize */
- if (l->spot_exponent > 0) {
- att=att*pow(dot_spot,l->spot_exponent);
- }
- }
- //GEK SAYS TO REMOVE THIS
- //printf("\nThis should not be being called.");
- }
+ if (l->position.v[3] == 0) {
+ /* light at infinity */
+ // Fixed by Gek, it used to use the unnormalized position?
+ d.X = l->norm_position.v[0];
+ d.Y = l->norm_position.v[1];
+ d.Z = l->norm_position.v[2];
+ att = 1;
+ } else {
+ /* distance attenuation */
+ d.X = l->position.v[0] - v->ec.v[0];
+ d.Y = l->position.v[1] - v->ec.v[1];
+ d.Z = l->position.v[2] - v->ec.v[2];
+ dist = sqrt(d.X * d.X + d.Y * d.Y + d.Z * d.Z);
+ if (dist > 1E-3) {
+ tmp = 1 / dist;
+ d.X *= tmp;
+ d.Y *= tmp;
+ d.Z *= tmp;
+ }
+ att = 1.0f / (l->attenuation[0] + dist * (l->attenuation[1] + dist * l->attenuation[2]));
+ }
+ dot = d.X * n.X + d.Y * n.Y + d.Z * n.Z;
+ if (twoside && dot < 0)
+ dot = -dot;
+ if (dot > 0) {
+ /* diffuse light */
+ lR += dot * l->diffuse.v[0] * m->diffuse.v[0];
+ lG += dot * l->diffuse.v[1] * m->diffuse.v[1];
+ lB += dot * l->diffuse.v[2] * m->diffuse.v[2];
- /* specular light */
- if (zEnableSpecular){
- if (c->local_light_model) {
- V3 vcoord;
- vcoord.X=v->ec.X;
- vcoord.Y=v->ec.Y;
- vcoord.Z=v->ec.Z;
- gl_V3_Norm(&vcoord);
- s.X=d.X-vcoord.X;
- s.Y=d.Y-vcoord.X;
- s.Z=d.Z-vcoord.X;
- } else {
- s.X=d.X;
- s.Y=d.Y;
- s.Z=d.Z+1.0;
- }
- dot_spec=n.X*s.X + n.Y*s.Y + n.Z*s.Z;
- if (twoside && dot_spec < 0) dot_spec = -dot_spec;
- if (dot_spec>0) {
- GLSpecBuf *specbuf;
- GLint idx;
- tmp=sqrt(s.X*s.X+s.Y*s.Y+s.Z*s.Z);
- if (tmp > 1E-3) {
- dot_spec=dot_spec / tmp;
- }
-
- /* TODO: optimize */
- /* testing specular buffer code */
- /* dot_spec= pow(dot_spec,m->shininess);*/
- specbuf = specbuf_get_buffer(c, m->shininess_i, m->shininess);
- idx = (GLint)(dot_spec*SPECULAR_BUFFER_SIZE);
- if (idx > SPECULAR_BUFFER_SIZE) idx = SPECULAR_BUFFER_SIZE;
- dot_spec = specbuf->buf[idx];
- lR+=dot_spec * l->specular.v[0] * m->specular.v[0];
- lG+=dot_spec * l->specular.v[1] * m->specular.v[1];
- lB+=dot_spec * l->specular.v[2] * m->specular.v[2];
- }//EOF if dot_spec>0
- }//EOF zEnableSpecular
- } //EOF if dot > 0
+ /* spot light */
+ if (l->spot_cutoff != 180) {
+ dot_spot = -(d.X * l->norm_spot_direction.v[0] + d.Y * l->norm_spot_direction.v[1] + d.Z * l->norm_spot_direction.v[2]);
+ if (twoside && dot_spot < 0)
+ dot_spot = -dot_spot;
+ if (dot_spot < l->cos_spot_cutoff) {
+ /* no contribution */
+ continue;
+ } else {
+ /* TODO: optimize */
+ if (l->spot_exponent > 0) {
+ att = att * pow(dot_spot, l->spot_exponent);
+ }
+ }
+ // GEK SAYS TO REMOVE THIS
+ // printf("\nThis should not be being called.");
+ }
- R+=att * lR;
- G+=att * lG;
- B+=att * lB;
- } //End of light loop.
+ /* specular light */
+ if (zEnableSpecular) {
+ if (c->local_light_model) {
+ V3 vcoord;
+ vcoord.X = v->ec.X;
+ vcoord.Y = v->ec.Y;
+ vcoord.Z = v->ec.Z;
+ gl_V3_Norm(&vcoord);
+ s.X = d.X - vcoord.X;
+ s.Y = d.Y - vcoord.X;
+ s.Z = d.Z - vcoord.X;
+ } else {
+ s.X = d.X;
+ s.Y = d.Y;
+ s.Z = d.Z + 1.0;
+ }
+ dot_spec = n.X * s.X + n.Y * s.Y + n.Z * s.Z;
+ if (twoside && dot_spec < 0)
+ dot_spec = -dot_spec;
+ if (dot_spec > 0) {
+ GLSpecBuf* specbuf;
+ GLint idx;
+ tmp = sqrt(s.X * s.X + s.Y * s.Y + s.Z * s.Z);
+ if (tmp > 1E-3) {
+ dot_spec = dot_spec / tmp;
+ }
- v->color.v[0]=clampf(R,0,1);
- v->color.v[1]=clampf(G,0,1);
- v->color.v[2]=clampf(B,0,1);
- v->color.v[3]=A;
-}
+ /* TODO: optimize */
+ /* testing specular buffer code */
+ /* dot_spec= pow(dot_spec,m->shininess);*/
+ specbuf = specbuf_get_buffer(c, m->shininess_i, m->shininess);
+ idx = (GLint)(dot_spec * SPECULAR_BUFFER_SIZE);
+ if (idx > SPECULAR_BUFFER_SIZE)
+ idx = SPECULAR_BUFFER_SIZE;
+ dot_spec = specbuf->buf[idx];
+ lR += dot_spec * l->specular.v[0] * m->specular.v[0];
+ lG += dot_spec * l->specular.v[1] * m->specular.v[1];
+ lB += dot_spec * l->specular.v[2] * m->specular.v[2];
+ } // EOF if dot_spec>0
+ } // EOF zEnableSpecular
+ } // EOF if dot > 0
+ R += att * lR;
+ G += att * lG;
+ B += att * lB;
+ } // End of light loop.
+
+ v->color.v[0] = clampf(R, 0, 1);
+ v->color.v[1] = clampf(G, 0, 1);
+ v->color.v[2] = clampf(B, 0, 1);
+ v->color.v[3] = A;
+}
--- a/src/list.c
+++ b/src/list.c
@@ -1,264 +1,233 @@
#include "zgl.h"
-static char *op_table_str[]=
-{
-#define ADD_OP(a,b,c) "gl" #a " " #c,
+static char* op_table_str[] = {
+#define ADD_OP(a, b, c) "gl" #a " " #c,
#include "opinfo.h"
};
-static void (*op_table_func[])(GLContext *,GLParam *)=
-{
-#define ADD_OP(a,b,c) glop ## a ,
+static void (*op_table_func[])(GLContext*, GLParam*) = {
+#define ADD_OP(a, b, c) glop##a,
#include "opinfo.h"
};
-static GLint op_table_size[]=
-{
-#define ADD_OP(a,b,c) b + 1 ,
+static GLint op_table_size[] = {
+#define ADD_OP(a, b, c) b + 1,
#include "opinfo.h"
};
+GLContext* gl_get_context(void) { return gl_ctx; }
-GLContext *gl_get_context(void)
-{
- return gl_ctx;
-}
+static GLList* find_list(GLContext* c, GLuint list) { return c->shared_state.lists[list]; }
-static GLList *find_list(GLContext *c,GLuint list)
-{
- return c->shared_state.lists[list];
-}
+static void delete_list(GLContext* c, GLint list) {
+ GLParamBuffer *pb, *pb1;
+ GLList* l;
+ l = find_list(c, list);
+ if (l == NULL)
+ puts("\nAttempted to delete NULL list!!!!\n");
+ assert(l != NULL);
-static void delete_list(GLContext *c,GLint list)
-{
- GLParamBuffer *pb,*pb1;
- GLList *l;
+ /* free param buffer */
+ pb = l->first_op_buffer;
+ while (pb != NULL) {
+ pb1 = pb->next;
+ gl_free(pb);
+ pb = pb1;
+ }
- l=find_list(c,list);
- if(l==NULL) puts("\nAttempted to delete NULL list!!!!\n");
- assert(l != NULL);
-
- /* free param buffer */
- pb=l->first_op_buffer;
- while (pb!=NULL) {
- pb1=pb->next;
- gl_free(pb);
- pb=pb1;
- }
-
- gl_free(l);
- c->shared_state.lists[list]=NULL;
+ gl_free(l);
+ c->shared_state.lists[list] = NULL;
}
-void glDeleteLists(GLuint list, GLuint range){
- for(GLuint i = 0; i < list + range; i++)
- glDeleteList(list+i);
+void glDeleteLists(GLuint list, GLuint range) {
+ for (GLuint i = 0; i < list + range; i++)
+ glDeleteList(list + i);
}
-void glDeleteList(GLuint list){
- delete_list(gl_get_context(), list);
-}
+void glDeleteList(GLuint list) { delete_list(gl_get_context(), list); }
-static GLList *alloc_list(GLContext *c,GLint list)
-{
- GLList *l;
- GLParamBuffer *ob;
+static GLList* alloc_list(GLContext* c, GLint list) {
+ GLList* l;
+ GLParamBuffer* ob;
- l=gl_zalloc(sizeof(GLList));
- ob=gl_zalloc(sizeof(GLParamBuffer));
+ l = gl_zalloc(sizeof(GLList));
+ ob = gl_zalloc(sizeof(GLParamBuffer));
- ob->next=NULL;
- l->first_op_buffer=ob;
-
- ob->ops[0].op=OP_EndList;
+ ob->next = NULL;
+ l->first_op_buffer = ob;
- c->shared_state.lists[list]=l;
- return l;
+ ob->ops[0].op = OP_EndList;
+
+ c->shared_state.lists[list] = l;
+ return l;
}
+void gl_print_op(FILE* f, GLParam* p) {
+ GLint op;
+ char* s;
-void gl_print_op(FILE *f,GLParam *p)
-{
- GLint op;
- char *s;
-
- op=p[0].op;
- p++;
- s=op_table_str[op];
- while (*s != 0) {
- if (*s == '%') {
- s++;
- switch (*s++) {
- case 'f':
- fprintf(f,"%g",p[0].f);
- break;
- default:
- fprintf(f,"%d",p[0].i);
- break;
- }
- p++;
- } else {
- fputc(*s,f);
- s++;
- }
- }
- fprintf(f,"\n");
+ op = p[0].op;
+ p++;
+ s = op_table_str[op];
+ while (*s != 0) {
+ if (*s == '%') {
+ s++;
+ switch (*s++) {
+ case 'f':
+ fprintf(f, "%g", p[0].f);
+ break;
+ default:
+ fprintf(f, "%d", p[0].i);
+ break;
+ }
+ p++;
+ } else {
+ fputc(*s, f);
+ s++;
+ }
+ }
+ fprintf(f, "\n");
}
+void gl_compile_op(GLContext* c, GLParam* p) {
+ GLint op, op_size;
+ GLParamBuffer *ob, *ob1;
+ GLint index, i;
-void gl_compile_op(GLContext *c,GLParam *p)
-{
- GLint op,op_size;
- GLParamBuffer *ob,*ob1;
- GLint index,i;
+ op = p[0].op;
+ op_size = op_table_size[op];
+ index = c->current_op_buffer_index;
+ ob = c->current_op_buffer;
- op=p[0].op;
- op_size=op_table_size[op];
- index=c->current_op_buffer_index;
- ob=c->current_op_buffer;
+ /* we should be able to add a NextBuffer opcode */
+ if ((index + op_size) > (OP_BUFFER_MAX_SIZE - 2)) {
- /* we should be able to add a NextBuffer opcode */
- if ((index + op_size) > (OP_BUFFER_MAX_SIZE-2)) {
+ ob1 = gl_zalloc(sizeof(GLParamBuffer));
+ ob1->next = NULL;
- ob1=gl_zalloc(sizeof(GLParamBuffer));
- ob1->next=NULL;
+ ob->next = ob1;
+ ob->ops[index].op = OP_NextBuffer;
+ ob->ops[index + 1].p = (void*)ob1;
- ob->next=ob1;
- ob->ops[index].op=OP_NextBuffer;
- ob->ops[index+1].p=(void *)ob1;
+ c->current_op_buffer = ob1;
+ ob = ob1;
+ index = 0;
+ }
- c->current_op_buffer=ob1;
- ob=ob1;
- index=0;
- }
-
- for(i=0;i<op_size;i++) {
- ob->ops[index]=p[i];
- index++;
- }
- c->current_op_buffer_index=index;
+ for (i = 0; i < op_size; i++) {
+ ob->ops[index] = p[i];
+ index++;
+ }
+ c->current_op_buffer_index = index;
}
-void gl_add_op(GLParam *p)
-{
- GLContext *c=gl_get_context();
- GLint op;
+void gl_add_op(GLParam* p) {
+ GLContext* c = gl_get_context();
+ GLint op;
- op=p[0].op;
- if (c->exec_flag) {
- op_table_func[op](c,p);
- }
- if (c->compile_flag) {
- gl_compile_op(c,p);
- }
- if (c->print_flag) {
- gl_print_op(stderr,p);
- }
+ op = p[0].op;
+ if (c->exec_flag) {
+ op_table_func[op](c, p);
+ }
+ if (c->compile_flag) {
+ gl_compile_op(c, p);
+ }
+ if (c->print_flag) {
+ gl_print_op(stderr, p);
+ }
}
/* this opcode is never called directly */
-void glopEndList(GLContext *c,GLParam *p)
-{
- assert(0);
-}
+void glopEndList(GLContext* c, GLParam* p) { assert(0); }
/* this opcode is never called directly */
-void glopNextBuffer(GLContext *c,GLParam *p)
-{
- assert(0);
-}
+void glopNextBuffer(GLContext* c, GLParam* p) { assert(0); }
+void glopCallList(GLContext* c, GLParam* p) {
+ GLList* l;
+ GLint list, op;
-void glopCallList(GLContext *c,GLParam *p)
-{
- GLList *l;
- GLint list,op;
+ list = p[1].ui;
+ l = find_list(c, list);
+ if (l == NULL)
+ gl_fatal_error("list %d not defined", list);
+ p = l->first_op_buffer->ops;
- list=p[1].ui;
- l=find_list(c,list);
- if (l == NULL) gl_fatal_error("list %d not defined",list);
- p=l->first_op_buffer->ops;
-
- while (1) {
- op=p[0].op;
- if (op == OP_EndList) break;
- if (op == OP_NextBuffer) {
- p=(GLParam *)p[1].p;
- } else {
- op_table_func[op](c,p);
- p+=op_table_size[op];
- }
- }
+ while (1) {
+ op = p[0].op;
+ if (op == OP_EndList)
+ break;
+ if (op == OP_NextBuffer) {
+ p = (GLParam*)p[1].p;
+ } else {
+ op_table_func[op](c, p);
+ p += op_table_size[op];
+ }
+ }
}
+void glNewList(GLuint list, GLint mode) {
+ GLList* l;
+ GLContext* c = gl_get_context();
+ assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE);
+ assert(c->compile_flag == 0);
-void glNewList(GLuint list,GLint mode)
-{
- GLList *l;
- GLContext *c=gl_get_context();
+ l = find_list(c, list);
+ if (l != NULL)
+ delete_list(c, list);
+ l = alloc_list(c, list);
- assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE);
- assert(c->compile_flag == 0);
+ c->current_op_buffer = l->first_op_buffer;
+ c->current_op_buffer_index = 0;
- l=find_list(c,list);
- if (l!=NULL) delete_list(c,list);
- l=alloc_list(c,list);
-
- c->current_op_buffer=l->first_op_buffer;
- c->current_op_buffer_index=0;
-
- c->compile_flag=1;
- c->exec_flag=(mode == GL_COMPILE_AND_EXECUTE);
+ c->compile_flag = 1;
+ c->exec_flag = (mode == GL_COMPILE_AND_EXECUTE);
}
-void glEndList(void)
-{
- GLContext *c=gl_get_context();
- GLParam p[1];
+void glEndList(void) {
+ GLContext* c = gl_get_context();
+ GLParam p[1];
- assert(c->compile_flag == 1);
-
- /* end of list */
- p[0].op=OP_EndList;
- gl_compile_op(c,p);
-
- c->compile_flag=0;
- c->exec_flag=1;
+ assert(c->compile_flag == 1);
+
+ /* end of list */
+ p[0].op = OP_EndList;
+ gl_compile_op(c, p);
+
+ c->compile_flag = 0;
+ c->exec_flag = 1;
}
-int glIsList(GLuint list)
-{
- GLContext *c=gl_get_context();
- GLList *l;
- l=find_list(c,list);
- return (l != NULL);
+int glIsList(GLuint list) {
+ GLContext* c = gl_get_context();
+ GLList* l;
+ l = find_list(c, list);
+ return (l != NULL);
}
-GLuint glGenLists(GLint range)
-{
- GLContext *c=gl_get_context();
- GLint count,i,list;
- GLList **lists;
+GLuint glGenLists(GLint range) {
+ GLContext* c = gl_get_context();
+ GLint count, i, list;
+ GLList** lists;
- lists=c->shared_state.lists;
- count=0;
- for(i=0;i<MAX_DISPLAY_LISTS;i++) {
- if (lists[i]==NULL) {
- count++;
- if (count == range) {
- list=i-range+1;
- for(i=0;i<range;i++) {
- alloc_list(c,list+i);
+ lists = c->shared_state.lists;
+ count = 0;
+ for (i = 0; i < MAX_DISPLAY_LISTS; i++) {
+ if (lists[i] == NULL) {
+ count++;
+ if (count == range) {
+ list = i - range + 1;
+ for (i = 0; i < range; i++) {
+ alloc_list(c, list + i);
+ }
+ return list;
+ }
+ } else {
+ count = 0;
+ }
}
- return list;
- }
- } else {
- count=0;
- }
- }
- return 0;
+ return 0;
}
-
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -1,241 +1,243 @@
#include "zgl.h"
-void gl_print_matrix( const GLfloat *m)
-{
- GLint i;
+void gl_print_matrix(const GLfloat* m) {
+ GLint i;
- for (i=0;i<4;i++) {
- fprintf(stderr,"%f %f %f %f\n", m[i], m[4+i], m[8+i], m[12+i] );
- }
+ for (i = 0; i < 4; i++) {
+ fprintf(stderr, "%f %f %f %f\n", m[i], m[4 + i], m[8 + i], m[12 + i]);
+ }
}
-static inline void gl_matrix_update(GLContext *c)
-{
- c->matrix_model_projection_updated=(c->matrix_mode<=1);
-}
+static inline void gl_matrix_update(GLContext* c) { c->matrix_model_projection_updated = (c->matrix_mode <= 1); }
-
-void glopMatrixMode(GLContext *c,GLParam *p)
-{
- GLint mode=p[1].i;
- switch(mode) {
- case GL_MODELVIEW:
- c->matrix_mode=0;
- break;
- case GL_PROJECTION:
- c->matrix_mode=1;
- break;
- case GL_TEXTURE:
- c->matrix_mode=2;
- break;
- default:
- assert(0);
- }
+void glopMatrixMode(GLContext* c, GLParam* p) {
+ GLint mode = p[1].i;
+ switch (mode) {
+ case GL_MODELVIEW:
+ c->matrix_mode = 0;
+ break;
+ case GL_PROJECTION:
+ c->matrix_mode = 1;
+ break;
+ case GL_TEXTURE:
+ c->matrix_mode = 2;
+ break;
+ default:
+ assert(0);
+ }
}
-void glopLoadMatrix(GLContext *c,GLParam *p)
-{
- M4 *m;
- GLint i;
-
- GLParam *q;
+void glopLoadMatrix(GLContext* c, GLParam* p) {
+ M4* m;
+ GLint i;
- m=c->matrix_stack_ptr[c->matrix_mode];
- q=p+1;
+ GLParam* q;
- for(i=0;i<4;i++) {
- m->m[0][i]=q[0].f;
- m->m[1][i]=q[1].f;
- m->m[2][i]=q[2].f;
- m->m[3][i]=q[3].f;
- q+=4;
- }
+ m = c->matrix_stack_ptr[c->matrix_mode];
+ q = p + 1;
- gl_matrix_update(c);
+ for (i = 0; i < 4; i++) {
+ m->m[0][i] = q[0].f;
+ m->m[1][i] = q[1].f;
+ m->m[2][i] = q[2].f;
+ m->m[3][i] = q[3].f;
+ q += 4;
+ }
+
+ gl_matrix_update(c);
}
-void glopLoadIdentity(GLContext *c,GLParam *p)
-{
+void glopLoadIdentity(GLContext* c, GLParam* p) {
- gl_M4_Id(c->matrix_stack_ptr[c->matrix_mode]);
+ gl_M4_Id(c->matrix_stack_ptr[c->matrix_mode]);
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
-void glopMultMatrix(GLContext *c,GLParam *p)
-{
- M4 m;
- GLint i;
+void glopMultMatrix(GLContext* c, GLParam* p) {
+ M4 m;
+ GLint i;
- GLParam *q;
- q=p+1;
+ GLParam* q;
+ q = p + 1;
- for(i=0;i<4;i++) {
- m.m[0][i]=q[0].f;
- m.m[1][i]=q[1].f;
- m.m[2][i]=q[2].f;
- m.m[3][i]=q[3].f;
- q+=4;
- }
+ for (i = 0; i < 4; i++) {
+ m.m[0][i] = q[0].f;
+ m.m[1][i] = q[1].f;
+ m.m[2][i] = q[2].f;
+ m.m[3][i] = q[3].f;
+ q += 4;
+ }
- gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);
+ gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode], &m);
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
+void glopPushMatrix(GLContext* c, GLParam* p) {
+ GLint n = c->matrix_mode;
+ M4* m;
-void glopPushMatrix(GLContext *c,GLParam *p)
-{
- GLint n=c->matrix_mode;
- M4 *m;
+ assert((c->matrix_stack_ptr[n] - c->matrix_stack[n] + 1) < c->matrix_stack_depth_max[n]);
- assert( (c->matrix_stack_ptr[n] - c->matrix_stack[n] + 1 )
- < c->matrix_stack_depth_max[n] );
+ m = ++c->matrix_stack_ptr[n];
- m=++c->matrix_stack_ptr[n];
-
- gl_M4_Move(&m[0],&m[-1]);
+ gl_M4_Move(&m[0], &m[-1]);
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
-void glopPopMatrix(GLContext *c,GLParam *p)
-{
- GLint n=c->matrix_mode;
+void glopPopMatrix(GLContext* c, GLParam* p) {
+ GLint n = c->matrix_mode;
- assert( c->matrix_stack_ptr[n] > c->matrix_stack[n] );
- c->matrix_stack_ptr[n]--;
- gl_matrix_update(c);
+ assert(c->matrix_stack_ptr[n] > c->matrix_stack[n]);
+ c->matrix_stack_ptr[n]--;
+ gl_matrix_update(c);
}
+void glopRotate(GLContext* c, GLParam* p) {
+ M4 m;
+ GLfloat u[3];
+ GLfloat angle;
+ GLint dir_code;
-void glopRotate(GLContext *c,GLParam *p)
-{
- M4 m;
- GLfloat u[3];
- GLfloat angle;
- GLint dir_code;
+ angle = p[1].f * M_PI / 180.0;
+ u[0] = p[2].f;
+ u[1] = p[3].f;
+ u[2] = p[4].f;
- angle = p[1].f * M_PI / 180.0;
- u[0]=p[2].f;
- u[1]=p[3].f;
- u[2]=p[4].f;
+ /* simple case detection */
+ dir_code = ((u[0] != 0) << 2) | ((u[1] != 0) << 1) | (u[2] != 0);
- /* simple case detection */
- dir_code = ((u[0] != 0)<<2) | ((u[1] != 0)<<1) | (u[2] != 0);
+ switch (dir_code) {
+ case 0:
+ gl_M4_Id(&m);
+ break;
+ case 4:
+ if (u[0] < 0)
+ angle = -angle;
+ gl_M4_Rotate(&m, angle, 0);
+ break;
+ case 2:
+ if (u[1] < 0)
+ angle = -angle;
+ gl_M4_Rotate(&m, angle, 1);
+ break;
+ case 1:
+ if (u[2] < 0)
+ angle = -angle;
+ gl_M4_Rotate(&m, angle, 2);
+ break;
+ default: {
+ GLfloat cost, sint;
- switch(dir_code) {
- case 0:
- gl_M4_Id(&m);
- break;
- case 4:
- if (u[0] < 0) angle=-angle;
- gl_M4_Rotate(&m,angle,0);
- break;
- case 2:
- if (u[1] < 0) angle=-angle;
- gl_M4_Rotate(&m,angle,1);
- break;
- case 1:
- if (u[2] < 0) angle=-angle;
- gl_M4_Rotate(&m,angle,2);
- break;
- default:
- {
- GLfloat cost, sint;
+ /* normalize vector */
+ GLfloat len = u[0] * u[0] + u[1] * u[1] + u[2] * u[2];
+ if (len == 0.0f)
+ return;
+ len = 1.0f / sqrt(len);
+ u[0] *= len;
+ u[1] *= len;
+ u[2] *= len;
- /* normalize vector */
- GLfloat len = u[0]*u[0]+u[1]*u[1]+u[2]*u[2];
- if (len == 0.0f) return;
- len = 1.0f / sqrt(len);
- u[0] *= len;
- u[1] *= len;
- u[2] *= len;
+ /* store cos and sin values */
+ cost = cos(angle);
+ sint = sin(angle);
- /* store cos and sin values */
- cost=cos(angle);
- sint=sin(angle);
+ /* fill in the values */
+ m.m[3][0] = m.m[3][1] = m.m[3][2] = m.m[0][3] = m.m[1][3] = m.m[2][3] = 0.0f;
+ m.m[3][3] = 1.0f;
- /* fill in the values */
- m.m[3][0]=m.m[3][1]=m.m[3][2]=
- m.m[0][3]=m.m[1][3]=m.m[2][3]=0.0f;
- m.m[3][3]=1.0f;
+ /* do the math */
+ m.m[0][0] = u[0] * u[0] + cost * (1 - u[0] * u[0]);
+ m.m[1][0] = u[0] * u[1] * (1 - cost) - u[2] * sint;
+ m.m[2][0] = u[2] * u[0] * (1 - cost) + u[1] * sint;
+ m.m[0][1] = u[0] * u[1] * (1 - cost) + u[2] * sint;
+ m.m[1][1] = u[1] * u[1] + cost * (1 - u[1] * u[1]);
+ m.m[2][1] = u[1] * u[2] * (1 - cost) - u[0] * sint;
+ m.m[0][2] = u[2] * u[0] * (1 - cost) - u[1] * sint;
+ m.m[1][2] = u[1] * u[2] * (1 - cost) + u[0] * sint;
+ m.m[2][2] = u[2] * u[2] + cost * (1 - u[2] * u[2]);
+ }
+ }
- /* do the math */
- m.m[0][0]=u[0]*u[0]+cost*(1-u[0]*u[0]);
- m.m[1][0]=u[0]*u[1]*(1-cost)-u[2]*sint;
- m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint;
- m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint;
- m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1]);
- m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint;
- m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint;
- m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint;
- m.m[2][2]=u[2]*u[2]+cost*(1-u[2]*u[2]);
- }
- }
+ gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode], &m);
- gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);
-
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
-void glopScale(GLContext *c,GLParam *p)
-{
- GLfloat *m;
- GLfloat x=p[1].f,y=p[2].f,z=p[3].f;
+void glopScale(GLContext* c, GLParam* p) {
+ GLfloat* m;
+ GLfloat x = p[1].f, y = p[2].f, z = p[3].f;
- m=&c->matrix_stack_ptr[c->matrix_mode]->m[0][0];
+ m = &c->matrix_stack_ptr[c->matrix_mode]->m[0][0];
- m[0] *= x; m[1] *= y; m[2] *= z;
- m[4] *= x; m[5] *= y; m[6] *= z;
- m[8] *= x; m[9] *= y; m[10] *= z;
- m[12] *= x; m[13] *= y; m[14] *= z;
- gl_matrix_update(c);
+ m[0] *= x;
+ m[1] *= y;
+ m[2] *= z;
+ m[4] *= x;
+ m[5] *= y;
+ m[6] *= z;
+ m[8] *= x;
+ m[9] *= y;
+ m[10] *= z;
+ m[12] *= x;
+ m[13] *= y;
+ m[14] *= z;
+ gl_matrix_update(c);
}
-void glopTranslate(GLContext *c,GLParam *p)
-{
- GLfloat *m;
- GLfloat x=p[1].f,y=p[2].f,z=p[3].f;
+void glopTranslate(GLContext* c, GLParam* p) {
+ GLfloat* m;
+ GLfloat x = p[1].f, y = p[2].f, z = p[3].f;
- m=&c->matrix_stack_ptr[c->matrix_mode]->m[0][0];
+ m = &c->matrix_stack_ptr[c->matrix_mode]->m[0][0];
- m[3] = m[0] * x + m[1] * y + m[2] * z + m[3];
- m[7] = m[4] * x + m[5] * y + m[6] * z + m[7];
- m[11] = m[8] * x + m[9] * y + m[10] * z + m[11];
- m[15] = m[12] * x + m[13] * y + m[14] * z + m[15];
+ m[3] = m[0] * x + m[1] * y + m[2] * z + m[3];
+ m[7] = m[4] * x + m[5] * y + m[6] * z + m[7];
+ m[11] = m[8] * x + m[9] * y + m[10] * z + m[11];
+ m[15] = m[12] * x + m[13] * y + m[14] * z + m[15];
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
+void glopFrustum(GLContext* c, GLParam* p) {
+ GLfloat* r;
+ M4 m;
+ GLfloat left = p[1].f;
+ GLfloat right = p[2].f;
+ GLfloat bottom = p[3].f;
+ GLfloat top = p[4].f;
+ GLfloat near = p[5].f;
+ GLfloat farp = p[6].f;
+ GLfloat x, y, A, B, C, D;
-void glopFrustum(GLContext *c,GLParam *p)
-{
- GLfloat *r;
- M4 m;
- GLfloat left=p[1].f;
- GLfloat right=p[2].f;
- GLfloat bottom=p[3].f;
- GLfloat top=p[4].f;
- GLfloat near=p[5].f;
- GLfloat farp=p[6].f;
- GLfloat x,y,A,B,C,D;
+ x = (2.0 * near) / (right - left);
+ y = (2.0 * near) / (top - bottom);
+ A = (right + left) / (right - left);
+ B = (top + bottom) / (top - bottom);
+ C = -(farp + near) / (farp - near);
+ D = -(2.0 * farp * near) / (farp - near);
- x = (2.0*near) / (right-left);
- y = (2.0*near) / (top-bottom);
- A = (right+left) / (right-left);
- B = (top+bottom) / (top-bottom);
- C = -(farp+near) / ( farp-near);
- D = -(2.0*farp*near) / (farp-near);
+ r = &m.m[0][0];
+ r[0] = x;
+ r[1] = 0;
+ r[2] = A;
+ r[3] = 0;
+ r[4] = 0;
+ r[5] = y;
+ r[6] = B;
+ r[7] = 0;
+ r[8] = 0;
+ r[9] = 0;
+ r[10] = C;
+ r[11] = D;
+ r[12] = 0;
+ r[13] = 0;
+ r[14] = -1;
+ r[15] = 0;
- r=&m.m[0][0];
- r[0]= x; r[1]=0; r[2]=A; r[3]=0;
- r[4]= 0; r[5]=y; r[6]=B; r[7]=0;
- r[8]= 0; r[9]=0; r[10]=C; r[11]=D;
- r[12]= 0; r[13]=0; r[14]=-1; r[15]=0;
+ gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode], &m);
- gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);
-
- gl_matrix_update(c);
+ gl_matrix_update(c);
}
-
--- a/src/memory.c
+++ b/src/memory.c
@@ -5,17 +5,8 @@
/* modify these functions so that they suit your needs */
-void gl_free(void *p)
-{
- free(p);
-}
+void gl_free(void* p) { free(p); }
-void *gl_malloc(GLint size)
-{
- return malloc(size);
-}
+void* gl_malloc(GLint size) { return malloc(size); }
-void *gl_zalloc(GLint size)
-{
- return calloc(1, size);
-}
+void* gl_zalloc(GLint size) { return calloc(1, size); }
--- a/src/misc.c
+++ b/src/misc.c
@@ -1,155 +1,145 @@
-#include "zgl.h"
#include "msghandling.h"
+#include "zgl.h"
-
-
-void glPolygonStipple(void* a){
+void glPolygonStipple(void* a) {
#if TGL_FEATURE_POLYGON_STIPPLE
GLubyte* b = a;
- GLContext *c=gl_get_context();
- ZBuffer *zb = c->zb;
+ GLContext* c = gl_get_context();
+ ZBuffer* zb = c->zb;
- for(GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++)
- {
+ for (GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++) {
zb->stipplepattern[i] = b[i];
}
#endif
}
+void glopViewport(GLContext* c, GLParam* p) {
+ GLint xsize, ysize, xmin, ymin, xsize_req, ysize_req;
-void glopViewport(GLContext *c,GLParam *p)
-{
- GLint xsize,ysize,xmin,ymin,xsize_req,ysize_req;
-
- xmin=p[1].i;
- ymin=p[2].i;
- xsize=p[3].i;
- ysize=p[4].i;
+ xmin = p[1].i;
+ ymin = p[2].i;
+ xsize = p[3].i;
+ ysize = p[4].i;
- /* we may need to resize the zbuffer */
+ /* we may need to resize the zbuffer */
- if (c->viewport.xmin != xmin ||
- c->viewport.ymin != ymin ||
- c->viewport.xsize != xsize ||
- c->viewport.ysize != ysize) {
+ if (c->viewport.xmin != xmin || c->viewport.ymin != ymin || c->viewport.xsize != xsize || c->viewport.ysize != ysize) {
- xsize_req=xmin+xsize;
- ysize_req=ymin+ysize;
+ xsize_req = xmin + xsize;
+ ysize_req = ymin + ysize;
- if (c->gl_resize_viewport &&
- c->gl_resize_viewport(c,&xsize_req,&ysize_req) != 0) {
- gl_fatal_error("glViewport: error while resizing display");
- }
+ if (c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
+ gl_fatal_error("glViewport: error while resizing display");
+ }
- xsize=xsize_req-xmin;
- ysize=ysize_req-ymin;
- if (xsize <= 0 || ysize <= 0) {
- gl_fatal_error("glViewport: size too small");
- }
+ xsize = xsize_req - xmin;
+ ysize = ysize_req - ymin;
+ if (xsize <= 0 || ysize <= 0) {
+ gl_fatal_error("glViewport: size too small");
+ }
- tgl_trace("glViewport: %d %d %d %d\n",
- xmin, ymin, xsize, ysize);
- c->viewport.xmin=xmin;
- c->viewport.ymin=ymin;
- c->viewport.xsize=xsize;
- c->viewport.ysize=ysize;
-
- c->viewport.updated=1;
- }
+ tgl_trace("glViewport: %d %d %d %d\n", xmin, ymin, xsize, ysize);
+ c->viewport.xmin = xmin;
+ c->viewport.ymin = ymin;
+ c->viewport.xsize = xsize;
+ c->viewport.ysize = ysize;
+
+ c->viewport.updated = 1;
+ }
}
-void glopEnableDisable(GLContext *c,GLParam *p)
-{
- GLint code=p[1].i;
- GLint v=p[2].i;
+void glopEnableDisable(GLContext* c, GLParam* p) {
+ GLint code = p[1].i;
+ GLint v = p[2].i;
- switch(code) {
- case GL_CULL_FACE:
- c->cull_face_enabled=v;
- break;
- case GL_LIGHTING:
- c->lighting_enabled=v;
- break;
- case GL_COLOR_MATERIAL:
- c->color_material_enabled=v;
- break;
- case GL_TEXTURE_2D:
- c->texture_2d_enabled=v;
- break;
- case GL_NORMALIZE:
- c->normalize_enabled=v;
- break;
- case GL_DEPTH_TEST:
- c->depth_test = v;
- break;
- case GL_POLYGON_OFFSET_FILL:
- if (v) c->offset_states |= TGL_OFFSET_FILL;
- else c->offset_states &= ~TGL_OFFSET_FILL;
- break;
- case GL_POLYGON_STIPPLE:
- c->zb->dostipple = v;
- break;
- case GL_POLYGON_OFFSET_POINT:
- if (v) c->offset_states |= TGL_OFFSET_POINT;
- else c->offset_states &= ~TGL_OFFSET_POINT;
- break;
- case GL_POLYGON_OFFSET_LINE:
- if (v) c->offset_states |= TGL_OFFSET_LINE;
- else c->offset_states &= ~TGL_OFFSET_LINE;
- break;
- default:
- if (code>=GL_LIGHT0 && code<GL_LIGHT0+MAX_LIGHTS) {
- gl_enable_disable_light(c,code - GL_LIGHT0, v);
- } else {
- /*
- fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
- */
- }
- break;
- }
+ switch (code) {
+ case GL_CULL_FACE:
+ c->cull_face_enabled = v;
+ break;
+ case GL_LIGHTING:
+ c->lighting_enabled = v;
+ break;
+ case GL_COLOR_MATERIAL:
+ c->color_material_enabled = v;
+ break;
+ case GL_TEXTURE_2D:
+ c->texture_2d_enabled = v;
+ break;
+ case GL_NORMALIZE:
+ c->normalize_enabled = v;
+ break;
+ case GL_DEPTH_TEST:
+ c->depth_test = v;
+ break;
+ case GL_POLYGON_OFFSET_FILL:
+ if (v)
+ c->offset_states |= TGL_OFFSET_FILL;
+ else
+ c->offset_states &= ~TGL_OFFSET_FILL;
+ break;
+ case GL_POLYGON_STIPPLE:
+ c->zb->dostipple = v;
+ break;
+ case GL_POLYGON_OFFSET_POINT:
+ if (v)
+ c->offset_states |= TGL_OFFSET_POINT;
+ else
+ c->offset_states &= ~TGL_OFFSET_POINT;
+ break;
+ case GL_POLYGON_OFFSET_LINE:
+ if (v)
+ c->offset_states |= TGL_OFFSET_LINE;
+ else
+ c->offset_states &= ~TGL_OFFSET_LINE;
+ break;
+ default:
+ if (code >= GL_LIGHT0 && code < GL_LIGHT0 + MAX_LIGHTS) {
+ gl_enable_disable_light(c, code - GL_LIGHT0, v);
+ } else {
+ /*
+ fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
+ */
+ }
+ break;
+ }
}
-void glopShadeModel(GLContext *c,GLParam *p)
-{
- GLint code=p[1].i;
- c->current_shade_model=code;
+void glopShadeModel(GLContext* c, GLParam* p) {
+ GLint code = p[1].i;
+ c->current_shade_model = code;
}
-void glopCullFace(GLContext *c,GLParam *p)
-{
- GLint code=p[1].i;
- c->current_cull_face=code;
+void glopCullFace(GLContext* c, GLParam* p) {
+ GLint code = p[1].i;
+ c->current_cull_face = code;
}
-void glopFrontFace(GLContext *c,GLParam *p)
-{
- GLint code=p[1].i;
- c->current_front_face=code;
+void glopFrontFace(GLContext* c, GLParam* p) {
+ GLint code = p[1].i;
+ c->current_front_face = code;
}
-void glopPolygonMode(GLContext *c,GLParam *p)
-{
- GLint face=p[1].i;
- GLint mode=p[2].i;
-
- switch(face) {
- case GL_BACK:
- c->polygon_mode_back=mode;
- break;
- case GL_FRONT:
- c->polygon_mode_front=mode;
- break;
- case GL_FRONT_AND_BACK:
- c->polygon_mode_front=mode;
- c->polygon_mode_back=mode;
- break;
- default:
- assert(0);
- }
+void glopPolygonMode(GLContext* c, GLParam* p) {
+ GLint face = p[1].i;
+ GLint mode = p[2].i;
+
+ switch (face) {
+ case GL_BACK:
+ c->polygon_mode_back = mode;
+ break;
+ case GL_FRONT:
+ c->polygon_mode_front = mode;
+ break;
+ case GL_FRONT_AND_BACK:
+ c->polygon_mode_front = mode;
+ c->polygon_mode_back = mode;
+ break;
+ default:
+ assert(0);
+ }
}
-void glopHint(GLContext *c,GLParam *p)
-{
+void glopHint(GLContext* c, GLParam* p) {
#if 0
GLint target=p[1].i;
GLint mode=p[2].i;
@@ -158,9 +148,7 @@
#endif
}
-void
-glopPolygonOffset(GLContext *c, GLParam *p)
-{
- c->offset_factor = p[1].f;
- c->offset_units = p[2].f;
+void glopPolygonOffset(GLContext* c, GLParam* p) {
+ c->offset_factor = p[1].f;
+ c->offset_units = p[2].f;
}
--- a/src/msghandling.c
+++ b/src/msghandling.c
@@ -1,6 +1,6 @@
+#include "../include/GL/gl.h"
#include <stdarg.h>
#include <stdio.h>
-#include "../include/GL/gl.h"
//#define NDEBUG
#ifdef NDEBUG
@@ -11,28 +11,24 @@
happens (which might be an indication of an error). *Don't* use it
when there's GLinternal errors in the code - these should be handled
by asserts. */
-void
-tgl_warning(const char *format, ...)
-{
+void tgl_warning(const char* format, ...) {
#ifndef NO_DEBUG_OUTPUT
- va_list args;
- va_start(args, format);
- fprintf(stderr, "*WARNING* ");
- vfprintf(stderr, format, args);
- va_end(args);
+ va_list args;
+ va_start(args, format);
+ fprintf(stderr, "*WARNING* ");
+ vfprintf(stderr, format, args);
+ va_end(args);
#endif /* !NO_DEBUG_OUTPUT */
}
/* This function should be used for debug output only. */
-void
-tgl_trace(const char *format, ...)
-{
+void tgl_trace(const char* format, ...) {
#ifndef NO_DEBUG_OUTPUT
- va_list args;
- va_start(args, format);
- fprintf(stderr, "*DEBUG* ");
- vfprintf(stderr, format, args);
- va_end(args);
+ va_list args;
+ va_start(args, format);
+ fprintf(stderr, "*DEBUG* ");
+ vfprintf(stderr, format, args);
+ va_end(args);
#endif /* !NO_DEBUG_OUTPUT */
}
@@ -39,14 +35,12 @@
/* Use this function to output info about things in the code which
should be fixed (missing handling of special cases, important
features not implemented, known bugs/buglets, ...). */
-void
-tgl_fixme(const char *format, ...)
-{
+void tgl_fixme(const char* format, ...) {
#ifndef NO_DEBUG_OUTPUT
- va_list args;
- va_start(args, format);
- fprintf(stderr, "*FIXME* ");
- vfprintf(stderr, format, args);
- va_end(args);
+ va_list args;
+ va_start(args, format);
+ fprintf(stderr, "*FIXME* ");
+ vfprintf(stderr, format, args);
+ va_end(args);
#endif /* !NO_DEBUG_OUTPUT */
}
--- a/src/msghandling.h
+++ b/src/msghandling.h
@@ -1,8 +1,8 @@
#ifndef _msghandling_h_
#define _msghandling_h_
#include "../include/GL/gl.h"
-extern void tgl_warning(const char *text, ...);
-extern void tgl_trace(const char *text, ...);
-extern void tgl_fixme(const char *text, ...);
+extern void tgl_warning(const char* text, ...);
+extern void tgl_trace(const char* text, ...);
+extern void tgl_fixme(const char* text, ...);
#endif /* _msghandling_h_ */
--- a/src/opinfo.h
+++ b/src/opinfo.h
@@ -1,60 +1,60 @@
-ADD_OP(Color,7,"%f %f %f %f %d %d %d")
-ADD_OP(TexCoord,4,"%f %f %f %f")
-ADD_OP(EdgeFlag,1,"%d")
-ADD_OP(Normal,3,"%f %f %f")
+ADD_OP(Color, 7, "%f %f %f %f %d %d %d")
+ADD_OP(TexCoord, 4, "%f %f %f %f")
+ADD_OP(EdgeFlag, 1, "%d")
+ADD_OP(Normal, 3, "%f %f %f")
-ADD_OP(Begin,1,"%C")
-ADD_OP(Vertex,4,"%f %f %f %f")
-ADD_OP(End,0,"")
+ADD_OP(Begin, 1, "%C")
+ADD_OP(Vertex, 4, "%f %f %f %f")
+ADD_OP(End, 0, "")
-ADD_OP(EnableDisable,2,"%C %d")
+ADD_OP(EnableDisable, 2, "%C %d")
-ADD_OP(MatrixMode,1,"%C")
-ADD_OP(LoadMatrix,16,"")
-ADD_OP(LoadIdentity,0,"")
-ADD_OP(MultMatrix,16,"")
-ADD_OP(PushMatrix,0,"")
-ADD_OP(PopMatrix,0,"")
-ADD_OP(Rotate,4,"%f %f %f %f")
-ADD_OP(Translate,3,"%f %f %f")
-ADD_OP(Scale,3,"%f %f %f")
+ADD_OP(MatrixMode, 1, "%C")
+ADD_OP(LoadMatrix, 16, "")
+ADD_OP(LoadIdentity, 0, "")
+ADD_OP(MultMatrix, 16, "")
+ADD_OP(PushMatrix, 0, "")
+ADD_OP(PopMatrix, 0, "")
+ADD_OP(Rotate, 4, "%f %f %f %f")
+ADD_OP(Translate, 3, "%f %f %f")
+ADD_OP(Scale, 3, "%f %f %f")
-ADD_OP(Viewport,4,"%d %d %d %d")
-ADD_OP(Frustum,6,"%f %f %f %f %f %f")
+ADD_OP(Viewport, 4, "%d %d %d %d")
+ADD_OP(Frustum, 6, "%f %f %f %f %f %f")
-ADD_OP(Material,6,"%C %C %f %f %f %f")
-ADD_OP(ColorMaterial,2,"%C %C")
-ADD_OP(Light,6,"%C %C %f %f %f %f")
-ADD_OP(LightModel,5,"%C %f %f %f %f")
+ADD_OP(Material, 6, "%C %C %f %f %f %f")
+ADD_OP(ColorMaterial, 2, "%C %C")
+ADD_OP(Light, 6, "%C %C %f %f %f %f")
+ADD_OP(LightModel, 5, "%C %f %f %f %f")
-ADD_OP(Clear,1,"%d")
-ADD_OP(ClearColor,4,"%f %f %f %f")
-ADD_OP(ClearDepth,1,"%f")
+ADD_OP(Clear, 1, "%d")
+ADD_OP(ClearColor, 4, "%f %f %f %f")
+ADD_OP(ClearDepth, 1, "%f")
-ADD_OP(InitNames,0,"")
-ADD_OP(PushName,1,"%d")
-ADD_OP(PopName,0,"")
-ADD_OP(LoadName,1,"%d")
+ADD_OP(InitNames, 0, "")
+ADD_OP(PushName, 1, "%d")
+ADD_OP(PopName, 0, "")
+ADD_OP(LoadName, 1, "%d")
-ADD_OP(TexImage2D,9,"%d %d %d %d %d %d %d %d %d")
-ADD_OP(BindTexture,2,"%C %d")
-ADD_OP(TexEnv,7,"%C %C %C %f %f %f %f")
-ADD_OP(TexParameter,7,"%C %C %C %f %f %f %f")
-ADD_OP(PixelStore,2,"%C %C")
+ADD_OP(TexImage2D, 9, "%d %d %d %d %d %d %d %d %d")
+ADD_OP(BindTexture, 2, "%C %d")
+ADD_OP(TexEnv, 7, "%C %C %C %f %f %f %f")
+ADD_OP(TexParameter, 7, "%C %C %C %f %f %f %f")
+ADD_OP(PixelStore, 2, "%C %C")
-ADD_OP(ShadeModel,1,"%C")
-ADD_OP(CullFace,1,"%C")
-ADD_OP(FrontFace,1,"%C")
-ADD_OP(PolygonMode,2,"%C %C")
+ADD_OP(ShadeModel, 1, "%C")
+ADD_OP(CullFace, 1, "%C")
+ADD_OP(FrontFace, 1, "%C")
+ADD_OP(PolygonMode, 2, "%C %C")
-ADD_OP(CallList,1,"%d")
-ADD_OP(Hint,2,"%C %C")
+ADD_OP(CallList, 1, "%d")
+ADD_OP(Hint, 2, "%C %C")
/* special opcodes */
-ADD_OP(EndList,0,"")
-ADD_OP(NextBuffer,1,"%p")
+ADD_OP(EndList, 0, "")
+ADD_OP(NextBuffer, 1, "%p")
/* opengl 1.1 arrays */
ADD_OP(ArrayElement, 1, "%d")
--- a/src/quick.sh
+++ b/src/quick.sh
@@ -8,6 +8,6 @@
#sed -i 's/char/GLbyte/g' *.c *.h
#sed -i 's/unsigned GLbyte/GLubyte/g' *.c *.h
#sed -i 's/ int/ GLint/g' *.c *.h
-sed -i 's/unsigned GLshort/GLushort/g' *.c *.h
+#sed -i 's/unsigned GLshort/GLushort/g' *.c *.h
#gcc *.c -o executable.out -lglut -lGL -lm -lGLU
--- a/src/select.c
+++ b/src/select.c
@@ -1,114 +1,108 @@
#include "zgl.h"
-int glRenderMode(GLint mode)
-{
- GLContext *c=gl_get_context();
- GLint result=0;
-
- switch(c->render_mode) {
- case GL_RENDER:
- break;
- case GL_SELECT:
- if (c->select_overflow) {
- result=-c->select_hits;
- } else {
- result=c->select_hits;
- }
- c->select_overflow=0;
- c->select_ptr=c->select_buffer;
- c->name_stack_size=0;
- break;
- default:
- assert(0);
- }
- switch(mode) {
- case GL_RENDER:
- c->render_mode=GL_RENDER;
- break;
- case GL_SELECT:
- c->render_mode=GL_SELECT;
- assert( c->select_buffer != NULL);
- c->select_ptr=c->select_buffer;
- c->select_hits=0;
- c->select_overflow=0;
- c->select_hit=NULL;
- break;
- default:
- assert(0);
- }
- return result;
+int glRenderMode(GLint mode) {
+ GLContext* c = gl_get_context();
+ GLint result = 0;
+
+ switch (c->render_mode) {
+ case GL_RENDER:
+ break;
+ case GL_SELECT:
+ if (c->select_overflow) {
+ result = -c->select_hits;
+ } else {
+ result = c->select_hits;
+ }
+ c->select_overflow = 0;
+ c->select_ptr = c->select_buffer;
+ c->name_stack_size = 0;
+ break;
+ default:
+ assert(0);
+ }
+ switch (mode) {
+ case GL_RENDER:
+ c->render_mode = GL_RENDER;
+ break;
+ case GL_SELECT:
+ c->render_mode = GL_SELECT;
+ assert(c->select_buffer != NULL);
+ c->select_ptr = c->select_buffer;
+ c->select_hits = 0;
+ c->select_overflow = 0;
+ c->select_hit = NULL;
+ break;
+ default:
+ assert(0);
+ }
+ return result;
}
-void glSelectBuffer(GLint size,GLuint *buf)
-{
- GLContext *c=gl_get_context();
+void glSelectBuffer(GLint size, GLuint* buf) {
+ GLContext* c = gl_get_context();
- assert(c->render_mode != GL_SELECT);
-
- c->select_buffer=buf;
- c->select_size=size;
+ assert(c->render_mode != GL_SELECT);
+
+ c->select_buffer = buf;
+ c->select_size = size;
}
-
-void glopInitNames(GLContext *c,GLParam *p)
-{
- if (c->render_mode == GL_SELECT) {
- c->name_stack_size=0;
- c->select_hit=NULL;
- }
+void glopInitNames(GLContext* c, GLParam* p) {
+ if (c->render_mode == GL_SELECT) {
+ c->name_stack_size = 0;
+ c->select_hit = NULL;
+ }
}
-void glopPushName(GLContext *c,GLParam *p)
-{
- if (c->render_mode == GL_SELECT) {
- assert(c->name_stack_size<MAX_NAME_STACK_DEPTH);
- c->name_stack[c->name_stack_size++]=p[1].i;
- c->select_hit=NULL;
- }
+void glopPushName(GLContext* c, GLParam* p) {
+ if (c->render_mode == GL_SELECT) {
+ assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
+ c->name_stack[c->name_stack_size++] = p[1].i;
+ c->select_hit = NULL;
+ }
}
-void glopPopName(GLContext *c,GLParam *p)
-{
- if (c->render_mode == GL_SELECT) {
- assert(c->name_stack_size>0);
- c->name_stack_size--;
- c->select_hit=NULL;
- }
+void glopPopName(GLContext* c, GLParam* p) {
+ if (c->render_mode == GL_SELECT) {
+ assert(c->name_stack_size > 0);
+ c->name_stack_size--;
+ c->select_hit = NULL;
+ }
}
-void glopLoadName(GLContext *c,GLParam *p)
-{
- if (c->render_mode == GL_SELECT) {
- assert(c->name_stack_size>0);
- c->name_stack[c->name_stack_size-1]=p[1].i;
- c->select_hit=NULL;
- }
+void glopLoadName(GLContext* c, GLParam* p) {
+ if (c->render_mode == GL_SELECT) {
+ assert(c->name_stack_size > 0);
+ c->name_stack[c->name_stack_size - 1] = p[1].i;
+ c->select_hit = NULL;
+ }
}
-void gl_add_select(GLContext *c,GLuint zmin,GLuint zmax)
-{
- GLuint *ptr;
- GLint n,i;
+void gl_add_select(GLContext* c, GLuint zmin, GLuint zmax) {
+ GLuint* ptr;
+ GLint n, i;
- if (!c->select_overflow) {
- if (c->select_hit==NULL) {
- n=c->name_stack_size;
- if ((c->select_ptr-c->select_buffer+3+n) >
- c->select_size) {
- c->select_overflow=1;
- } else {
- ptr=c->select_ptr;
- c->select_hit=ptr;
- *ptr++=c->name_stack_size;
- *ptr++=zmin;
- *ptr++=zmax;
- for(i=0;i<n;i++) *ptr++=c->name_stack[i];
- c->select_ptr=ptr;
- c->select_hits++;
- }
- } else {
- if (zmin<c->select_hit[1]) c->select_hit[1]=zmin;
- if (zmax>c->select_hit[2]) c->select_hit[2]=zmax;
- }
- }
+ if (!c->select_overflow) {
+ if (c->select_hit == NULL) {
+ n = c->name_stack_size;
+ if ((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) {
+ c->select_overflow = 1;
+ } else {
+ ptr = c->select_ptr;
+ c->select_hit = ptr;
+ *ptr++ = c->name_stack_size;
+ *ptr++ = zmin;
+ *ptr++ = zmax;
+ for (i = 0; i < n; i++)
+ *ptr++ = c->name_stack[i];
+ c->select_ptr = ptr;
+ c->select_hits++;
+ }
+ } else {
+ if (zmin < c->select_hit[1])
+ c->select_hit[1] = zmin;
+ if (zmax > c->select_hit[2])
+ c->select_hit[2] = zmax;
+ }
+ }
}
--- a/src/specbuf.c
+++ b/src/specbuf.c
@@ -1,52 +1,49 @@
-#include "zgl.h"
#include "msghandling.h"
+#include "zgl.h"
#include <math.h>
#include <stdlib.h>
-static void calc_buf(GLSpecBuf *buf, const GLfloat shininess)
-{
- GLint i;
- GLfloat val, inc;
- val = 0.0f;
- inc = 1.0f/SPECULAR_BUFFER_SIZE;
- for (i = 0; i <= SPECULAR_BUFFER_SIZE; i++) {
- buf->buf[i] = pow(val, shininess);
- val += inc;
- }
+static void calc_buf(GLSpecBuf* buf, const GLfloat shininess) {
+ GLint i;
+ GLfloat val, inc;
+ val = 0.0f;
+ inc = 1.0f / SPECULAR_BUFFER_SIZE;
+ for (i = 0; i <= SPECULAR_BUFFER_SIZE; i++) {
+ buf->buf[i] = pow(val, shininess);
+ val += inc;
+ }
}
-GLSpecBuf *
-specbuf_get_buffer(GLContext *c, const GLint shininess_i,
- const GLfloat shininess)
-{
- GLSpecBuf *found, *oldest;
- found = oldest = c->specbuf_first;
- while (found && found->shininess_i != shininess_i) {
- if (found->last_used < oldest->last_used) {
- oldest = found;
- }
- found = found->next;
- }
- if (found) { /* hey, found one! */
- found->last_used = c->specbuf_used_counter++;
- return found;
- }
- if (oldest == NULL || c->specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
- /* create new buffer */
- GLSpecBuf *buf = gl_malloc(sizeof(GLSpecBuf));
- if (!buf) gl_fatal_error("could not allocate specular buffer");
- c->specbuf_num_buffers++;
- buf->next = c->specbuf_first;
- c->specbuf_first = buf;
- buf->last_used = c->specbuf_used_counter++;
- buf->shininess_i = shininess_i;
- calc_buf(buf, shininess);
- return buf;
- }
- /* overwrite the lru buffer */
- /*tgl_trace("overwriting spec buffer :(\n");*/
- oldest->shininess_i = shininess_i;
- oldest->last_used = c->specbuf_used_counter++;
- calc_buf(oldest, shininess);
- return oldest;
+GLSpecBuf* specbuf_get_buffer(GLContext* c, const GLint shininess_i, const GLfloat shininess) {
+ GLSpecBuf *found, *oldest;
+ found = oldest = c->specbuf_first;
+ while (found && found->shininess_i != shininess_i) {
+ if (found->last_used < oldest->last_used) {
+ oldest = found;
+ }
+ found = found->next;
+ }
+ if (found) { /* hey, found one! */
+ found->last_used = c->specbuf_used_counter++;
+ return found;
+ }
+ if (oldest == NULL || c->specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
+ /* create new buffer */
+ GLSpecBuf* buf = gl_malloc(sizeof(GLSpecBuf));
+ if (!buf)
+ gl_fatal_error("could not allocate specular buffer");
+ c->specbuf_num_buffers++;
+ buf->next = c->specbuf_first;
+ c->specbuf_first = buf;
+ buf->last_used = c->specbuf_used_counter++;
+ buf->shininess_i = shininess_i;
+ calc_buf(buf, shininess);
+ return buf;
+ }
+ /* overwrite the lru buffer */
+ /*tgl_trace("overwriting spec buffer :(\n");*/
+ oldest->shininess_i = shininess_i;
+ oldest->last_used = c->specbuf_used_counter++;
+ calc_buf(oldest, shininess);
+ return oldest;
}
--- a/src/specbuf.h
+++ b/src/specbuf.h
@@ -9,14 +9,13 @@
#define SPECULAR_BUFFER_RESOLUTION 1024
typedef struct GLSpecBuf {
- GLint shininess_i;
- GLint last_used;
- GLfloat buf[SPECULAR_BUFFER_SIZE+1];
- struct GLSpecBuf *next;
+ GLint shininess_i;
+ GLint last_used;
+ GLfloat buf[SPECULAR_BUFFER_SIZE + 1];
+ struct GLSpecBuf* next;
} GLSpecBuf;
-GLSpecBuf *specbuf_get_buffer(GLContext *c, const GLint shininess_i,
- const GLfloat shininess);
-void specbuf_cleanup(GLContext *c); /* free all memory used */
+GLSpecBuf* specbuf_get_buffer(GLContext* c, const GLint shininess_i, const GLfloat shininess);
+void specbuf_cleanup(GLContext* c); /* free all memory used */
#endif /* _tgl_specbuf_h_ */
\ No newline at end of file
--- a/src/texture.c
+++ b/src/texture.c
@@ -4,237 +4,228 @@
#include "zgl.h"
-static GLTexture *find_texture(GLContext *c,GLint h)
-{
- GLTexture *t;
+static GLTexture* find_texture(GLContext* c, GLint h) {
+ GLTexture* t;
- t=c->shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
- while (t!=NULL) {
- if (t->handle == h) return t;
- t=t->next;
- }
- return NULL;
+ t = c->shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
+ while (t != NULL) {
+ if (t->handle == h)
+ return t;
+ t = t->next;
+ }
+ return NULL;
}
-void* glGetTexturePixmap(GLint text, GLint level, GLint* xsize, GLint* ysize){
+void* glGetTexturePixmap(GLint text, GLint level, GLint* xsize, GLint* ysize) {
GLTexture* tex;
- GLContext *c=gl_get_context();
+ GLContext* c = gl_get_context();
assert(text >= 0 && level < MAX_TEXTURE_LEVELS);
tex = find_texture(c, text);
- if(!tex)return NULL;
+ if (!tex)
+ return NULL;
*xsize = tex->images[level].xsize;
*ysize = tex->images[level].ysize;
return tex->images[level].pixmap;
}
-static void free_texture(GLContext *c,GLint h)
-{
- GLTexture *t,**ht;
- GLImage *im;
- GLint i;
+static void free_texture(GLContext* c, GLint h) {
+ GLTexture *t, **ht;
+ GLImage* im;
+ GLint i;
- t=find_texture(c,h);
- if (t->prev==NULL) {
- ht=&c->shared_state.texture_hash_table
- [t->handle % TEXTURE_HASH_TABLE_SIZE];
- *ht=t->next;
- } else {
- t->prev->next=t->next;
- }
- if (t->next!=NULL) t->next->prev=t->prev;
+ t = find_texture(c, h);
+ if (t->prev == NULL) {
+ ht = &c->shared_state.texture_hash_table[t->handle % TEXTURE_HASH_TABLE_SIZE];
+ *ht = t->next;
+ } else {
+ t->prev->next = t->next;
+ }
+ if (t->next != NULL)
+ t->next->prev = t->prev;
- for(i=0;i<MAX_TEXTURE_LEVELS;i++) {
- im=&t->images[i];
- if (im->pixmap != NULL) gl_free(im->pixmap);
- }
+ for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
+ im = &t->images[i];
+ if (im->pixmap != NULL)
+ gl_free(im->pixmap);
+ }
- gl_free(t);
+ gl_free(t);
}
-GLTexture *alloc_texture(GLContext *c,GLint h)
-{
- GLTexture *t,**ht;
-
- t=gl_zalloc(sizeof(GLTexture));
+GLTexture* alloc_texture(GLContext* c, GLint h) {
+ GLTexture *t, **ht;
- ht=&c->shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
+ t = gl_zalloc(sizeof(GLTexture));
- t->next=*ht;
- t->prev=NULL;
- if (t->next != NULL) t->next->prev=t;
- *ht=t;
+ ht = &c->shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
- t->handle=h;
-
- return t;
-}
+ t->next = *ht;
+ t->prev = NULL;
+ if (t->next != NULL)
+ t->next->prev = t;
+ *ht = t;
+ t->handle = h;
-void glInitTextures(GLContext *c)
-{
- /* textures */
-
- c->texture_2d_enabled=0;
- c->current_texture=find_texture(c,0);
+ return t;
}
-void glGenTextures(GLint n, GLuint *textures)
-{
- GLContext *c=gl_get_context();
- GLint max,i;
- GLTexture *t;
+void glInitTextures(GLContext* c) {
+ /* textures */
- max=0;
- for(i=0;i<TEXTURE_HASH_TABLE_SIZE;i++) {
- t=c->shared_state.texture_hash_table[i];
- while (t!=NULL) {
- if (t->handle>max) max=t->handle;
- t=t->next;
- }
-
- }
- for(i=0;i<n;i++) {
- textures[i]=max+i+1;
- }
+ c->texture_2d_enabled = 0;
+ c->current_texture = find_texture(c, 0);
}
+void glGenTextures(GLint n, GLuint* textures) {
+ GLContext* c = gl_get_context();
+ GLint max, i;
+ GLTexture* t;
-void glDeleteTextures(GLint n, const GLuint *textures)
-{
- GLContext *c=gl_get_context();
- GLint i;
- GLTexture *t;
-
- for(i=0;i<n;i++) {
- t=find_texture(c,textures[i]);
- if (t!=NULL && t!=0) {
- if (t==c->current_texture) {
- glBindTexture(GL_TEXTURE_2D,0);
- }
- free_texture(c,textures[i]);
- }
- }
+ max = 0;
+ for (i = 0; i < TEXTURE_HASH_TABLE_SIZE; i++) {
+ t = c->shared_state.texture_hash_table[i];
+ while (t != NULL) {
+ if (t->handle > max)
+ max = t->handle;
+ t = t->next;
+ }
+ }
+ for (i = 0; i < n; i++) {
+ textures[i] = max + i + 1;
+ }
}
+void glDeleteTextures(GLint n, const GLuint* textures) {
+ GLContext* c = gl_get_context();
+ GLint i;
+ GLTexture* t;
-void glopBindTexture(GLContext *c,GLParam *p)
-{
- GLint target=p[1].i;
- GLint texture=p[2].i;
- GLTexture *t;
+ for (i = 0; i < n; i++) {
+ t = find_texture(c, textures[i]);
+ if (t != NULL && t != 0) {
+ if (t == c->current_texture) {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+ free_texture(c, textures[i]);
+ }
+ }
+}
- assert(target == GL_TEXTURE_2D && texture >= 0);
+void glopBindTexture(GLContext* c, GLParam* p) {
+ GLint target = p[1].i;
+ GLint texture = p[2].i;
+ GLTexture* t;
- t=find_texture(c,texture);
- if (t==NULL) {
- t=alloc_texture(c,texture);
- }
- c->current_texture=t;
+ assert(target == GL_TEXTURE_2D && texture >= 0);
+
+ t = find_texture(c, texture);
+ if (t == NULL) {
+ t = alloc_texture(c, texture);
+ }
+ c->current_texture = t;
}
-void glopTexImage2D(GLContext *c,GLParam *p)
-{
- GLint target=p[1].i;
- GLint level=p[2].i;
- GLint components=p[3].i;
- GLint width=p[4].i;
- GLint height=p[5].i;
- GLint border=p[6].i;
- GLint format=p[7].i;
- GLint type=p[8].i;
- void *pixels=p[9].p;
- GLImage *im;
- GLubyte *pixels1;
- GLint do_free;
+void glopTexImage2D(GLContext* c, GLParam* p) {
+ GLint target = p[1].i;
+ GLint level = p[2].i;
+ GLint components = p[3].i;
+ GLint width = p[4].i;
+ GLint height = p[5].i;
+ GLint border = p[6].i;
+ GLint format = p[7].i;
+ GLint type = p[8].i;
+ void* pixels = p[9].p;
+ GLImage* im;
+ GLubyte* pixels1;
+ GLint do_free;
- if (!(target == GL_TEXTURE_2D && level == 0 && components == 3 &&
- border == 0 && format == GL_RGB &&
- type == GL_UNSIGNED_BYTE)) {
- gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
- }
-
- do_free=0;
- if (width != 256 || height != 256) {
- pixels1 = gl_malloc(256 * 256 * 3);
- /* no GLinterpolation is done here to respect the original image aliasing ! */
- gl_resizeImageNoInterpolate(pixels1,256,256,pixels,width,height);
- do_free=1;
- width=256;
- height=256;
- } else {
- pixels1=pixels;
- }
+ if (!(target == GL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE)) {
+ gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
+ }
- im=&c->current_texture->images[level];
- im->xsize=width;
- im->ysize=height;
- if (im->pixmap!=NULL) gl_free(im->pixmap);
-#if TGL_FEATURE_RENDER_BITS == 24
- im->pixmap=gl_malloc(width*height*3);
- if(im->pixmap) {
- memcpy(im->pixmap,pixels1,width*height*3);
- }
+ do_free = 0;
+ if (width != 256 || height != 256) {
+ pixels1 = gl_malloc(256 * 256 * 3);
+ /* no GLinterpolation is done here to respect the original image aliasing ! */
+ gl_resizeImageNoInterpolate(pixels1, 256, 256, pixels, width, height);
+ do_free = 1;
+ width = 256;
+ height = 256;
+ } else {
+ pixels1 = pixels;
+ }
+
+ im = &c->current_texture->images[level];
+ im->xsize = width;
+ im->ysize = height;
+ if (im->pixmap != NULL)
+ gl_free(im->pixmap);
+#if TGL_FEATURE_RENDER_BITS == 24
+ im->pixmap = gl_malloc(width * height * 3);
+ if (im->pixmap) {
+ memcpy(im->pixmap, pixels1, width * height * 3);
+ }
#elif TGL_FEATURE_RENDER_BITS == 32
- im->pixmap=gl_malloc(width*height*4);
- if(im->pixmap) {
- gl_convertRGB_to_8A8R8G8B(im->pixmap,pixels1,width,height);
- }
+ im->pixmap = gl_malloc(width * height * 4);
+ if (im->pixmap) {
+ gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height);
+ }
#elif TGL_FEATURE_RENDER_BITS == 16
- im->pixmap=gl_malloc(width*height*2);
- if(im->pixmap) {
- gl_convertRGB_to_5R6G5B(im->pixmap,pixels1,width,height);
- }
+ im->pixmap = gl_malloc(width * height * 2);
+ if (im->pixmap) {
+ gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height);
+ }
#else
#error TODO
#endif
- if (do_free) gl_free(pixels1);
+ if (do_free)
+ gl_free(pixels1);
}
-
/* TODO: not all tests are done */
-void glopTexEnv(GLContext *c,GLParam *p)
-{
- GLint target=p[1].i;
- GLint pname=p[2].i;
- GLint param=p[3].i;
+void glopTexEnv(GLContext* c, GLParam* p) {
+ GLint target = p[1].i;
+ GLint pname = p[2].i;
+ GLint param = p[3].i;
- if (target != GL_TEXTURE_ENV) {
- error:
- gl_fatal_error("glTexParameter: unsupported option");
- }
+ if (target != GL_TEXTURE_ENV) {
+ error:
+ gl_fatal_error("glTexParameter: unsupported option");
+ }
- if (pname != GL_TEXTURE_ENV_MODE) goto error;
+ if (pname != GL_TEXTURE_ENV_MODE)
+ goto error;
- if (param != GL_DECAL) goto error;
+ if (param != GL_DECAL)
+ goto error;
}
/* TODO: not all tests are done */
-void glopTexParameter(GLContext *c,GLParam *p)
-{
- GLint target=p[1].i;
- GLint pname=p[2].i;
- GLint param=p[3].i;
-
- if (target != GL_TEXTURE_2D) {
- error:
- gl_fatal_error("glTexParameter: unsupported option");
- }
+void glopTexParameter(GLContext* c, GLParam* p) {
+ GLint target = p[1].i;
+ GLint pname = p[2].i;
+ GLint param = p[3].i;
- switch(pname) {
- case GL_TEXTURE_WRAP_S:
- case GL_TEXTURE_WRAP_T:
- if (param != GL_REPEAT) goto error;
- break;
- }
+ if (target != GL_TEXTURE_2D) {
+ error:
+ gl_fatal_error("glTexParameter: unsupported option");
+ }
+
+ switch (pname) {
+ case GL_TEXTURE_WRAP_S:
+ case GL_TEXTURE_WRAP_T:
+ if (param != GL_REPEAT)
+ goto error;
+ break;
+ }
}
-void glopPixelStore(GLContext *c,GLParam *p)
-{
- GLint pname=p[1].i;
- GLint param=p[2].i;
+void glopPixelStore(GLContext* c, GLParam* p) {
+ GLint pname = p[1].i;
+ GLint param = p[2].i;
- if (pname != GL_UNPACK_ALIGNMENT ||
- param != 1) {
- gl_fatal_error("glPixelStore: unsupported option");
- }
+ if (pname != GL_UNPACK_ALIGNMENT || param != 1) {
+ gl_fatal_error("glPixelStore: unsupported option");
+ }
}
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -1,44 +1,38 @@
#include "zgl.h"
#include <string.h>
-void glopNormal(GLContext * c, GLParam * p)
-{
- V3 v;
+void glopNormal(GLContext* c, GLParam* p) {
+ V3 v;
- v.X = p[1].f;
- v.Y = p[2].f;
- v.Z = p[3].f;
+ v.X = p[1].f;
+ v.Y = p[2].f;
+ v.Z = p[3].f;
- c->current_normal.X = v.X;
- c->current_normal.Y = v.Y;
- c->current_normal.Z = v.Z;
- c->current_normal.W = 0;
+ c->current_normal.X = v.X;
+ c->current_normal.Y = v.Y;
+ c->current_normal.Z = v.Z;
+ c->current_normal.W = 0;
}
-void glopTexCoord(GLContext * c, GLParam * p)
-{
- c->current_tex_coord.X = p[1].f;
- c->current_tex_coord.Y = p[2].f;
- c->current_tex_coord.Z = p[3].f;
- c->current_tex_coord.W = p[4].f;
+void glopTexCoord(GLContext* c, GLParam* p) {
+ c->current_tex_coord.X = p[1].f;
+ c->current_tex_coord.Y = p[2].f;
+ c->current_tex_coord.Z = p[3].f;
+ c->current_tex_coord.W = p[4].f;
}
-void glopEdgeFlag(GLContext * c, GLParam * p)
-{
- c->current_edge_flag = p[1].i;
-}
+void glopEdgeFlag(GLContext* c, GLParam* p) { c->current_edge_flag = p[1].i; }
-void glopColor(GLContext * c, GLParam * p)
-{
+void glopColor(GLContext* c, GLParam* p) {
- c->current_color.X = p[1].f;
- c->current_color.Y = p[2].f;
- c->current_color.Z = p[3].f;
- c->current_color.W = p[4].f;
- //c->longcurrent_color[0] = p[5].ui; //MARKED
- //c->longcurrent_color[1] = p[6].ui; //MARKED
- //c->longcurrent_color[2] = p[7].ui; //MARKED
+ c->current_color.X = p[1].f;
+ c->current_color.Y = p[2].f;
+ c->current_color.Z = p[3].f;
+ c->current_color.W = p[4].f;
+ // c->longcurrent_color[0] = p[5].ui; //MARKED
+ // c->longcurrent_color[1] = p[6].ui; //MARKED
+ // c->longcurrent_color[2] = p[7].ui; //MARKED
- if (c->color_material_enabled) {
+ if (c->color_material_enabled) {
GLParam q[7];
q[0].op = OP_Material;
q[1].i = c->current_color_material_mode;
@@ -48,320 +42,300 @@
q[5].f = p[3].f;
q[6].f = p[4].f;
glopMaterial(c, q);
- }
+ }
}
+void gl_eval_viewport(GLContext* c) {
+ GLViewport* v;
+ GLfloat zsize = (1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS));
-void gl_eval_viewport(GLContext * c)
-{
- GLViewport *v;
- GLfloat zsize = (1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS));
+ v = &c->viewport;
- v = &c->viewport;
+ v->trans.X = ((v->xsize - 0.5) / 2.0) + v->xmin;
+ v->trans.Y = ((v->ysize - 0.5) / 2.0) + v->ymin;
+ v->trans.Z = ((zsize - 0.5) / 2.0) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2;
- v->trans.X = ((v->xsize - 0.5) / 2.0) + v->xmin;
- v->trans.Y = ((v->ysize - 0.5) / 2.0) + v->ymin;
- v->trans.Z = ((zsize - 0.5) / 2.0) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2;
-
- v->scale.X = (v->xsize - 0.5) / 2.0;
- v->scale.Y = -(v->ysize - 0.5) / 2.0;
- v->scale.Z = -((zsize - 0.5) / 2.0);
+ v->scale.X = (v->xsize - 0.5) / 2.0;
+ v->scale.Y = -(v->ysize - 0.5) / 2.0;
+ v->scale.Z = -((zsize - 0.5) / 2.0);
}
-void glopBegin(GLContext * c, GLParam * p)
-{
- GLint type;
- M4 tmp;
+void glopBegin(GLContext* c, GLParam* p) {
+ GLint type;
+ M4 tmp;
- assert(c->in_begin == 0);
+ assert(c->in_begin == 0);
- type = p[1].i;
- c->begin_type = type;
- c->in_begin = 1;
- c->vertex_n = 0;
- c->vertex_cnt = 0;
+ type = p[1].i;
+ c->begin_type = type;
+ c->in_begin = 1;
+ c->vertex_n = 0;
+ c->vertex_cnt = 0;
- if (c->matrix_model_projection_updated) {
+ if (c->matrix_model_projection_updated) {
- if (c->lighting_enabled) {
- /* precompute inverse modelview */
- gl_M4_Inv(&tmp, c->matrix_stack_ptr[0]);
- gl_M4_Transpose(&c->matrix_model_view_inv, &tmp);
- } else {
- GLfloat *m = &c->matrix_model_projection.m[0][0];
- /* precompute projection matrix */
- gl_M4_Mul(&c->matrix_model_projection,
- c->matrix_stack_ptr[1],
- c->matrix_stack_ptr[0]);
- /* test to accelerate computation */
- c->matrix_model_projection_no_w_transform = 0;
- if (m[12] == 0.0 && m[13] == 0.0 && m[14] == 0.0)
- c->matrix_model_projection_no_w_transform = 1;
- }
+ if (c->lighting_enabled) {
+ /* precompute inverse modelview */
+ gl_M4_Inv(&tmp, c->matrix_stack_ptr[0]);
+ gl_M4_Transpose(&c->matrix_model_view_inv, &tmp);
+ } else {
+ GLfloat* m = &c->matrix_model_projection.m[0][0];
+ /* precompute projection matrix */
+ gl_M4_Mul(&c->matrix_model_projection, c->matrix_stack_ptr[1], c->matrix_stack_ptr[0]);
+ /* test to accelerate computation */
+ c->matrix_model_projection_no_w_transform = 0;
+ if (m[12] == 0.0 && m[13] == 0.0 && m[14] == 0.0)
+ c->matrix_model_projection_no_w_transform = 1;
+ }
- /* test if the texture matrix is not Identity */
- c->apply_texture_matrix = !gl_M4_IsId(c->matrix_stack_ptr[2]);
+ /* test if the texture matrix is not Identity */
+ c->apply_texture_matrix = !gl_M4_IsId(c->matrix_stack_ptr[2]);
- c->matrix_model_projection_updated = 0;
- }
- /* viewport */
- if (c->viewport.updated) {
- gl_eval_viewport(c);
- c->viewport.updated = 0;
- }
- /* triangle drawing functions */
- if (c->render_mode == GL_SELECT) {
- c->draw_triangle_front = gl_draw_triangle_select;
- c->draw_triangle_back = gl_draw_triangle_select;
- } else {
- switch (c->polygon_mode_front) {
- case GL_POINT:
- c->draw_triangle_front = gl_draw_triangle_point;
- break;
- case GL_LINE:
- c->draw_triangle_front = gl_draw_triangle_line;
- break;
- default:
- c->draw_triangle_front = gl_draw_triangle_fill;
- break;
+ c->matrix_model_projection_updated = 0;
}
+ /* viewport */
+ if (c->viewport.updated) {
+ gl_eval_viewport(c);
+ c->viewport.updated = 0;
+ }
+ /* triangle drawing functions */
+ if (c->render_mode == GL_SELECT) {
+ c->draw_triangle_front = gl_draw_triangle_select;
+ c->draw_triangle_back = gl_draw_triangle_select;
+ } else {
+ switch (c->polygon_mode_front) {
+ case GL_POINT:
+ c->draw_triangle_front = gl_draw_triangle_point;
+ break;
+ case GL_LINE:
+ c->draw_triangle_front = gl_draw_triangle_line;
+ break;
+ default:
+ c->draw_triangle_front = gl_draw_triangle_fill;
+ break;
+ }
- switch (c->polygon_mode_back) {
- case GL_POINT:
- c->draw_triangle_back = gl_draw_triangle_point;
- break;
- case GL_LINE:
- c->draw_triangle_back = gl_draw_triangle_line;
- break;
- default:
- c->draw_triangle_back = gl_draw_triangle_fill;
- break;
+ switch (c->polygon_mode_back) {
+ case GL_POINT:
+ c->draw_triangle_back = gl_draw_triangle_point;
+ break;
+ case GL_LINE:
+ c->draw_triangle_back = gl_draw_triangle_line;
+ break;
+ default:
+ c->draw_triangle_back = gl_draw_triangle_fill;
+ break;
+ }
}
- }
}
/* coords, tranformation , clip code and projection */
/* TODO : handle all cases */
-static inline void gl_vertex_transform(GLContext * c, GLVertex * v)
-{
- GLfloat *m;
- V4 *n;
+static inline void gl_vertex_transform(GLContext* c, GLVertex* v) {
+ GLfloat* m;
+ V4* n;
- if (c->lighting_enabled) {
- /* eye coordinates needed for lighting */
+ if (c->lighting_enabled) {
+ /* eye coordinates needed for lighting */
- m = &c->matrix_stack_ptr[0]->m[0][0];
- v->ec.X = (v->coord.X * m[0] + v->coord.Y * m[1] +
- v->coord.Z * m[2] + m[3]);
- v->ec.Y = (v->coord.X * m[4] + v->coord.Y * m[5] +
- v->coord.Z * m[6] + m[7]);
- v->ec.Z = (v->coord.X * m[8] + v->coord.Y * m[9] +
- v->coord.Z * m[10] + m[11]);
- v->ec.W = (v->coord.X * m[12] + v->coord.Y * m[13] +
- v->coord.Z * m[14] + m[15]);
+ m = &c->matrix_stack_ptr[0]->m[0][0];
+ v->ec.X = (v->coord.X * m[0] + v->coord.Y * m[1] + v->coord.Z * m[2] + m[3]);
+ v->ec.Y = (v->coord.X * m[4] + v->coord.Y * m[5] + v->coord.Z * m[6] + m[7]);
+ v->ec.Z = (v->coord.X * m[8] + v->coord.Y * m[9] + v->coord.Z * m[10] + m[11]);
+ v->ec.W = (v->coord.X * m[12] + v->coord.Y * m[13] + v->coord.Z * m[14] + m[15]);
- /* projection coordinates */
- m = &c->matrix_stack_ptr[1]->m[0][0];
- v->pc.X = (v->ec.X * m[0] + v->ec.Y * m[1] +
- v->ec.Z * m[2] + v->ec.W * m[3]);
- v->pc.Y = (v->ec.X * m[4] + v->ec.Y * m[5] +
- v->ec.Z * m[6] + v->ec.W * m[7]);
- v->pc.Z = (v->ec.X * m[8] + v->ec.Y * m[9] +
- v->ec.Z * m[10] + v->ec.W * m[11]);
- v->pc.W = (v->ec.X * m[12] + v->ec.Y * m[13] +
- v->ec.Z * m[14] + v->ec.W * m[15]);
+ /* projection coordinates */
+ m = &c->matrix_stack_ptr[1]->m[0][0];
+ v->pc.X = (v->ec.X * m[0] + v->ec.Y * m[1] + v->ec.Z * m[2] + v->ec.W * m[3]);
+ v->pc.Y = (v->ec.X * m[4] + v->ec.Y * m[5] + v->ec.Z * m[6] + v->ec.W * m[7]);
+ v->pc.Z = (v->ec.X * m[8] + v->ec.Y * m[9] + v->ec.Z * m[10] + v->ec.W * m[11]);
+ v->pc.W = (v->ec.X * m[12] + v->ec.Y * m[13] + v->ec.Z * m[14] + v->ec.W * m[15]);
- m = &c->matrix_model_view_inv.m[0][0];
- n = &c->current_normal;
+ m = &c->matrix_model_view_inv.m[0][0];
+ n = &c->current_normal;
- v->normal.X = (n->X * m[0] + n->Y * m[1] + n->Z * m[2]);
- v->normal.Y = (n->X * m[4] + n->Y * m[5] + n->Z * m[6]);
- v->normal.Z = (n->X * m[8] + n->Y * m[9] + n->Z * m[10]);
+ v->normal.X = (n->X * m[0] + n->Y * m[1] + n->Z * m[2]);
+ v->normal.Y = (n->X * m[4] + n->Y * m[5] + n->Z * m[6]);
+ v->normal.Z = (n->X * m[8] + n->Y * m[9] + n->Z * m[10]);
- if (c->normalize_enabled) {
- gl_V3_Norm(&v->normal);
- }
- } else {
- /* no eye coordinates needed, no normal */
- /* NOTE: W = 1 is assumed */
- m = &c->matrix_model_projection.m[0][0];
-
- v->pc.X = (v->coord.X * m[0] + v->coord.Y * m[1] +
- v->coord.Z * m[2] + m[3]);
- v->pc.Y = (v->coord.X * m[4] + v->coord.Y * m[5] +
- v->coord.Z * m[6] + m[7]);
- v->pc.Z = (v->coord.X * m[8] + v->coord.Y * m[9] +
- v->coord.Z * m[10] + m[11]);
- if (c->matrix_model_projection_no_w_transform) {
- v->pc.W = m[15];
+ if (c->normalize_enabled) {
+ gl_V3_Norm(&v->normal);
+ }
} else {
- v->pc.W = (v->coord.X * m[12] + v->coord.Y * m[13] +
- v->coord.Z * m[14] + m[15]);
+ /* no eye coordinates needed, no normal */
+ /* NOTE: W = 1 is assumed */
+ m = &c->matrix_model_projection.m[0][0];
+
+ v->pc.X = (v->coord.X * m[0] + v->coord.Y * m[1] + v->coord.Z * m[2] + m[3]);
+ v->pc.Y = (v->coord.X * m[4] + v->coord.Y * m[5] + v->coord.Z * m[6] + m[7]);
+ v->pc.Z = (v->coord.X * m[8] + v->coord.Y * m[9] + v->coord.Z * m[10] + m[11]);
+ if (c->matrix_model_projection_no_w_transform) {
+ v->pc.W = m[15];
+ } else {
+ v->pc.W = (v->coord.X * m[12] + v->coord.Y * m[13] + v->coord.Z * m[14] + m[15]);
+ }
}
- }
- v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
+ v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
}
-void glopVertex(GLContext * c, GLParam * p)
-{
- GLVertex *v;
- GLint n, i, cnt;
+void glopVertex(GLContext* c, GLParam* p) {
+ GLVertex* v;
+ GLint n, i, cnt;
- assert(c->in_begin != 0);
+ assert(c->in_begin != 0);
- n = c->vertex_n;
- cnt = c->vertex_cnt;
- cnt++;
- c->vertex_cnt = cnt;
+ n = c->vertex_n;
+ cnt = c->vertex_cnt;
+ cnt++;
+ c->vertex_cnt = cnt;
- /* quick fix to avoid crashes on large polygons */
- if (n >= c->vertex_max) {
- GLVertex *newarray;
- c->vertex_max <<= 1; /* just GLdouble size */
- newarray = gl_malloc(sizeof(GLVertex) * c->vertex_max);
- if (!newarray) {
- gl_fatal_error("unable to allocate GLVertex array.\n");
+ /* quick fix to avoid crashes on large polygons */
+ if (n >= c->vertex_max) {
+ GLVertex* newarray;
+ c->vertex_max <<= 1; /* just GLdouble size */
+ newarray = gl_malloc(sizeof(GLVertex) * c->vertex_max);
+ if (!newarray) {
+ gl_fatal_error("unable to allocate GLVertex array.\n");
+ }
+ memcpy(newarray, c->vertex, n * sizeof(GLVertex));
+ gl_free(c->vertex);
+ c->vertex = newarray;
}
- memcpy(newarray, c->vertex, n * sizeof(GLVertex));
- gl_free(c->vertex);
- c->vertex = newarray;
- }
- /* new vertex entry */
- v = &c->vertex[n];
- n++;
+ /* new vertex entry */
+ v = &c->vertex[n];
+ n++;
- v->coord.X = p[1].f;
- v->coord.Y = p[2].f;
- v->coord.Z = p[3].f;
- v->coord.W = p[4].f;
+ v->coord.X = p[1].f;
+ v->coord.Y = p[2].f;
+ v->coord.Z = p[3].f;
+ v->coord.W = p[4].f;
- gl_vertex_transform(c, v);
+ gl_vertex_transform(c, v);
- /* color */
+ /* color */
- if (c->lighting_enabled) {
+ if (c->lighting_enabled) {
gl_shade_vertex(c, v);
- } else {
+ } else {
v->color = c->current_color;
- }
+ }
/* Added by Gek to fix bug with rendering*/
- //v->zp.r=(GLuint)(v->color.v[0] * 65535) & 65535;
- //v->zp.g=(GLuint)(v->color.v[1] * 65535) & 65535;
- //v->zp.b=(GLuint)(v->color.v[2] * 65535) & 65535;
- /* tex coords */
+ // v->zp.r=(GLuint)(v->color.v[0] * 65535) & 65535;
+ // v->zp.g=(GLuint)(v->color.v[1] * 65535) & 65535;
+ // v->zp.b=(GLuint)(v->color.v[2] * 65535) & 65535;
+ /* tex coords */
- if (c->texture_2d_enabled) {
- if (c->apply_texture_matrix) {
- gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord);
- } else {
- v->tex_coord = c->current_tex_coord;
+ if (c->texture_2d_enabled) {
+ if (c->apply_texture_matrix) {
+ gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord);
+ } else {
+ v->tex_coord = c->current_tex_coord;
+ }
}
- }
- /* precompute the mapping to the viewport */
- if (v->clip_code == 0)
- gl_transform_to_viewport(c, v);
+ /* precompute the mapping to the viewport */
+ if (v->clip_code == 0)
+ gl_transform_to_viewport(c, v);
- /* edge flag */
+ /* edge flag */
- v->edge_flag = c->current_edge_flag;
+ v->edge_flag = c->current_edge_flag;
- switch (c->begin_type) {
- case GL_POINTS:
- gl_draw_point(c, &c->vertex[0]);
- n = 0;
- break;
+ switch (c->begin_type) {
+ case GL_POINTS:
+ gl_draw_point(c, &c->vertex[0]);
+ n = 0;
+ break;
- case GL_LINES:
- if (n == 2) {
- gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
- n = 0;
- }
- break;
- case GL_LINE_STRIP:
- case GL_LINE_LOOP:
- if (n == 1) {
- c->vertex[2] = c->vertex[0];
- } else if (n == 2) {
- gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
- c->vertex[0] = c->vertex[1];
- n = 1;
- }
- break;
+ case GL_LINES:
+ if (n == 2) {
+ gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
+ n = 0;
+ }
+ break;
+ case GL_LINE_STRIP:
+ case GL_LINE_LOOP:
+ if (n == 1) {
+ c->vertex[2] = c->vertex[0];
+ } else if (n == 2) {
+ gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
+ c->vertex[0] = c->vertex[1];
+ n = 1;
+ }
+ break;
- case GL_TRIANGLES:
- if (n == 3) {
- gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
- n = 0;
- }
- break;
- case GL_TRIANGLE_STRIP:
- if (cnt >= 3) {
- if (n == 3)
- n = 0;
- /* needed to respect triangle orientation */
- switch(cnt & 1) {
- case 0:
- gl_draw_triangle(c,&c->vertex[2],&c->vertex[1],&c->vertex[0]);
- break;
- default:
- case 1:
- gl_draw_triangle(c,&c->vertex[0],&c->vertex[1],&c->vertex[2]);
- break;
- }
- }
- break;
- case GL_TRIANGLE_FAN:
- if (n == 3) {
- gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
- c->vertex[1] = c->vertex[2];
- n = 2;
- }
- break;
+ case GL_TRIANGLES:
+ if (n == 3) {
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+ n = 0;
+ }
+ break;
+ case GL_TRIANGLE_STRIP:
+ if (cnt >= 3) {
+ if (n == 3)
+ n = 0;
+ /* needed to respect triangle orientation */
+ switch (cnt & 1) {
+ case 0:
+ gl_draw_triangle(c, &c->vertex[2], &c->vertex[1], &c->vertex[0]);
+ break;
+ default:
+ case 1:
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+ break;
+ }
+ }
+ break;
+ case GL_TRIANGLE_FAN:
+ if (n == 3) {
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+ c->vertex[1] = c->vertex[2];
+ n = 2;
+ }
+ break;
- case GL_QUADS:
- if (n == 4) {
- c->vertex[2].edge_flag = 0;
- gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
- c->vertex[2].edge_flag = 1;
- c->vertex[0].edge_flag = 0;
- gl_draw_triangle(c, &c->vertex[0], &c->vertex[2], &c->vertex[3]);
- n = 0;
- }
- break;
+ case GL_QUADS:
+ if (n == 4) {
+ c->vertex[2].edge_flag = 0;
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+ c->vertex[2].edge_flag = 1;
+ c->vertex[0].edge_flag = 0;
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[2], &c->vertex[3]);
+ n = 0;
+ }
+ break;
- case GL_QUAD_STRIP:
- if (n == 4) {
- gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
- gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]);
- for (i = 0; i < 2; i++)
- c->vertex[i] = c->vertex[i + 2];
- n = 2;
+ case GL_QUAD_STRIP:
+ if (n == 4) {
+ gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+ gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]);
+ for (i = 0; i < 2; i++)
+ c->vertex[i] = c->vertex[i + 2];
+ n = 2;
+ }
+ break;
+ case GL_POLYGON:
+ break;
+ default:
+ gl_fatal_error("glBegin: type %x not handled\n", c->begin_type);
}
- break;
- case GL_POLYGON:
- break;
- default:
- gl_fatal_error("glBegin: type %x not handled\n", c->begin_type);
- }
- c->vertex_n = n;
+ c->vertex_n = n;
}
-void glopEnd(GLContext * c, GLParam * param)
-{
- assert(c->in_begin == 1);
+void glopEnd(GLContext* c, GLParam* param) {
+ assert(c->in_begin == 1);
- if (c->begin_type == GL_LINE_LOOP) {
- if (c->vertex_cnt >= 3) {
- gl_draw_line(c, &c->vertex[0], &c->vertex[2]);
+ if (c->begin_type == GL_LINE_LOOP) {
+ if (c->vertex_cnt >= 3) {
+ gl_draw_line(c, &c->vertex[0], &c->vertex[2]);
+ }
+ } else if (c->begin_type == GL_POLYGON) {
+ GLint i = c->vertex_cnt;
+ while (i >= 3) {
+ i--;
+ gl_draw_triangle(c, &c->vertex[i], &c->vertex[0], &c->vertex[i - 1]);
+ }
}
- } else if (c->begin_type == GL_POLYGON) {
- GLint i = c->vertex_cnt;
- while (i >= 3) {
- i--;
- gl_draw_triangle(c, &c->vertex[i], &c->vertex[0], &c->vertex[i - 1]);
- }
- }
- c->in_begin = 0;
+ c->in_begin = 0;
}
--- a/src/zbuffer.c
+++ b/src/zbuffer.c
@@ -1,159 +1,145 @@
/*
* Z buffer: 16 bits Z / 16 bits color
- *
+ *
*/
-#include <stdlib.h>
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
//#include "../include/GL/gl.h"
#include "../include/zbuffer.h"
-ZBuffer *ZB_open(GLint xsize, GLint ysize, GLint mode,
- GLint nb_colors,
- GLubyte *color_indexes,
- GLint *color_table,
- void *frame_buffer)
-{
- ZBuffer *zb;
- GLint size;
+ZBuffer* ZB_open(GLint xsize, GLint ysize, GLint mode, GLint nb_colors, GLubyte* color_indexes, GLint* color_table, void* frame_buffer) {
+ ZBuffer* zb;
+ GLint size;
- zb = gl_malloc(sizeof(ZBuffer));
- if (zb == NULL)
- return NULL;
+ zb = gl_malloc(sizeof(ZBuffer));
+ if (zb == NULL)
+ return NULL;
- zb->xsize = xsize;
- zb->ysize = ysize;
- zb->mode = mode;
- zb->linesize = (xsize * PSZB + 3) & ~3;
+ zb->xsize = xsize;
+ zb->ysize = ysize;
+ zb->mode = mode;
+ zb->linesize = (xsize * PSZB + 3) & ~3;
- switch (mode) {
+ switch (mode) {
#ifdef TGL_FEATURE_8_BITS
- case ZB_MODE_INDEX:
- ZB_initDither(zb, nb_colors, color_indexes, color_table);
- break;
+ case ZB_MODE_INDEX:
+ ZB_initDither(zb, nb_colors, color_indexes, color_table);
+ break;
#endif
#ifdef TGL_FEATURE_32_BITS
- case ZB_MODE_RGBA:
+ case ZB_MODE_RGBA:
#endif
#ifdef TGL_FEATURE_24_BITS
- case ZB_MODE_RGB24:
+ case ZB_MODE_RGB24:
#endif
- case ZB_MODE_5R6G5B:
- zb->nb_colors = 0;
- break;
- default:
- goto error;
- }
+ case ZB_MODE_5R6G5B:
+ zb->nb_colors = 0;
+ break;
+ default:
+ goto error;
+ }
- size = zb->xsize * zb->ysize * sizeof(GLushort);
+ size = zb->xsize * zb->ysize * sizeof(GLushort);
- zb->zbuf = gl_malloc(size);
- if (zb->zbuf == NULL)
- goto error;
+ zb->zbuf = gl_malloc(size);
+ if (zb->zbuf == NULL)
+ goto error;
- if (frame_buffer == NULL) {
- zb->pbuf = gl_malloc(zb->ysize * zb->linesize);
- if (zb->pbuf == NULL) {
- gl_free(zb->zbuf);
- goto error;
+ if (frame_buffer == NULL) {
+ zb->pbuf = gl_malloc(zb->ysize * zb->linesize);
+ if (zb->pbuf == NULL) {
+ gl_free(zb->zbuf);
+ goto error;
+ }
+ zb->frame_buffer_allocated = 1;
+ } else {
+ zb->frame_buffer_allocated = 0;
+ zb->pbuf = frame_buffer;
}
- zb->frame_buffer_allocated = 1;
- } else {
- zb->frame_buffer_allocated = 0;
- zb->pbuf = frame_buffer;
- }
- zb->current_texture = NULL;
+ zb->current_texture = NULL;
- return zb;
- error:
- gl_free(zb);
- return NULL;
+ return zb;
+error:
+ gl_free(zb);
+ return NULL;
}
-void ZB_close(ZBuffer * zb)
-{
+void ZB_close(ZBuffer* zb) {
#ifdef TGL_FEATURE_8_BITS
- if (zb->mode == ZB_MODE_INDEX)
- ZB_closeDither(zb);
+ if (zb->mode == ZB_MODE_INDEX)
+ ZB_closeDither(zb);
#endif
- if (zb->frame_buffer_allocated)
- gl_free(zb->pbuf);
+ if (zb->frame_buffer_allocated)
+ gl_free(zb->pbuf);
- gl_free(zb->zbuf);
- gl_free(zb);
+ gl_free(zb->zbuf);
+ gl_free(zb);
}
-void ZB_resize(ZBuffer * zb, void *frame_buffer, GLint xsize, GLint ysize)
-{
- GLint size;
+void ZB_resize(ZBuffer* zb, void* frame_buffer, GLint xsize, GLint ysize) {
+ GLint size;
- /* xsize must be a multiple of 4 */
- xsize = xsize & ~3;
+ /* xsize must be a multiple of 4 */
+ xsize = xsize & ~3;
- zb->xsize = xsize;
- zb->ysize = ysize;
- zb->linesize = (xsize * PSZB + 3) & ~3;
+ zb->xsize = xsize;
+ zb->ysize = ysize;
+ zb->linesize = (xsize * PSZB + 3) & ~3;
- size = zb->xsize * zb->ysize * sizeof(GLushort);
+ size = zb->xsize * zb->ysize * sizeof(GLushort);
- gl_free(zb->zbuf);
- zb->zbuf = gl_malloc(size);
+ gl_free(zb->zbuf);
+ zb->zbuf = gl_malloc(size);
- if (zb->frame_buffer_allocated)
- gl_free(zb->pbuf);
+ if (zb->frame_buffer_allocated)
+ gl_free(zb->pbuf);
- if (frame_buffer == NULL) {
- zb->pbuf = gl_malloc(zb->ysize * zb->linesize);
- zb->frame_buffer_allocated = 1;
- } else {
- zb->pbuf = frame_buffer;
- zb->frame_buffer_allocated = 0;
- }
+ if (frame_buffer == NULL) {
+ zb->pbuf = gl_malloc(zb->ysize * zb->linesize);
+ zb->frame_buffer_allocated = 1;
+ } else {
+ zb->pbuf = frame_buffer;
+ zb->frame_buffer_allocated = 0;
+ }
}
-
#if TGL_FEATURE_32_BITS == 1
-inline PIXEL pxReverse32(PIXEL x)
-{
+inline PIXEL pxReverse32(PIXEL x) {
- return
- // Source is in format: 0xAARRGGBB
- ((x & 0xFF000000) >> 24) | //______AA
- ((x & 0x00FF0000) >> 8) | //____RR__
- ((x & 0x0000FF00) << 8) | //__GG____
- ((x & 0x000000FF) << 24); //BB______
- // Return value is in format: 0xBBGGRRAA
+ return
+ // Source is in format: 0xAARRGGBB
+ ((x & 0xFF000000) >> 24) | //______AA
+ ((x & 0x00FF0000) >> 8) | //____RR__
+ ((x & 0x0000FF00) << 8) | //__GG____
+ ((x & 0x000000FF) << 24); // BB______
+ // Return value is in format: 0xBBGGRRAA
}
#endif
+static void ZB_copyBuffer(ZBuffer* zb, void* buf, GLint linesize) {
+ GLubyte* p1;
+ PIXEL* q;
+ GLint y;
-static void ZB_copyBuffer(ZBuffer * zb,
- void *buf,
- GLint linesize)
-{
- GLubyte *p1;
- PIXEL *q;
- GLint y;
-
- q = zb->pbuf;
- p1 = buf;
- for (y = 0; y < zb->ysize; y++) {
- #if TGL_FEATURE_NO_COPY_COLOR == 1
- for(GLint i = 0; i < zb->xsize; i++)
- {
- if((*(q+i) & TGL_COLOR_MASK) != TGL_NO_COPY_COLOR)
- *(((PIXEL*)p1) + i) = *(q+i);
+ q = zb->pbuf;
+ p1 = buf;
+ for (y = 0; y < zb->ysize; y++) {
+#if TGL_FEATURE_NO_COPY_COLOR == 1
+ for (GLint i = 0; i < zb->xsize; i++) {
+ if ((*(q + i) & TGL_COLOR_MASK) != TGL_NO_COPY_COLOR)
+ *(((PIXEL*)p1) + i) = *(q + i);
}
- #else
+#else
memcpy(p1, q, linesize);
- #endif
+#endif
p1 += linesize;
- q = (PIXEL *) ((GLbyte *) q + zb->linesize);
- }
+ q = (PIXEL*)((GLbyte*)q + zb->linesize);
+ }
}
#if TGL_FEATURE_RENDER_BITS == 16
@@ -165,45 +151,45 @@
#define RGB16_TO_RGB32(p0,p1,v)\
{\
- GLuint g,b,gb;\
- g = (v & 0x07E007E0) << 5;\
- b = (v & 0x001F001F) << 3;\
- gb = g | b;\
- p0 = (gb & 0x0000FFFF) | ((v & 0x0000F800) << 8);\
- p1 = (gb >> 16) | ((v & 0xF8000000) >> 8);\
+ GLuint g,b,gb;\
+ g = (v & 0x07E007E0) << 5;\
+ b = (v & 0x001F001F) << 3;\
+ gb = g | b;\
+ p0 = (gb & 0x0000FFFF) | ((v & 0x0000F800) << 8);\
+ p1 = (gb >> 16) | ((v & 0xF8000000) >> 8);\
}
//This function is never called.
static void ZB_copyFrameBufferRGB32(ZBuffer * zb,
- void *buf,
- GLint linesize)
+ void *buf,
+ GLint linesize)
{
- GLushort *q;
- GLuint *p, *p1, v, w0, w1;
- GLint y, n;
+ GLushort *q;
+ GLuint *p, *p1, v, w0, w1;
+ GLint y, n;
- q = zb->pbuf;
- p1 = (GLuint *) buf;
+ q = zb->pbuf;
+ p1 = (GLuint *) buf;
//puts("\nBEING CALLED\n");
- for (y = 0; y < zb->ysize; y++) {
+ for (y = 0; y < zb->ysize; y++) {
p = p1;
n = zb->xsize >> 2;
do {
- v = *(GLuint *) q;
- RGB16_TO_RGB32(w1, w0, v);
- p[0] = w0;
- p[1] = w1;
- v = *(GLuint *) (q + 2);
- RGB16_TO_RGB32(w1, w0, v);
- p[2] = w0;
- p[3] = 0;
+ v = *(GLuint *) q;
+ RGB16_TO_RGB32(w1, w0, v);
+ p[0] = w0;
+ p[1] = w1;
+ v = *(GLuint *) (q + 2);
+ RGB16_TO_RGB32(w1, w0, v);
+ p[2] = w0;
+ p[3] = 0;
- q += 4;
- p += 4;
+ q += 4;
+ p += 4;
} while (--n > 0);
p1 += linesize;
- }
+ }
}
*/
#endif
@@ -221,19 +207,19 @@
#define RGB16_TO_RGB24(p0,p1,p2,v1,v2)\
{\
- GLuint r1,g1,b1,gb1,g2,b2,gb2;\
- v1 = (v1 << 16) | (v1 >> 16);\
- v2 = (v2 << 16) | (v2 >> 16);\
- r1 = (v1 & 0xF800F800);\
- g1 = (v1 & 0x07E007E0) << 5;\
- b1 = (v1 & 0x001F001F) << 3;\
- gb1 = g1 | b1;\
- p0 = ((gb1 & 0x0000FFFF) << 8) | (r1 << 16) | (r1 >> 24);\
- g2 = (v2 & 0x07E007E0) << 5;\
- b2 = (v2 & 0x001F001F) << 3;\
- gb2 = g2 | b2;\
- p1 = (gb1 & 0xFFFF0000) | (v2 & 0xF800) | ((gb2 >> 8) & 0xff);\
- p2 = (gb2 << 24) | ((v2 & 0xF8000000) >> 8) | (gb2 >> 16);\
+ GLuint r1,g1,b1,gb1,g2,b2,gb2;\
+ v1 = (v1 << 16) | (v1 >> 16);\
+ v2 = (v2 << 16) | (v2 >> 16);\
+ r1 = (v1 & 0xF800F800);\
+ g1 = (v1 & 0x07E007E0) << 5;\
+ b1 = (v1 & 0x001F001F) << 3;\
+ gb1 = g1 | b1;\
+ p0 = ((gb1 & 0x0000FFFF) << 8) | (r1 << 16) | (r1 >> 24);\
+ g2 = (v2 & 0x07E007E0) << 5;\
+ b2 = (v2 & 0x001F001F) << 3;\
+ gb2 = g2 | b2;\
+ p1 = (gb1 & 0xFFFF0000) | (v2 & 0xF800) | ((gb2 >> 8) & 0xff);\
+ p2 = (gb2 << 24) | ((v2 & 0xF8000000) >> 8) | (gb2 >> 16);\
}
#else
@@ -240,17 +226,17 @@
#define RGB16_TO_RGB24(p0,p1,p2,v1,v2)\
{\
- GLuint r1,g1,b1,gb1,g2,b2,gb2;\
- r1 = (v1 & 0xF800F800);\
- g1 = (v1 & 0x07E007E0) << 5;\
- b1 = (v1 & 0x001F001F) << 3;\
- gb1 = g1 | b1;\
- p0 = ((gb1 & 0x0000FFFF) << 8) | (r1 << 16) | (r1 >> 24);\
- g2 = (v2 & 0x07E007E0) << 5;\
- b2 = (v2 & 0x001F001F) << 3;\
- gb2 = g2 | b2;\
- p1 = (gb1 & 0xFFFF0000) | (v2 & 0xF800) | ((gb2 >> 8) & 0xff);\
- p2 = (gb2 << 24) | ((v2 & 0xF8000000) >> 8) | (gb2 >> 16);\
+ GLuint r1,g1,b1,gb1,g2,b2,gb2;\
+ r1 = (v1 & 0xF800F800);\
+ g1 = (v1 & 0x07E007E0) << 5;\
+ b1 = (v1 & 0x001F001F) << 3;\
+ gb1 = g1 | b1;\
+ p0 = ((gb1 & 0x0000FFFF) << 8) | (r1 << 16) | (r1 >> 24);\
+ g2 = (v2 & 0x07E007E0) << 5;\
+ b2 = (v2 & 0x001F001F) << 3;\
+ gb2 = g2 | b2;\
+ p1 = (gb1 & 0xFFFF0000) | (v2 & 0xF800) | ((gb2 >> 8) & 0xff);\
+ p2 = (gb2 << 24) | ((v2 & 0xF8000000) >> 8) | (gb2 >> 16);\
}
#endif
@@ -257,34 +243,34 @@
*/
/*
static void ZB_copyFrameBufferRGB24(ZBuffer * zb,
- void *buf,
- GLint linesize)
+ void *buf,
+ GLint linesize)
{
- GLushort *q;
- GLuint *p, *p1, w0, w1, w2, v0, v1;
- GLint y, n;
+ GLushort *q;
+ GLuint *p, *p1, w0, w1, w2, v0, v1;
+ GLint y, n;
- q = zb->pbuf;
- p1 = (GLuint *) buf;
- linesize = linesize * 3;
+ q = zb->pbuf;
+ p1 = (GLuint *) buf;
+ linesize = linesize * 3;
- for (y = 0; y < zb->ysize; y++) {
+ for (y = 0; y < zb->ysize; y++) {
p = p1;
n = zb->xsize >> 2;
do {
- v0 = *(GLuint *) q;
- v1 = *(GLuint *) (q + 2);
- RGB16_TO_RGB24(w0, w1, w2, v0, v1);
- p[0] = w0;
- p[1] = w1;
- p[2] = w2;
+ v0 = *(GLuint *) q;
+ v1 = *(GLuint *) (q + 2);
+ RGB16_TO_RGB24(w0, w1, w2, v0, v1);
+ p[0] = w0;
+ p[1] = w1;
+ p[2] = w2;
- q += 4;
- p += 3;
+ q += 4;
+ p += 3;
} while (--n > 0);
*((GLbyte *) p1) += linesize;
- }
+ }
}
*/
#endif
@@ -291,13 +277,10 @@
#if TGL_FEATURE_RENDER_BITS == 16
+void ZB_copyFrameBuffer(ZBuffer* zb, void* buf, GLint linesize) {
-void ZB_copyFrameBuffer(ZBuffer * zb, void *buf,
- GLint linesize)
-{
-
ZB_copyBuffer(zb, buf, linesize);
- //switch (zb->mode) {
+ // switch (zb->mode) {
/*
#ifdef TGL_FEATURE_8_BITS
case ZB_MODE_INDEX:
@@ -311,7 +294,6 @@
break;
#endif*/
-
/*#ifdef TGL_FEATURE_32_BITS
case ZB_MODE_RGBA:
ZB_copyFrameBufferRGB32(zb, buf, linesize >> 1);
@@ -325,10 +307,6 @@
#endif /* TGL_FEATURE_RENDER_BITS == 16 */
-
-
-
-
/*
#if TGL_FEATURE_RENDER_BITS == 24
@@ -336,231 +314,222 @@
#define RGB24_TO_RGB16(r, g, b) \
((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))
-// XXX: not optimized
-static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb,
- void *buf, GLint linesize)
+// XXX: not optimized
+static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb,
+ void *buf, GLint linesize)
{
- PIXEL *q;
- GLushort *p, *p1;
- GLint y, n;
+ PIXEL *q;
+ GLushort *p, *p1;
+ GLint y, n;
- q = zb->pbuf;
- p1 = (GLushort *) buf;
+ q = zb->pbuf;
+ p1 = (GLushort *) buf;
- for (y = 0; y < zb->ysize; y++) {
+ for (y = 0; y < zb->ysize; y++) {
p = p1;
n = zb->xsize >> 2;
do {
- p[0] = RGB24_TO_RGB16(q[0], q[1], q[2]);
- p[1] = RGB24_TO_RGB16(q[3], q[4], q[5]);
- p[2] = RGB24_TO_RGB16(q[6], q[7], q[8]);
- p[3] = RGB24_TO_RGB16(q[9], q[10], q[11]);
- q = (PIXEL *)((GLbyte *)q + 4 * PSZB);
- p += 4;
+ p[0] = RGB24_TO_RGB16(q[0], q[1], q[2]);
+ p[1] = RGB24_TO_RGB16(q[3], q[4], q[5]);
+ p[2] = RGB24_TO_RGB16(q[6], q[7], q[8]);
+ p[3] = RGB24_TO_RGB16(q[9], q[10], q[11]);
+ q = (PIXEL *)((GLbyte *)q + 4 * PSZB);
+ p += 4;
} while (--n > 0);
p1 = (GLushort *)((GLbyte *)p1 + linesize);
- }
+ }
}
void ZB_copyFrameBuffer(ZBuffer * zb, void *buf,
GLint linesize)
{
- switch (zb->mode) {
+ switch (zb->mode) {
#ifdef TGL_FEATURE_16_BITS
- case ZB_MODE_5R6G5B:
+ case ZB_MODE_5R6G5B:
ZB_copyFrameBuffer5R6G5B(zb, buf, linesize);
break;
#endif
#ifdef TGL_FEATURE_24_BITS
- case ZB_MODE_RGB24:
+ case ZB_MODE_RGB24:
ZB_copyBuffer(zb, buf, linesize);
break;
#endif
- default:
+ default:
assert(0);
- }
+ }
}
-#endif
+#endif
*/
-/* TGL_FEATURE_RENDER_BITS == 24
-*/
+/* TGL_FEATURE_RENDER_BITS == 24
+ */
#if TGL_FEATURE_RENDER_BITS == 32
-#define RGB32_TO_RGB16(v) \
- (((v >> 8) & 0xf800) | (((v) >> 5) & 0x07e0) | (((v) & 0xff) >> 3))
+#define RGB32_TO_RGB16(v) (((v >> 8) & 0xf800) | (((v) >> 5) & 0x07e0) | (((v)&0xff) >> 3))
/* XXX: not optimized */
/*
-static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb,
- void *buf, GLint linesize)
+static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb,
+ void *buf, GLint linesize)
{
- PIXEL *q;
- GLushort *p, *p1;
- GLint y, n;
+ PIXEL *q;
+ GLushort *p, *p1;
+ GLint y, n;
- q = zb->pbuf;
- p1 = (GLushort *) buf;
+ q = zb->pbuf;
+ p1 = (GLushort *) buf;
- for (y = 0; y < zb->ysize; y++) {
+ for (y = 0; y < zb->ysize; y++) {
p = p1;
n = zb->xsize >> 2;
do {
- p[0] = RGB32_TO_RGB16(q[0]);
- p[1] = RGB32_TO_RGB16(q[1]);
- p[2] = RGB32_TO_RGB16(q[2]);
- p[3] = RGB32_TO_RGB16(q[3]);
- q += 4;
- p += 4;
+ p[0] = RGB32_TO_RGB16(q[0]);
+ p[1] = RGB32_TO_RGB16(q[1]);
+ p[2] = RGB32_TO_RGB16(q[2]);
+ p[3] = RGB32_TO_RGB16(q[3]);
+ q += 4;
+ p += 4;
} while (--n > 0);
p1 = (GLushort *)((GLbyte *)p1 + linesize);
- }
+ }
}
*/
-void ZB_copyFrameBuffer(ZBuffer * zb, void *buf,
- GLint linesize)
-{
+void ZB_copyFrameBuffer(ZBuffer* zb, void* buf, GLint linesize) {
ZB_copyBuffer(zb, buf, linesize);
- //switch (zb->mode) {
- /*
+ // switch (zb->mode) {
+ /*
#ifdef TGL_FEATURE_16_BITS
- case ZB_MODE_5R6G5B:
- ZB_copyFrameBuffer5R6G5B(zb, buf, linesize);
- break;
+case ZB_MODE_5R6G5B:
+ZB_copyFrameBuffer5R6G5B(zb, buf, linesize);
+break;
#endif
- */
-/*
-#ifdef TGL_FEATURE_32_BITS
- case ZB_MODE_RGBA:
- ZB_copyBuffer(zb, buf, linesize);
- break;
-#endif
- default:
- assert(0);
- }
-*/
+ */
+ /*
+ #ifdef TGL_FEATURE_32_BITS
+ case ZB_MODE_RGBA:
+ ZB_copyBuffer(zb, buf, linesize);
+ break;
+ #endif
+ default:
+ assert(0);
+ }
+ */
}
#endif /* TGL_FEATURE_RENDER_BITS == 32 */
-
/*
* adr must be aligned on an 'int'
*/
- //Used in 16 bit mode
-void memset_s(void *adr, GLint val, GLint count)
-{
- GLint i, n, v;
- GLuint *p;
- GLushort *q;
+// Used in 16 bit mode
+void memset_s(void* adr, GLint val, GLint count) {
+ GLint i, n, v;
+ GLuint* p;
+ GLushort* q;
- p = adr;
- v = val | (val << 16);
+ p = adr;
+ v = val | (val << 16);
- n = count >> 3;
- for (i = 0; i < n; i++) {
- p[0] = v;
- p[1] = v;
- p[2] = v;
- p[3] = v;
- p += 4;
- }
+ n = count >> 3;
+ for (i = 0; i < n; i++) {
+ p[0] = v;
+ p[1] = v;
+ p[2] = v;
+ p[3] = v;
+ p += 4;
+ }
- q = (GLushort *) p;
- n = count & 7;
- for (i = 0; i < n; i++)
- *q++ = val;
+ q = (GLushort*)p;
+ n = count & 7;
+ for (i = 0; i < n; i++)
+ *q++ = val;
}
-//Used in 32 bit mode
-void memset_l(void *adr, GLint val, GLint count)
-{
- GLint i, n, v;
- GLuint *p;
+// Used in 32 bit mode
+void memset_l(void* adr, GLint val, GLint count) {
+ GLint i, n, v;
+ GLuint* p;
- p = adr;
- v = val;
- n = count >> 2;
- for (i = 0; i < n; i++) {
- p[0] = v;
- p[1] = v;
- p[2] = v;
- p[3] = v;
- p += 4;
- }
+ p = adr;
+ v = val;
+ n = count >> 2;
+ for (i = 0; i < n; i++) {
+ p[0] = v;
+ p[1] = v;
+ p[2] = v;
+ p[3] = v;
+ p += 4;
+ }
- n = count & 3;
- for (i = 0; i < n; i++)
- *p++ = val;
+ n = count & 3;
+ for (i = 0; i < n; i++)
+ *p++ = val;
}
/* count must be a multiple of 4 and >= 4 */
-//Gek's note: Should never be used.
-void memset_RGB24(void *adr,GLint r, GLint v, GLint b,long count)
-{
- long i, n;
- register long v1,v2,v3,*pt=(long *)(adr);
- GLubyte *p,R=(GLubyte)r,V=(GLubyte)v,B=(GLubyte)b;
+// Gek's note: Should never be used.
+void memset_RGB24(void* adr, GLint r, GLint v, GLint b, long count) {
+ long i, n;
+ register long v1, v2, v3, *pt = (long*)(adr);
+ GLubyte *p, R = (GLubyte)r, V = (GLubyte)v, B = (GLubyte)b;
- p=(GLubyte *)adr;
- *p++=R;
- *p++=V;
- *p++=B;
- *p++=R;
- *p++=V;
- *p++=B;
- *p++=R;
- *p++=V;
- *p++=B;
- *p++=R;
- *p++=V;
- *p++=B;
- v1=*pt++;
- v2=*pt++;
- v3=*pt++;
- n = count >> 2;
- for(i=1;i<n;i++) {
- *pt++=v1;
- *pt++=v2;
- *pt++=v3;
- }
+ p = (GLubyte*)adr;
+ *p++ = R;
+ *p++ = V;
+ *p++ = B;
+ *p++ = R;
+ *p++ = V;
+ *p++ = B;
+ *p++ = R;
+ *p++ = V;
+ *p++ = B;
+ *p++ = R;
+ *p++ = V;
+ *p++ = B;
+ v1 = *pt++;
+ v2 = *pt++;
+ v3 = *pt++;
+ n = count >> 2;
+ for (i = 1; i < n; i++) {
+ *pt++ = v1;
+ *pt++ = v2;
+ *pt++ = v3;
+ }
}
-void ZB_clear(ZBuffer * zb, GLint clear_z, GLint z,
- GLint clear_color, GLint r, GLint g, GLint b)
-{
-//#if TGL_FEATURE_RENDER_BITS != 24
- GLuint color;
-//#endif
- GLint y;
- PIXEL *pp;
+void ZB_clear(ZBuffer* zb, GLint clear_z, GLint z, GLint clear_color, GLint r, GLint g, GLint b) {
+ //#if TGL_FEATURE_RENDER_BITS != 24
+ GLuint color;
+ //#endif
+ GLint y;
+ PIXEL* pp;
- if (clear_z) {
- memset_s(zb->zbuf, z, zb->xsize * zb->ysize);
- }
- if (clear_color) {
- pp = zb->pbuf;
- for (y = 0; y < zb->ysize; y++) {
+ if (clear_z) {
+ memset_s(zb->zbuf, z, zb->xsize * zb->ysize);
+ }
+ if (clear_color) {
+ pp = zb->pbuf;
+ for (y = 0; y < zb->ysize; y++) {
#if TGL_FEATURE_RENDER_BITS == 15 || TGL_FEATURE_RENDER_BITS == 16
- //color = RGB_TO_PIXEL(r, g, b);
- #if TGL_FEATURE_FORCE_CLEAR_NO_COPY_COLOR
- color = TGL_NO_COPY_COLOR;
- #else
- color = RGB_TO_PIXEL(r, g, b);
- #endif
- memset_s(pp, color, zb->xsize);
+ // color = RGB_TO_PIXEL(r, g, b);
+#if TGL_FEATURE_FORCE_CLEAR_NO_COPY_COLOR
+ color = TGL_NO_COPY_COLOR;
+#else
+ color = RGB_TO_PIXEL(r, g, b);
+#endif
+ memset_s(pp, color, zb->xsize);
#elif TGL_FEATURE_RENDER_BITS == 32
- #if TGL_FEATURE_FORCE_CLEAR_NO_COPY_COLOR
+#if TGL_FEATURE_FORCE_CLEAR_NO_COPY_COLOR
color = TGL_NO_COPY_COLOR;
- #else
- color = RGB_TO_PIXEL(r, g, b);
- #endif
- memset_l(pp, color, zb->xsize);
#else
+ color = RGB_TO_PIXEL(r, g, b);
+#endif
+ memset_l(pp, color, zb->xsize);
+#else
#error BADJUJU
#endif
- pp = (PIXEL *) ((GLbyte *) pp + zb->linesize);
+ pp = (PIXEL*)((GLbyte*)pp + zb->linesize);
+ }
}
- }
}
--- a/src/zdither.c
+++ b/src/zdither.c
@@ -1,81 +1,77 @@
-/*
- * Highly optimised dithering 16 bits -> 8 bits.
+/*
+ * Highly optimised dithering 16 bits -> 8 bits.
* The formulas were taken in Mesa (Bob Mercier mercier@hollywood.cinenet.net).
*/
-#include <stdlib.h>
-#include <stdio.h>
#include "../include/zbuffer.h"
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
#if defined(TGL_FEATURE_8_BITS)
-#define _R 5
-#define _G 9
-#define _B 5
-#define _DX 4
-#define _DY 4
-#define _D (_DX*_DY)
-#define _MIX(r,g,b) ( ((g)<<6) | ((b)<<3) | (r) )
+#define _R 5
+#define _G 9
+#define _B 5
+#define _DX 4
+#define _DY 4
+#define _D (_DX * _DY)
+#define _MIX(r, g, b) (((g) << 6) | ((b) << 3) | (r))
#define DITHER_TABLE_SIZE (1 << 15)
-#define DITHER_INDEX(r,g,b) ((b) + (g) * _B + (r) * (_B * _G))
+#define DITHER_INDEX(r, g, b) ((b) + (g)*_B + (r) * (_B * _G))
-#define MAXC 256
-static GLint kernel8[_DY*_DX] = {
- 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC,
- 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
- 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC,
- 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
+#define MAXC 256
+static GLint kernel8[_DY * _DX] = {
+ 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC, 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
+ 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC, 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
};
/* we build the color table and the lookup table */
-void ZB_initDither(ZBuffer *zb,GLint nb_colors,
- GLubyte *color_indexes,GLint *color_table)
-{
- GLint c,r,g,b,i,index,r1,g1,b1;
+void ZB_initDither(ZBuffer* zb, GLint nb_colors, GLubyte* color_indexes, GLint* color_table) {
+ GLint c, r, g, b, i, index, r1, g1, b1;
- if (nb_colors < (_R * _G * _B)) {
- fprintf(stderr,"zdither: not enough colors\n");
- exit(1);
- }
+ if (nb_colors < (_R * _G * _B)) {
+ fprintf(stderr, "zdither: not enough colors\n");
+ exit(1);
+ }
- for(i=0;i<nb_colors;i++) color_table[i]=0;
+ for (i = 0; i < nb_colors; i++)
+ color_table[i] = 0;
- zb->nb_colors=nb_colors;
- zb->ctable=gl_malloc(nb_colors * sizeof(GLint));
+ zb->nb_colors = nb_colors;
+ zb->ctable = gl_malloc(nb_colors * sizeof(GLint));
- for (r = 0; r < _R; r++) {
- for (g = 0; g < _G; g++) {
- for (b = 0; b < _B; b++) {
- r1=(r*255) / (_R - 1);
- g1=(g*255) / (_G - 1);
- b1=(b*255) / (_B - 1);
- index=DITHER_INDEX(r,g,b);
- c=(r1 << 16) | (g1 << 8) | b1;
- zb->ctable[index]=c;
- color_table[index]=c;
- }
- }
- }
+ for (r = 0; r < _R; r++) {
+ for (g = 0; g < _G; g++) {
+ for (b = 0; b < _B; b++) {
+ r1 = (r * 255) / (_R - 1);
+ g1 = (g * 255) / (_G - 1);
+ b1 = (b * 255) / (_B - 1);
+ index = DITHER_INDEX(r, g, b);
+ c = (r1 << 16) | (g1 << 8) | b1;
+ zb->ctable[index] = c;
+ color_table[index] = c;
+ }
+ }
+ }
- zb->dctable=gl_malloc( DITHER_TABLE_SIZE );
+ zb->dctable = gl_malloc(DITHER_TABLE_SIZE);
- for(i=0;i<DITHER_TABLE_SIZE;i++) {
- r=(i >> 12) & 0x7;
- g=(i >> 8) & 0xF;
- b=(i >> 3) & 0x7;
- index=DITHER_INDEX(r,g,b);
- zb->dctable[i]=color_indexes[index];
- }
+ for (i = 0; i < DITHER_TABLE_SIZE; i++) {
+ r = (i >> 12) & 0x7;
+ g = (i >> 8) & 0xF;
+ b = (i >> 3) & 0x7;
+ index = DITHER_INDEX(r, g, b);
+ zb->dctable[i] = color_indexes[index];
+ }
}
-void ZB_closeDither(ZBuffer *zb)
-{
- gl_free(zb->ctable);
- gl_free(zb->dctable);
+void ZB_closeDither(ZBuffer* zb) {
+ gl_free(zb->ctable);
+ gl_free(zb->dctable);
}
#if 0
@@ -86,76 +82,73 @@
}
#endif
+#define DITHER_PIXEL2(a) \
+ { \
+ register GLint v, t, r, g, c; \
+ v = *(GLuint*)(pp + (a)); \
+ g = (v & 0x07DF07DF) + g_d; \
+ r = (((v & 0xF800F800) >> 2) + r_d) & 0x70007000; \
+ t = r | g; \
+ c = ctable[t & 0xFFFF] | (ctable[t >> 16] << 8); \
+ *(GLushort*)(dest + (a)) = c; \
+ }
-#define DITHER_PIXEL2(a) \
-{ \
- register GLint v,t,r,g,c; \
- v=*(GLuint *)(pp+(a)); \
- g=(v & 0x07DF07DF) + g_d; \
- r=(((v & 0xF800F800) >> 2) + r_d) & 0x70007000; \
- t=r | g; \
- c=ctable[t & 0xFFFF] | (ctable[t >> 16] << 8); \
- *(GLushort *)(dest+(a))=c; \
-}
-
/* NOTE: all the memory access are 16 bit aligned, so if buf or
linesize are not multiple of 2, it cannot work efficiently (or
hang!) */
-void ZB_ditherFrameBuffer(ZBuffer *zb,GLubyte *buf,
- GLint linesize)
-{
- GLint xk,yk,x,y,c1,c2;
- GLubyte *dest1;
- GLushort *pp1;
- GLint r_d,g_d,b_d;
- GLubyte *ctable=zb->dctable;
- register GLubyte *dest;
- register GLushort *pp;
+void ZB_ditherFrameBuffer(ZBuffer* zb, GLubyte* buf, GLint linesize) {
+ GLint xk, yk, x, y, c1, c2;
+ GLubyte* dest1;
+ GLushort* pp1;
+ GLint r_d, g_d, b_d;
+ GLubyte* ctable = zb->dctable;
+ register GLubyte* dest;
+ register GLushort* pp;
- assert( ((long)buf & 1) == 0 && (linesize & 1) == 0);
+ assert(((long)buf & 1) == 0 && (linesize & 1) == 0);
- for(yk=0;yk<4;yk++) {
- for(xk=0;xk<4;xk+=2) {
+ for (yk = 0; yk < 4; yk++) {
+ for (xk = 0; xk < 4; xk += 2) {
#if BYTE_ORDER == BIG_ENDIAN
- c1=kernel8[yk*4+xk+1];
- c2=kernel8[yk*4+xk];
+ c1 = kernel8[yk * 4 + xk + 1];
+ c2 = kernel8[yk * 4 + xk];
#else
- c1=kernel8[yk*4+xk];
- c2=kernel8[yk*4+xk+1];
+ c1 = kernel8[yk * 4 + xk];
+ c2 = kernel8[yk * 4 + xk + 1];
#endif
- r_d=((c1 << 2) & 0xF800) >> 2;
- g_d=(c1 >> 4) & 0x07C0;
- b_d=(c1 >> 9) & 0x001F;
-
- r_d|=(((c2 << 2) & 0xF800) >> 2) << 16;
- g_d|=((c2 >> 4) & 0x07C0) << 16;
- b_d|=((c2 >> 9) & 0x001F) << 16;
- g_d=b_d | g_d;
+ r_d = ((c1 << 2) & 0xF800) >> 2;
+ g_d = (c1 >> 4) & 0x07C0;
+ b_d = (c1 >> 9) & 0x001F;
- dest1=buf + (yk * linesize) + xk;
- //NOTE BY GEK: The following line was modified to fix a compiler warning,
- //casting zb->pbuf to GLushort*
- pp1=(GLushort*)(zb->pbuf) + (yk * zb->xsize) + xk;
-
- for(y=yk;y<zb->ysize;y+=4) {
- dest=dest1;
- pp=pp1;
- for(x=xk;x<zb->xsize;x+=16) {
+ r_d |= (((c2 << 2) & 0xF800) >> 2) << 16;
+ g_d |= ((c2 >> 4) & 0x07C0) << 16;
+ b_d |= ((c2 >> 9) & 0x001F) << 16;
+ g_d = b_d | g_d;
- DITHER_PIXEL2(0);
- DITHER_PIXEL2(1*4);
- DITHER_PIXEL2(2*4);
- DITHER_PIXEL2(3*4);
+ dest1 = buf + (yk * linesize) + xk;
+ // NOTE BY GEK: The following line was modified to fix a compiler warning,
+ // casting zb->pbuf to GLushort*
+ pp1 = (GLushort*)(zb->pbuf) + (yk * zb->xsize) + xk;
- pp+=16;
- dest+=16;
+ for (y = yk; y < zb->ysize; y += 4) {
+ dest = dest1;
+ pp = pp1;
+ for (x = xk; x < zb->xsize; x += 16) {
+
+ DITHER_PIXEL2(0);
+ DITHER_PIXEL2(1 * 4);
+ DITHER_PIXEL2(2 * 4);
+ DITHER_PIXEL2(3 * 4);
+
+ pp += 16;
+ dest += 16;
+ }
+ dest1 += linesize * 4;
+ pp1 += zb->xsize * 4;
+ }
+ }
}
- dest1+=linesize*4;
- pp1+=zb->xsize*4;
- }
- }
- }
}
#endif
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -1,14 +1,14 @@
#ifndef _tgl_zgl_h_
#define _tgl_zgl_h_
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <assert.h>
#include "../include/GL/gl.h"
#include "../include/zbuffer.h"
-#include "zmath.h"
#include "../include/zfeatures.h"
+#include "zmath.h"
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
#ifndef M_PI
#define M_PI 3.14159265358979323
#endif
@@ -17,7 +17,7 @@
enum {
-#define ADD_OP(a,b,c) OP_ ## a ,
+#define ADD_OP(a, b, c) OP_##a,
#include "opinfo.h"
@@ -34,13 +34,12 @@
/* specular buffer granularity */
#define SPECULAR_BUFFER_RESOLUTION 1024
-
-#define MAX_MODELVIEW_STACK_DEPTH 32
+#define MAX_MODELVIEW_STACK_DEPTH 32
#define MAX_PROJECTION_STACK_DEPTH 8
-#define MAX_TEXTURE_STACK_DEPTH 8
-#define MAX_NAME_STACK_DEPTH 64
-#define MAX_TEXTURE_LEVELS 11
-#define MAX_LIGHTS 16
+#define MAX_TEXTURE_STACK_DEPTH 8
+#define MAX_NAME_STACK_DEPTH 64
+#define MAX_TEXTURE_LEVELS 11
+#define MAX_LIGHTS 16
#define VERTEX_HASH_SIZE 1031
@@ -47,90 +46,89 @@
#define MAX_DISPLAY_LISTS 1024
#define OP_BUFFER_MAX_SIZE 512
-#define TGL_OFFSET_FILL 0x1
-#define TGL_OFFSET_LINE 0x2
-#define TGL_OFFSET_POINT 0x4
+#define TGL_OFFSET_FILL 0x1
+#define TGL_OFFSET_LINE 0x2
+#define TGL_OFFSET_POINT 0x4
typedef struct GLSpecBuf {
- GLint shininess_i;
- GLint last_used;
- GLfloat buf[SPECULAR_BUFFER_SIZE+1];
- struct GLSpecBuf *next;
+ GLint shininess_i;
+ GLint last_used;
+ GLfloat buf[SPECULAR_BUFFER_SIZE + 1];
+ struct GLSpecBuf* next;
} GLSpecBuf;
typedef struct GLLight {
- V4 ambient;
- V4 diffuse;
- V4 specular;
- V4 position;
- V3 spot_direction;
- GLfloat spot_exponent;
- GLfloat spot_cutoff;
- GLfloat attenuation[3];
- /* precomputed values */
- GLfloat cos_spot_cutoff;
- V3 norm_spot_direction;
- V3 norm_position;
- /* we use a linked list to know which are the enabled lights */
- GLint enabled;
- struct GLLight *next,*prev;
+ V4 ambient;
+ V4 diffuse;
+ V4 specular;
+ V4 position;
+ V3 spot_direction;
+ GLfloat spot_exponent;
+ GLfloat spot_cutoff;
+ GLfloat attenuation[3];
+ /* precomputed values */
+ GLfloat cos_spot_cutoff;
+ V3 norm_spot_direction;
+ V3 norm_position;
+ /* we use a linked list to know which are the enabled lights */
+ GLint enabled;
+ struct GLLight *next, *prev;
} GLLight;
typedef struct GLMaterial {
- V4 emission;
- V4 ambient;
- V4 diffuse;
- V4 specular;
- GLfloat shininess;
+ V4 emission;
+ V4 ambient;
+ V4 diffuse;
+ V4 specular;
+ GLfloat shininess;
- /* computed values */
- GLint shininess_i;
- GLint do_specular;
+ /* computed values */
+ GLint shininess_i;
+ GLint do_specular;
} GLMaterial;
-
typedef struct GLViewport {
- GLint xmin,ymin,xsize,ysize;
- V3 scale;
- V3 trans;
- GLint updated;
+ GLint xmin, ymin, xsize, ysize;
+ V3 scale;
+ V3 trans;
+ GLint updated;
} GLViewport;
typedef union {
- GLint op;
- GLfloat f;
- GLint i;
- GLuint ui;
- void *p;
+ GLint op;
+ GLfloat f;
+ GLint i;
+ GLuint ui;
+ void* p;
} GLParam;
typedef struct GLParamBuffer {
- GLParam ops[OP_BUFFER_MAX_SIZE];
- struct GLParamBuffer *next;
+ GLParam ops[OP_BUFFER_MAX_SIZE];
+ struct GLParamBuffer* next;
} GLParamBuffer;
typedef struct GLList {
- GLParamBuffer *first_op_buffer;
- /* TODO: extensions for an hash table or a better allocating scheme */
+ GLParamBuffer* first_op_buffer;
+ /* TODO: extensions for an hash table or a better allocating scheme */
} GLList;
typedef struct GLVertex {
- GLint edge_flag;
- V3 normal;
- V4 coord;
- V4 tex_coord;
- V4 color;
-
- /* computed values */
- V4 ec; /* eye coordinates */
- V4 pc; /* coordinates in the normalized volume */
- GLint clip_code; /* clip code */
- ZBufferPoint zp; /* GLinteger coordinates for the rasterization */
+ GLint edge_flag;
+ V3 normal;
+ V4 coord;
+ V4 tex_coord;
+ V4 color;
+
+ /* computed values */
+ V4 ec; /* eye coordinates */
+ V4 pc; /* coordinates in the normalized volume */
+ GLint clip_code; /* clip code */
+ ZBufferPoint zp; /* GLinteger coordinates for the rasterization */
} GLVertex;
typedef struct GLImage {
- void *pixmap;
- GLint xsize,ysize;
+ void* pixmap;
+ GLint xsize, ysize;
} GLImage;
/* textures */
@@ -138,209 +136,196 @@
#define TEXTURE_HASH_TABLE_SIZE 256
typedef struct GLTexture {
- GLImage images[MAX_TEXTURE_LEVELS];
- GLint handle;
- struct GLTexture *next,*prev;
+ GLImage images[MAX_TEXTURE_LEVELS];
+ GLint handle;
+ struct GLTexture *next, *prev;
} GLTexture;
-
/* shared state */
typedef struct GLSharedState {
- GLList **lists;
- GLTexture **texture_hash_table;
+ GLList** lists;
+ GLTexture** texture_hash_table;
} GLSharedState;
struct GLContext;
-typedef void (*gl_draw_triangle_func)(struct GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2);
+typedef void (*gl_draw_triangle_func)(struct GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
/* display context */
typedef struct GLContext {
- /* Z buffer */
- ZBuffer *zb;
+ /* Z buffer */
+ ZBuffer* zb;
- /* lights */
- GLLight lights[MAX_LIGHTS];
- GLLight *first_light;
- V4 ambient_light_model;
- GLint local_light_model;
- GLint lighting_enabled;
- GLint light_model_two_side;
+ /* lights */
+ GLLight lights[MAX_LIGHTS];
+ GLLight* first_light;
+ V4 ambient_light_model;
+ GLint local_light_model;
+ GLint lighting_enabled;
+ GLint light_model_two_side;
- /* materials */
- GLMaterial materials[2];
- GLint color_material_enabled;
- GLint current_color_material_mode;
- GLint current_color_material_type;
+ /* materials */
+ GLMaterial materials[2];
+ GLint color_material_enabled;
+ GLint current_color_material_mode;
+ GLint current_color_material_type;
- /* textures */
- GLTexture *current_texture;
- GLint texture_2d_enabled;
+ /* textures */
+ GLTexture* current_texture;
+ GLint texture_2d_enabled;
- /* shared state */
- GLSharedState shared_state;
+ /* shared state */
+ GLSharedState shared_state;
- /* current list */
- GLParamBuffer *current_op_buffer;
- GLint current_op_buffer_index;
- GLint exec_flag,compile_flag,print_flag;
+ /* current list */
+ GLParamBuffer* current_op_buffer;
+ GLint current_op_buffer_index;
+ GLint exec_flag, compile_flag, print_flag;
- /* matrix */
+ /* matrix */
- GLint matrix_mode;
- M4 *matrix_stack[3];
- M4 *matrix_stack_ptr[3];
- GLint matrix_stack_depth_max[3];
+ GLint matrix_mode;
+ M4* matrix_stack[3];
+ M4* matrix_stack_ptr[3];
+ GLint matrix_stack_depth_max[3];
- M4 matrix_model_view_inv;
- M4 matrix_model_projection;
- GLint matrix_model_projection_updated;
- GLint matrix_model_projection_no_w_transform;
- GLint apply_texture_matrix;
+ M4 matrix_model_view_inv;
+ M4 matrix_model_projection;
+ GLint matrix_model_projection_updated;
+ GLint matrix_model_projection_no_w_transform;
+ GLint apply_texture_matrix;
- /* viewport */
- GLViewport viewport;
+ /* viewport */
+ GLViewport viewport;
- /* current state */
- GLint polygon_mode_back;
- GLint polygon_mode_front;
+ /* current state */
+ GLint polygon_mode_back;
+ GLint polygon_mode_front;
- GLint current_front_face;
- GLint current_shade_model;
- GLint current_cull_face;
- GLint cull_face_enabled;
- GLint normalize_enabled;
- gl_draw_triangle_func draw_triangle_front,draw_triangle_back;
+ GLint current_front_face;
+ GLint current_shade_model;
+ GLint current_cull_face;
+ GLint cull_face_enabled;
+ GLint normalize_enabled;
+ gl_draw_triangle_func draw_triangle_front, draw_triangle_back;
- /* selection */
- GLint render_mode;
- GLuint *select_buffer;
- GLint select_size;
- GLuint *select_ptr,*select_hit;
- GLint select_overflow;
- GLint select_hits;
+ /* selection */
+ GLint render_mode;
+ GLuint* select_buffer;
+ GLint select_size;
+ GLuint *select_ptr, *select_hit;
+ GLint select_overflow;
+ GLint select_hits;
- /* names */
- GLuint name_stack[MAX_NAME_STACK_DEPTH];
- GLint name_stack_size;
+ /* names */
+ GLuint name_stack[MAX_NAME_STACK_DEPTH];
+ GLint name_stack_size;
- /* clear */
- GLfloat clear_depth;
- V4 clear_color;
+ /* clear */
+ GLfloat clear_depth;
+ V4 clear_color;
- /* current vertex state */
- V4 current_color;
- //GLuint longcurrent_color[3]; /* precomputed GLinteger color */
- V4 current_normal;
- V4 current_tex_coord;
- GLint current_edge_flag;
+ /* current vertex state */
+ V4 current_color;
+ // GLuint longcurrent_color[3]; /* precomputed GLinteger color */
+ V4 current_normal;
+ V4 current_tex_coord;
+ GLint current_edge_flag;
- /* glBegin / glEnd */
- GLint in_begin;
- GLint begin_type;
- GLint vertex_n,vertex_cnt;
- GLint vertex_max;
- GLVertex *vertex;
+ /* glBegin / glEnd */
+ GLint in_begin;
+ GLint begin_type;
+ GLint vertex_n, vertex_cnt;
+ GLint vertex_max;
+ GLVertex* vertex;
- /* opengl 1.1 arrays */
- GLfloat *vertex_array;
- GLint vertex_array_size;
- GLint vertex_array_stride;
- GLfloat *normal_array;
- GLint normal_array_stride;
- GLfloat *color_array;
- GLint color_array_size;
- GLint color_array_stride;
- GLfloat *texcoord_array;
- GLint texcoord_array_size;
- GLint texcoord_array_stride;
- GLint client_states;
-
- /* opengl 1.1 polygon offset */
- GLfloat offset_factor;
- GLfloat offset_units;
- GLint offset_states;
-
- /* specular buffer. could probably be shared between contexts,
- but that wouldn't be 100% thread safe */
- GLSpecBuf *specbuf_first;
- GLint specbuf_used_counter;
- GLint specbuf_num_buffers;
+ /* opengl 1.1 arrays */
+ GLfloat* vertex_array;
+ GLint vertex_array_size;
+ GLint vertex_array_stride;
+ GLfloat* normal_array;
+ GLint normal_array_stride;
+ GLfloat* color_array;
+ GLint color_array_size;
+ GLint color_array_stride;
+ GLfloat* texcoord_array;
+ GLint texcoord_array_size;
+ GLint texcoord_array_stride;
+ GLint client_states;
- /* opaque structure for user's use */
- void *opaque;
- /* resize viewport function */
- GLint (*gl_resize_viewport)(struct GLContext *c,GLint *xsize,GLint *ysize);
+ /* opengl 1.1 polygon offset */
+ GLfloat offset_factor;
+ GLfloat offset_units;
+ GLint offset_states;
- /* depth test */
- GLint depth_test;
+ /* specular buffer. could probably be shared between contexts,
+ but that wouldn't be 100% thread safe */
+ GLSpecBuf* specbuf_first;
+ GLint specbuf_used_counter;
+ GLint specbuf_num_buffers;
+
+ /* opaque structure for user's use */
+ void* opaque;
+ /* resize viewport function */
+ GLint (*gl_resize_viewport)(struct GLContext* c, GLint* xsize, GLint* ysize);
+
+ /* depth test */
+ GLint depth_test;
} GLContext;
-extern GLContext *gl_ctx;
+extern GLContext* gl_ctx;
-void gl_add_op(GLParam *p);
+void gl_add_op(GLParam* p);
/* clip.c */
-void gl_transform_to_viewport(GLContext *c,GLVertex *v);
-void gl_draw_triangle(GLContext *c,GLVertex *p0,GLVertex *p1,GLVertex *p2);
-void gl_draw_line(GLContext *c,GLVertex *p0,GLVertex *p1);
-void gl_draw_point(GLContext *c,GLVertex *p0);
+void gl_transform_to_viewport(GLContext* c, GLVertex* v);
+void gl_draw_triangle(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+void gl_draw_line(GLContext* c, GLVertex* p0, GLVertex* p1);
+void gl_draw_point(GLContext* c, GLVertex* p0);
-void gl_draw_triangle_point(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2);
-void gl_draw_triangle_line(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2);
-void gl_draw_triangle_fill(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2);
-void gl_draw_triangle_select(GLContext *c,
- GLVertex *p0,GLVertex *p1,GLVertex *p2);
+void gl_draw_triangle_point(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+void gl_draw_triangle_line(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+void gl_draw_triangle_fill(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+void gl_draw_triangle_select(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
/* matrix.c */
-void gl_print_matrix(const GLfloat *m);
+void gl_print_matrix(const GLfloat* m);
/*
void glopLoadIdentity(GLContext *c,GLParam *p);
void glopTranslate(GLContext *c,GLParam *p);*/
/* light.c */
-void gl_add_select(GLContext *c,GLuint zmin,GLuint zmax);
-void gl_enable_disable_light(GLContext *c,GLint light,GLint v);
-void gl_shade_vertex(GLContext *c,GLVertex *v);
+void gl_add_select(GLContext* c, GLuint zmin, GLuint zmax);
+void gl_enable_disable_light(GLContext* c, GLint light, GLint v);
+void gl_shade_vertex(GLContext* c, GLVertex* v);
-void glInitTextures(GLContext *c);
-void glEndTextures(GLContext *c);
-GLTexture *alloc_texture(GLContext *c,GLint h);
+void glInitTextures(GLContext* c);
+void glEndTextures(GLContext* c);
+GLTexture* alloc_texture(GLContext* c, GLint h);
/* image_util.c */
-void gl_convertRGB_to_5R6G5B(GLushort *pixmap,GLubyte *rgb,
- GLint xsize,GLint ysize);
-void gl_convertRGB_to_8A8R8G8B(GLuint *pixmap, GLubyte *rgb,
- GLint xsize, GLint ysize);
-void gl_resizeImage(GLubyte *dest,GLint xsize_dest,GLint ysize_dest,
- GLubyte *src,GLint xsize_src,GLint ysize_src);
-void gl_resizeImageNoInterpolate(GLubyte *dest,GLint xsize_dest,GLint ysize_dest,
- GLubyte *src,GLint xsize_src,GLint ysize_src);
+void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize);
+void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize);
+void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src);
+void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src);
-GLContext *gl_get_context(void);
+GLContext* gl_get_context(void);
-void gl_fatal_error(char *format, ...);
+void gl_fatal_error(char* format, ...);
-
/* specular buffer "api" */
-GLSpecBuf *specbuf_get_buffer(GLContext *c, const GLint shininess_i,
- const GLfloat shininess);
+GLSpecBuf* specbuf_get_buffer(GLContext* c, const GLint shininess_i, const GLfloat shininess);
#ifdef __BEOS__
-void dprintf(const char *, ...);
+void dprintf(const char*, ...);
#else /* !BEOS */
#ifdef DEBUG
-#define dprintf(format, args...) \
- fprintf(stderr,"In '%s': " format "\n",__FUNCTION__, ##args);
+#define dprintf(format, args...) fprintf(stderr, "In '%s': " format "\n", __FUNCTION__, ##args);
#else
@@ -351,7 +336,7 @@
/* glopXXX functions */
-#define ADD_OP(a,b,c) void glop ## a (GLContext *,GLParam *);
+#define ADD_OP(a, b, c) void glop##a(GLContext*, GLParam*);
#include "opinfo.h"
/* this clip epsilon is needed to avoid some rounding errors after
@@ -359,17 +344,11 @@
#define CLIP_EPSILON (1E-5)
-static inline GLint gl_clipcode(GLfloat x,GLfloat y,GLfloat z,GLfloat w1)
-{
- GLfloat w;
+static inline GLint gl_clipcode(GLfloat x, GLfloat y, GLfloat z, GLfloat w1) {
+ GLfloat w;
- w=w1 * (1.0 + CLIP_EPSILON);
- return (x<-w) |
- ((x>w)<<1) |
- ((y<-w)<<2) |
- ((y>w)<<3) |
- ((z<-w)<<4) |
- ((z>w)<<5) ;
+ w = w1 * (1.0 + CLIP_EPSILON);
+ return (x < -w) | ((x > w) << 1) | ((y < -w) << 2) | ((y > w) << 3) | ((z < -w) << 4) | ((z > w) << 5);
}
#endif /* _tgl_zgl_h_ */
--- a/src/zline.c
+++ b/src/zline.c
@@ -1,42 +1,39 @@
-#include <stdlib.h>
#include "../include/zbuffer.h"
+#include <stdlib.h>
-#define ZCMP(z,zpix) ((z) >= (zpix))
+#define ZCMP(z, zpix) ((z) >= (zpix))
-void ZB_plot(ZBuffer * zb, ZBufferPoint * p)
-{
- GLushort *pz;
- PIXEL *pp;
- GLint zz;
- #if TGL_FEATURE_NO_DRAW_COLOR == 1
+void ZB_plot(ZBuffer* zb, ZBufferPoint* p) {
+ GLushort* pz;
+ PIXEL* pp;
+ GLint zz;
+#if TGL_FEATURE_NO_DRAW_COLOR == 1
PIXEL col;
- #endif
- pz = zb->zbuf + (p->y * zb->xsize + p->x);
- pp = (PIXEL *) ((GLbyte *) zb->pbuf + zb->linesize * p->y + p->x * PSZB);
- zz = p->z >> ZB_POINT_Z_FRAC_BITS;
- if (ZCMP(zz, *pz)) {
-//#if TGL_FEATURE_RENDER_BITS == 24
- //pp[0]=p->r>>8;
- //pp[1]=p->g>>8;
- //pp[2]=p->b>>8;
+#endif
+ pz = zb->zbuf + (p->y * zb->xsize + p->x);
+ pp = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * p->y + p->x * PSZB);
+ zz = p->z >> ZB_POINT_Z_FRAC_BITS;
+ if (ZCMP(zz, *pz)) {
+//#if TGL_FEATURE_RENDER_BITS == 24
+// pp[0]=p->r>>8;
+// pp[1]=p->g>>8;
+// pp[2]=p->b>>8;
//#else
#if TGL_FEATURE_NO_DRAW_COLOR == 1
-#define NODRAWTEST(color) ( (color & TGL_COLOR_MASK) != TGL_NO_DRAW_COLOR)
+#define NODRAWTEST(color) ((color & TGL_COLOR_MASK) != TGL_NO_DRAW_COLOR)
col = RGB_TO_PIXEL(p->r, p->g, p->b);
- if(NODRAWTEST(col))
+ if (NODRAWTEST(col))
*pp = RGB_TO_PIXEL(p->r, p->g, p->b);
#else
*pp = RGB_TO_PIXEL(p->r, p->g, p->b);
#endif
-//#endif
- *pz = zz;
- }
+ //#endif
+ *pz = zz;
+ }
}
#define INTERP_Z
-static void ZB_line_flat_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2,
- GLint color)
-{
+static void ZB_line_flat_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2, GLint color) {
#include "zline.h"
}
@@ -43,51 +40,45 @@
/* line with color GLinterpolation */
#define INTERP_Z
#define INTERP_RGB
-static void ZB_line_interp_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
-{
+static void ZB_line_interp_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
#include "zline.h"
}
/* no Z GLinterpolation */
-static void ZB_line_flat(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2,
- GLint color)
-{
+static void ZB_line_flat(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2, GLint color) {
#include "zline.h"
}
#define INTERP_RGB
-static void ZB_line_interp(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
-{
+static void ZB_line_interp(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
#include "zline.h"
}
-void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
-{
- GLint color1, color2;
+void ZB_line_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
+ GLint color1, color2;
- color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
- color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
+ color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
+ color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
- /* choose if the line should have its color GLinterpolated or not */
- if (color1 == color2) {
- ZB_line_flat_z(zb, p1, p2, color1);
- } else {
- ZB_line_interp_z(zb, p1, p2);
- }
+ /* choose if the line should have its color GLinterpolated or not */
+ if (color1 == color2) {
+ ZB_line_flat_z(zb, p1, p2, color1);
+ } else {
+ ZB_line_interp_z(zb, p1, p2);
+ }
}
-void ZB_line(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
-{
- GLint color1, color2;
+void ZB_line(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
+ GLint color1, color2;
- color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
- color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
+ color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
+ color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
- /* choose if the line should have its color GLinterpolated or not */
- if (color1 == color2) {
- ZB_line_flat(zb, p1, p2, color1);
- } else {
- ZB_line_interp(zb, p1, p2);
- }
+ /* choose if the line should have its color GLinterpolated or not */
+ if (color1 == color2) {
+ ZB_line_flat(zb, p1, p2, color1);
+ } else {
+ ZB_line_interp(zb, p1, p2);
+ }
}
--- a/src/zline.h
+++ b/src/zline.h
@@ -1,43 +1,43 @@
{
- GLint n, dx, dy, sx, pp_inc_1, pp_inc_2;
- register GLint a;
- register PIXEL *pp;
+ GLint n, dx, dy, sx, pp_inc_1, pp_inc_2;
+ register GLint a;
+ register PIXEL* pp;
#if defined(INTERP_RGB) || TGL_FEATURE_RENDER_BITS == 24
- register GLuint r, g, b;
+ register GLuint r, g, b;
#endif
#ifdef INTERP_RGB
- register GLuint rinc, ginc, binc;
+ register GLuint rinc, ginc, binc;
#endif
#ifdef INTERP_Z
- register GLushort *pz;
- GLint zinc;
- register GLint z, zz;
+ register GLushort* pz;
+ GLint zinc;
+ register GLint z, zz;
#endif
- if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) {
- ZBufferPoint *tmp;
- tmp = p1;
- p1 = p2;
- p2 = tmp;
- }
- sx = zb->xsize;
- pp = (PIXEL *) ((GLbyte *) zb->pbuf + zb->linesize * p1->y + p1->x * PSZB);
+ if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) {
+ ZBufferPoint* tmp;
+ tmp = p1;
+ p1 = p2;
+ p2 = tmp;
+ }
+ sx = zb->xsize;
+ pp = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * p1->y + p1->x * PSZB);
#ifdef INTERP_Z
- pz = zb->zbuf + (p1->y * sx + p1->x);
- z = p1->z;
+ pz = zb->zbuf + (p1->y * sx + p1->x);
+ z = p1->z;
#endif
- dx = p2->x - p1->x;
- dy = p2->y - p1->y;
+ dx = p2->x - p1->x;
+ dy = p2->y - p1->y;
#ifdef INTERP_RGB
- r = p2->r << 8;
- g = p2->g << 8;
- b = p2->b << 8;
+ r = p2->r << 8;
+ g = p2->g << 8;
+ b = p2->b << 8;
#elif TGL_FEATURE_RENDER_BITS == 24
- /* for 24 bits, we store the colors in different variables */
- r = p2->r >> 8;
- g = p2->g >> 8;
- b = p2->b >> 8;
+ /* for 24 bits, we store the colors in different variables */
+ r = p2->r >> 8;
+ g = p2->g >> 8;
+ b = p2->b >> 8;
#endif
#ifdef INTERP_RGB
@@ -45,7 +45,7 @@
#if TGL_FEATURE_RENDER_BITS == 24
#define RGBPIXEL pp[0] = r >> 16, pp[1] = g >> 16, pp[2] = b >> 16
#else
-#define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
+#define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8, g >> 8, b >> 8)
#endif
#else /* INTERP_RGB */
#define RGB(x)
@@ -58,56 +58,61 @@
#ifdef INTERP_Z
#define ZZ(x) x
-#define PUTPIXEL() \
- { \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,*pz)) { \
- RGBPIXEL; \
- *pz=zz; \
- } \
- }
+#define PUTPIXEL() \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, *pz)) { \
+ RGBPIXEL; \
+ *pz = zz; \
+ } \
+ }
#else /* INTERP_Z */
#define ZZ(x)
#define PUTPIXEL() RGBPIXEL
#endif /* INTERP_Z */
-#define DRAWLINE(dx,dy,inc_1,inc_2) \
- n=dx;\
- ZZ(zinc=(p2->z-p1->z)/n);\
- RGB(rinc=((p2->r-p1->r) << 8)/n;\
- ginc=((p2->g-p1->g) << 8)/n;\
- binc=((p2->b-p1->b) << 8)/n);\
- a=2*dy-dx;\
- dy=2*dy;\
- dx=2*dx-dy;\
- pp_inc_1 = (inc_1) * PSZB;\
- pp_inc_2 = (inc_2) * PSZB;\
- do {\
- PUTPIXEL();\
- ZZ(z+=zinc);\
- RGB(r+=rinc;g+=ginc;b+=binc);\
- if (a>0) { pp=(PIXEL *)((GLbyte *)pp + pp_inc_1); ZZ(pz+=(inc_1)); a-=dx; }\
- else { pp=(PIXEL *)((GLbyte *)pp + pp_inc_2); ZZ(pz+=(inc_2)); a+=dy; }\
- } while (--n >= 0);
+#define DRAWLINE(dx, dy, inc_1, inc_2) \
+ n = dx; \
+ ZZ(zinc = (p2->z - p1->z) / n); \
+ RGB(rinc = ((p2->r - p1->r) << 8) / n; ginc = ((p2->g - p1->g) << 8) / n; binc = ((p2->b - p1->b) << 8) / n); \
+ a = 2 * dy - dx; \
+ dy = 2 * dy; \
+ dx = 2 * dx - dy; \
+ pp_inc_1 = (inc_1)*PSZB; \
+ pp_inc_2 = (inc_2)*PSZB; \
+ do { \
+ PUTPIXEL(); \
+ ZZ(z += zinc); \
+ RGB(r += rinc; g += ginc; b += binc); \
+ if (a > 0) { \
+ pp = (PIXEL*)((GLbyte*)pp + pp_inc_1); \
+ ZZ(pz += (inc_1)); \
+ a -= dx; \
+ } else { \
+ pp = (PIXEL*)((GLbyte*)pp + pp_inc_2); \
+ ZZ(pz += (inc_2)); \
+ a += dy; \
+ } \
+ } while (--n >= 0);
-/* fin macro */
+ /* fin macro */
- if (dx == 0 && dy == 0) {
- PUTPIXEL();
- } else if (dx > 0) {
- if (dx >= dy) {
- DRAWLINE(dx, dy, sx + 1, 1);
+ if (dx == 0 && dy == 0) {
+ PUTPIXEL();
+ } else if (dx > 0) {
+ if (dx >= dy) {
+ DRAWLINE(dx, dy, sx + 1, 1);
+ } else {
+ DRAWLINE(dy, dx, sx + 1, sx);
+ }
} else {
- DRAWLINE(dy, dx, sx + 1, sx);
+ dx = -dx;
+ if (dx >= dy) {
+ DRAWLINE(dx, dy, sx - 1, -1);
+ } else {
+ DRAWLINE(dy, dx, sx - 1, sx);
+ }
}
- } else {
- dx = -dx;
- if (dx >= dy) {
- DRAWLINE(dx, dy, sx - 1, -1);
- } else {
- DRAWLINE(dy, dx, sx - 1, sx);
- }
- }
}
#undef INTERP_Z
@@ -118,4 +123,4 @@
#undef PUTPIXEL
#undef ZZ
#undef RGB
-#undef RGBPIXEL
+#undef RGBPIXEL
--- a/src/zmath.c
+++ b/src/zmath.c
@@ -1,134 +1,129 @@
/* Some simple mathematical functions. Don't look for some logic in
the function names :-) */
+#include "zmath.h"
+#include <math.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
-#include "zmath.h"
-
/* ******* Gestion des matrices 4x4 ****** */
-void gl_M4_Id(M4 *a)
-{
- GLint i,j;
- for(i=0;i<4;i++)
- for(j=0;j<4;j++)
- if (i==j) a->m[i][j]=1.0; else a->m[i][j]=0.0;
+void gl_M4_Id(M4* a) {
+ GLint i, j;
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ if (i == j)
+ a->m[i][j] = 1.0;
+ else
+ a->m[i][j] = 0.0;
}
-int gl_M4_IsId(M4 *a)
-{
- GLint i,j;
- for(i=0;i<4;i++)
- for(j=0;j<4;j++) {
- if (i==j) {
- if (a->m[i][j] != 1.0) return 0;
- } else if (a->m[i][j] != 0.0) return 0;
- }
- return 1;
+int gl_M4_IsId(M4* a) {
+ GLint i, j;
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++) {
+ if (i == j) {
+ if (a->m[i][j] != 1.0)
+ return 0;
+ } else if (a->m[i][j] != 0.0)
+ return 0;
+ }
+ return 1;
}
-void gl_M4_Mul(M4 *c,M4 *a,M4 *b)
-{
- GLint i,j,k;
- GLfloat s;
- for(i=0;i<4;i++)
- for(j=0;j<4;j++) {
- s=0.0;
- for(k=0;k<4;k++) s+=a->m[i][k]*b->m[k][j];
- c->m[i][j]=s;
- }
+void gl_M4_Mul(M4* c, M4* a, M4* b) {
+ GLint i, j, k;
+ GLfloat s;
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++) {
+ s = 0.0;
+ for (k = 0; k < 4; k++)
+ s += a->m[i][k] * b->m[k][j];
+ c->m[i][j] = s;
+ }
}
/* c=c*a */
-void gl_M4_MulLeft(M4 *c,M4 *b)
-{
- GLint i,j,k;
- GLfloat s;
- M4 a;
+void gl_M4_MulLeft(M4* c, M4* b) {
+ GLint i, j, k;
+ GLfloat s;
+ M4 a;
- /*memcpy(&a, c, 16*sizeof(GLfloat));
- */
- a=*c;
+ /*memcpy(&a, c, 16*sizeof(GLfloat));
+ */
+ a = *c;
- for(i=0;i<4;i++)
- for(j=0;j<4;j++) {
- s=0.0;
- for(k=0;k<4;k++) s+=a.m[i][k]*b->m[k][j];
- c->m[i][j]=s;
- }
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++) {
+ s = 0.0;
+ for (k = 0; k < 4; k++)
+ s += a.m[i][k] * b->m[k][j];
+ c->m[i][j] = s;
+ }
}
-void gl_M4_Move(M4 *a,M4 *b)
-{
- memcpy(a,b,sizeof(M4));
-}
+void gl_M4_Move(M4* a, M4* b) { memcpy(a, b, sizeof(M4)); }
-void gl_MoveV3(V3 *a,V3 *b)
-{
- memcpy(a,b,sizeof(V3));
-}
+void gl_MoveV3(V3* a, V3* b) { memcpy(a, b, sizeof(V3)); }
-
-void gl_MulM4V3(V3 *a,M4 *b,V3 *c)
-{
- a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3];
- a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3];
- a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3];
+void gl_MulM4V3(V3* a, M4* b, V3* c) {
+ a->X = b->m[0][0] * c->X + b->m[0][1] * c->Y + b->m[0][2] * c->Z + b->m[0][3];
+ a->Y = b->m[1][0] * c->X + b->m[1][1] * c->Y + b->m[1][2] * c->Z + b->m[1][3];
+ a->Z = b->m[2][0] * c->X + b->m[2][1] * c->Y + b->m[2][2] * c->Z + b->m[2][3];
}
-void gl_MulM3V3(V3 *a,M4 *b,V3 *c)
-{
- a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z;
- a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z;
- a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
+void gl_MulM3V3(V3* a, M4* b, V3* c) {
+ a->X = b->m[0][0] * c->X + b->m[0][1] * c->Y + b->m[0][2] * c->Z;
+ a->Y = b->m[1][0] * c->X + b->m[1][1] * c->Y + b->m[1][2] * c->Z;
+ a->Z = b->m[2][0] * c->X + b->m[2][1] * c->Y + b->m[2][2] * c->Z;
}
-void gl_M4_MulV4(V4 *a,M4 *b,V4 *c)
-{
- a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3]*c->W;
- a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3]*c->W;
- a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3]*c->W;
- a->W=b->m[3][0]*c->X+b->m[3][1]*c->Y+b->m[3][2]*c->Z+b->m[3][3]*c->W;
+void gl_M4_MulV4(V4* a, M4* b, V4* c) {
+ a->X = b->m[0][0] * c->X + b->m[0][1] * c->Y + b->m[0][2] * c->Z + b->m[0][3] * c->W;
+ a->Y = b->m[1][0] * c->X + b->m[1][1] * c->Y + b->m[1][2] * c->Z + b->m[1][3] * c->W;
+ a->Z = b->m[2][0] * c->X + b->m[2][1] * c->Y + b->m[2][2] * c->Z + b->m[2][3] * c->W;
+ a->W = b->m[3][0] * c->X + b->m[3][1] * c->Y + b->m[3][2] * c->Z + b->m[3][3] * c->W;
}
-
+
/* transposition of a 4x4 matrix */
-void gl_M4_Transpose(M4 *a,M4 *b)
-{
- a->m[0][0]=b->m[0][0];
- a->m[0][1]=b->m[1][0];
- a->m[0][2]=b->m[2][0];
- a->m[0][3]=b->m[3][0];
+void gl_M4_Transpose(M4* a, M4* b) {
+ a->m[0][0] = b->m[0][0];
+ a->m[0][1] = b->m[1][0];
+ a->m[0][2] = b->m[2][0];
+ a->m[0][3] = b->m[3][0];
- a->m[1][0]=b->m[0][1];
- a->m[1][1]=b->m[1][1];
- a->m[1][2]=b->m[2][1];
- a->m[1][3]=b->m[3][1];
+ a->m[1][0] = b->m[0][1];
+ a->m[1][1] = b->m[1][1];
+ a->m[1][2] = b->m[2][1];
+ a->m[1][3] = b->m[3][1];
- a->m[2][0]=b->m[0][2];
- a->m[2][1]=b->m[1][2];
- a->m[2][2]=b->m[2][2];
- a->m[2][3]=b->m[3][2];
+ a->m[2][0] = b->m[0][2];
+ a->m[2][1] = b->m[1][2];
+ a->m[2][2] = b->m[2][2];
+ a->m[2][3] = b->m[3][2];
- a->m[3][0]=b->m[0][3];
- a->m[3][1]=b->m[1][3];
- a->m[3][2]=b->m[2][3];
- a->m[3][3]=b->m[3][3];
+ a->m[3][0] = b->m[0][3];
+ a->m[3][1] = b->m[1][3];
+ a->m[3][2] = b->m[2][3];
+ a->m[3][3] = b->m[3][3];
}
-/* inversion of an orthogonal matrix of type Y=M.X+P */
-void gl_M4_InvOrtho(M4 *a,M4 b)
-{
- GLint i,j;
+/* inversion of an orthogonal matrix of type Y=M.X+P */
+void gl_M4_InvOrtho(M4* a, M4 b) {
+ GLint i, j;
GLfloat s;
- for(i=0;i<3;i++)
- for(j=0;j<3;j++) a->m[i][j]=b.m[j][i];
- a->m[3][0]=0.0; a->m[3][1]=0.0; a->m[3][2]=0.0; a->m[3][3]=1.0;
- for(i=0;i<3;i++) {
- s=0;
- for(j=0;j<3;j++) s-=b.m[j][i]*b.m[j][3];
- a->m[i][3]=s;
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 3; j++)
+ a->m[i][j] = b.m[j][i];
+ a->m[3][0] = 0.0;
+ a->m[3][1] = 0.0;
+ a->m[3][2] = 0.0;
+ a->m[3][3] = 1.0;
+ for (i = 0; i < 3; i++) {
+ s = 0;
+ for (j = 0; j < 3; j++)
+ s -= b.m[j][i] * b.m[j][3];
+ a->m[i][3] = s;
}
}
@@ -135,141 +130,135 @@
/* Inversion of a general nxn matrix.
Note : m is destroyed */
-int Matrix_Inv(GLfloat *r,GLfloat *m,GLint n)
-{
- GLint i,j,k,l;
- GLfloat max,tmp,t;
+int Matrix_Inv(GLfloat* r, GLfloat* m, GLint n) {
+ GLint i, j, k, l;
+ GLfloat max, tmp, t;
- /* identit�e dans r */
- for(i=0;i<n*n;i++) r[i]=0;
- for(i=0;i<n;i++) r[i*n+i]=1;
-
- for(j=0;j<n;j++) {
-
- /* recherche du nombre de plus grand module sur la colonne j */
- max=m[j*n+j];
- k=j;
- for(i=j+1;i<n;i++)
- if (fabs(m[i*n+j])>fabs(max)) {
- k=i;
- max=m[i*n+j];
- }
+ /* identit�e dans r */
+ for (i = 0; i < n * n; i++)
+ r[i] = 0;
+ for (i = 0; i < n; i++)
+ r[i * n + i] = 1;
- /* non GLintersible matrix */
- if (max==0) return 1;
+ for (j = 0; j < n; j++) {
-
- /* permutation des lignes j et k */
- if (k!=j) {
- for(i=0;i<n;i++) {
- tmp=m[j*n+i];
- m[j*n+i]=m[k*n+i];
- m[k*n+i]=tmp;
-
- tmp=r[j*n+i];
- r[j*n+i]=r[k*n+i];
- r[k*n+i]=tmp;
- }
+ /* recherche du nombre de plus grand module sur la colonne j */
+ max = m[j * n + j];
+ k = j;
+ for (i = j + 1; i < n; i++)
+ if (fabs(m[i * n + j]) > fabs(max)) {
+ k = i;
+ max = m[i * n + j];
}
-
- /* multiplication de la ligne j par 1/max */
- max=1/max;
- for(i=0;i<n;i++) {
- m[j*n+i]*=max;
- r[j*n+i]*=max;
+
+ /* non GLintersible matrix */
+ if (max == 0)
+ return 1;
+
+ /* permutation des lignes j et k */
+ if (k != j) {
+ for (i = 0; i < n; i++) {
+ tmp = m[j * n + i];
+ m[j * n + i] = m[k * n + i];
+ m[k * n + i] = tmp;
+
+ tmp = r[j * n + i];
+ r[j * n + i] = r[k * n + i];
+ r[k * n + i] = tmp;
}
-
-
- for(l=0;l<n;l++) if (l!=j) {
- t=m[l*n+j];
- for(i=0;i<n;i++) {
- m[l*n+i]-=m[j*n+i]*t;
- r[l*n+i]-=r[j*n+i]*t;
- }
+ }
+
+ /* multiplication de la ligne j par 1/max */
+ max = 1 / max;
+ for (i = 0; i < n; i++) {
+ m[j * n + i] *= max;
+ r[j * n + i] *= max;
+ }
+
+ for (l = 0; l < n; l++)
+ if (l != j) {
+ t = m[l * n + j];
+ for (i = 0; i < n; i++) {
+ m[l * n + i] -= m[j * n + i] * t;
+ r[l * n + i] -= r[j * n + i] * t;
+ }
}
- }
+ }
- return 0;
+ return 0;
}
-
/* inversion of a 4x4 matrix */
-void gl_M4_Inv(M4 *a,M4 *b)
-{
- M4 tmp;
- memcpy(&tmp, b, 16*sizeof(GLfloat));
- /*tmp=*b;*/
- Matrix_Inv(&a->m[0][0],&tmp.m[0][0],4);
+void gl_M4_Inv(M4* a, M4* b) {
+ M4 tmp;
+ memcpy(&tmp, b, 16 * sizeof(GLfloat));
+ /*tmp=*b;*/
+ Matrix_Inv(&a->m[0][0], &tmp.m[0][0], 4);
}
-void gl_M4_Rotate(M4 *a,GLfloat t,GLint u)
-{
- GLfloat s,c;
- GLint v,w;
- if ((v=u+1)>2) v=0;
- if ((w=v+1)>2) w=0;
- s=sin(t);
- c=cos(t);
- gl_M4_Id(a);
- a->m[v][v]=c; a->m[v][w]=-s;
- a->m[w][v]=s; a->m[w][w]=c;
+void gl_M4_Rotate(M4* a, GLfloat t, GLint u) {
+ GLfloat s, c;
+ GLint v, w;
+ if ((v = u + 1) > 2)
+ v = 0;
+ if ((w = v + 1) > 2)
+ w = 0;
+ s = sin(t);
+ c = cos(t);
+ gl_M4_Id(a);
+ a->m[v][v] = c;
+ a->m[v][w] = -s;
+ a->m[w][v] = s;
+ a->m[w][w] = c;
}
-
/* inverse of a 3x3 matrix */
-void gl_M3_Inv(M3 *a,M3 *m)
-{
- GLfloat det;
-
- det = m->m[0][0]*m->m[1][1]*m->m[2][2]-m->m[0][0]*m->m[1][2]*m->m[2][1]-
- m->m[1][0]*m->m[0][1]*m->m[2][2]+m->m[1][0]*m->m[0][2]*m->m[2][1]+
- m->m[2][0]*m->m[0][1]*m->m[1][2]-m->m[2][0]*m->m[0][2]*m->m[1][1];
+void gl_M3_Inv(M3* a, M3* m) {
+ GLfloat det;
- a->m[0][0] = (m->m[1][1]*m->m[2][2]-m->m[1][2]*m->m[2][1])/det;
- a->m[0][1] = -(m->m[0][1]*m->m[2][2]-m->m[0][2]*m->m[2][1])/det;
- a->m[0][2] = -(-m->m[0][1]*m->m[1][2]+m->m[0][2]*m->m[1][1])/det;
-
- a->m[1][0] = -(m->m[1][0]*m->m[2][2]-m->m[1][2]*m->m[2][0])/det;
- a->m[1][1] = (m->m[0][0]*m->m[2][2]-m->m[0][2]*m->m[2][0])/det;
- a->m[1][2] = -(m->m[0][0]*m->m[1][2]-m->m[0][2]*m->m[1][0])/det;
+ det = m->m[0][0] * m->m[1][1] * m->m[2][2] - m->m[0][0] * m->m[1][2] * m->m[2][1] - m->m[1][0] * m->m[0][1] * m->m[2][2] +
+ m->m[1][0] * m->m[0][2] * m->m[2][1] + m->m[2][0] * m->m[0][1] * m->m[1][2] - m->m[2][0] * m->m[0][2] * m->m[1][1];
- a->m[2][0] = (m->m[1][0]*m->m[2][1]-m->m[1][1]*m->m[2][0])/det;
- a->m[2][1] = -(m->m[0][0]*m->m[2][1]-m->m[0][1]*m->m[2][0])/det;
- a->m[2][2] = (m->m[0][0]*m->m[1][1]-m->m[0][1]*m->m[1][0])/det;
+ a->m[0][0] = (m->m[1][1] * m->m[2][2] - m->m[1][2] * m->m[2][1]) / det;
+ a->m[0][1] = -(m->m[0][1] * m->m[2][2] - m->m[0][2] * m->m[2][1]) / det;
+ a->m[0][2] = -(-m->m[0][1] * m->m[1][2] + m->m[0][2] * m->m[1][1]) / det;
+
+ a->m[1][0] = -(m->m[1][0] * m->m[2][2] - m->m[1][2] * m->m[2][0]) / det;
+ a->m[1][1] = (m->m[0][0] * m->m[2][2] - m->m[0][2] * m->m[2][0]) / det;
+ a->m[1][2] = -(m->m[0][0] * m->m[1][2] - m->m[0][2] * m->m[1][0]) / det;
+
+ a->m[2][0] = (m->m[1][0] * m->m[2][1] - m->m[1][1] * m->m[2][0]) / det;
+ a->m[2][1] = -(m->m[0][0] * m->m[2][1] - m->m[0][1] * m->m[2][0]) / det;
+ a->m[2][2] = (m->m[0][0] * m->m[1][1] - m->m[0][1] * m->m[1][0]) / det;
}
-
/* vector arithmetic */
-int gl_V3_Norm(V3 *a)
-{
+int gl_V3_Norm(V3* a) {
GLfloat n;
- n=sqrt(a->X*a->X+a->Y*a->Y+a->Z*a->Z);
- if (n==0) return 1;
- a->X/=n;
- a->Y/=n;
- a->Z/=n;
+ n = sqrt(a->X * a->X + a->Y * a->Y + a->Z * a->Z);
+ if (n == 0)
+ return 1;
+ a->X /= n;
+ a->Y /= n;
+ a->Z /= n;
return 0;
}
-V3 gl_V3_New(GLfloat x,GLfloat y,GLfloat z)
-{
- V3 a;
- a.X=x;
- a.Y=y;
- a.Z=z;
- return a;
+V3 gl_V3_New(GLfloat x, GLfloat y, GLfloat z) {
+ V3 a;
+ a.X = x;
+ a.Y = y;
+ a.Z = z;
+ return a;
}
-V4 gl_V4_New(GLfloat x,GLfloat y,GLfloat z,GLfloat w)
-{
- V4 a;
- a.X=x;
- a.Y=y;
- a.Z=z;
- a.W=w;
- return a;
+V4 gl_V4_New(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
+ V4 a;
+ a.X = x;
+ a.Y = y;
+ a.Z = z;
+ a.W = w;
+ return a;
}
-
-
--- a/src/zmath.h
+++ b/src/zmath.h
@@ -12,10 +12,9 @@
} M3;
typedef struct {
- GLfloat m[3][4];
+ GLfloat m[3][4];
} M34;
-
#define X v[0]
#define Y v[1]
#define Z v[2]
@@ -22,33 +21,33 @@
#define W v[3]
typedef struct {
- GLfloat v[3];
+ GLfloat v[3];
} V3;
typedef struct {
- GLfloat v[4];
+ GLfloat v[4];
} V4;
-
-void gl_M4_Id(M4 *a);
-int gl_M4_IsId(M4 *a);
-void gl_M4_Move(M4 *a,M4 *b);
-void gl_MoveV3(V3 *a,V3 *b);
-void gl_MulM4V3(V3 *a,M4 *b,V3 *c);
-void gl_MulM3V3(V3 *a,M4 *b,V3 *c);
-void gl_M4_MulV4(V4 * a,M4 *b,V4 * c);
-void gl_M4_InvOrtho(M4 *a,M4 b);
-void gl_M4_Inv(M4 *a,M4 *b);
-void gl_M4_Mul(M4 *c,M4 *a,M4 *b);
-void gl_M4_MulLeft(M4 *c,M4 *a);
-void gl_M4_Transpose(M4 *a,M4 *b);
-void gl_M4_Rotate(M4 *c,GLfloat t,GLint u);
-int gl_V3_Norm(V3 *a);
+void gl_M4_Id(M4* a);
+int gl_M4_IsId(M4* a);
+void gl_M4_Move(M4* a, M4* b);
+void gl_MoveV3(V3* a, V3* b);
+void gl_MulM4V3(V3* a, M4* b, V3* c);
+void gl_MulM3V3(V3* a, M4* b, V3* c);
-V3 gl_V3_New(GLfloat x,GLfloat y,GLfloat z);
-V4 gl_V4_New(GLfloat x,GLfloat y,GLfloat z,GLfloat w);
+void gl_M4_MulV4(V4* a, M4* b, V4* c);
+void gl_M4_InvOrtho(M4* a, M4 b);
+void gl_M4_Inv(M4* a, M4* b);
+void gl_M4_Mul(M4* c, M4* a, M4* b);
+void gl_M4_MulLeft(M4* c, M4* a);
+void gl_M4_Transpose(M4* a, M4* b);
+void gl_M4_Rotate(M4* c, GLfloat t, GLint u);
+int gl_V3_Norm(V3* a);
-int gl_Matrix_Inv(GLfloat *r,GLfloat *m,GLint n);
+V3 gl_V3_New(GLfloat x, GLfloat y, GLfloat z);
+V4 gl_V4_New(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+int gl_Matrix_Inv(GLfloat* r, GLfloat* m, GLint n);
+
#endif
-// __ZMATH__
+// __ZMATH__
--- a/src/ztext.c
+++ b/src/ztext.c
@@ -1,79 +1,76 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "../include/zbuffer.h"
#include "../include/GL/gl.h"
-#include "zgl.h"
+#include "../include/zbuffer.h"
#include "font8x8_basic.h"
+#include "zgl.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
GLTEXTSIZE textsize = 1;
-void glTextSize(GLTEXTSIZE mode){
+void glTextSize(GLTEXTSIZE mode) {
GLParam p[2];
p[0].op = OP_TextSize;
p[1].ui = mode;
gl_add_op(p);
}
-void glopTextSize(GLContext * c,GLParam * p){
- textsize = p[1].ui;
-}//Set text size
-void renderchar(GLbyte *bitmap, GLint _x, GLint _y, GLuint p) {
- GLint x,y;
- GLint set;
- //int mask;
- GLint mult = textsize;
- for (x=0; x < 8; x++) {
- for (y=0; y < 8; y++) {
- set = bitmap[x] & 1 << y;
- if(set)
- for(GLint i = 0; i < mult; i++)
- for(GLint j = 0; j < mult; j++)
- glPlotPixel(y*mult + i + _x, x*mult + j + _y, p);
- }
- }
+void glopTextSize(GLContext* c, GLParam* p) { textsize = p[1].ui; } // Set text size
+void renderchar(GLbyte* bitmap, GLint _x, GLint _y, GLuint p) {
+ GLint x, y;
+ GLint set;
+ // int mask;
+ GLint mult = textsize;
+ for (x = 0; x < 8; x++) {
+ for (y = 0; y < 8; y++) {
+ set = bitmap[x] & 1 << y;
+ if (set)
+ for (GLint i = 0; i < mult; i++)
+ for (GLint j = 0; j < mult; j++)
+ glPlotPixel(y * mult + i + _x, x * mult + j + _y, p);
+ }
+ }
}
-void glopPlotPixel(GLContext * c,GLParam * p){
+void glopPlotPixel(GLContext* c, GLParam* p) {
GLint x = p[1].i;
PIXEL pix = p[2].ui;
- //PIXEL* pbuf = c->zb->pbuf;
+ // PIXEL* pbuf = c->zb->pbuf;
c->zb->pbuf[x] = pix;
}
-void glPlotPixel(GLint x, GLint y, GLuint pix){
+void glPlotPixel(GLint x, GLint y, GLuint pix) {
GLParam p[3];
- //PIXEL* pbuf = gl_get_context()->zb->pbuf;
+ // PIXEL* pbuf = gl_get_context()->zb->pbuf;
GLint w = gl_get_context()->zb->xsize;
GLint h = gl_get_context()->zb->ysize;
p[0].op = OP_PlotPixel;
-
-
- if(x>0 && x<w && y>0 && y < h){
+
+ if (x > 0 && x < w && y > 0 && y < h) {
#if TGL_FEATURE_RENDER_BITS == 16
- pix = RGB_TO_PIXEL( ( (pix & 255) << 8) , ( pix & 65280) , ( (pix >>16)<<8 ) );
+ pix = RGB_TO_PIXEL(((pix & 255) << 8), (pix & 65280), ((pix >> 16) << 8));
#endif
- p[1].i = x+y*w;
+ p[1].i = x + y * w;
p[2].ui = pix;
gl_add_op(p);
}
}
-void glDrawText(const GLubyte* text, GLint x, GLint y, GLuint p){
- if(!text)return;
- //PIXEL* pbuf = gl_get_context()->zb->pbuf;
+void glDrawText(const GLubyte* text, GLint x, GLint y, GLuint p) {
+ if (!text)
+ return;
+ // PIXEL* pbuf = gl_get_context()->zb->pbuf;
GLint w = gl_get_context()->zb->xsize;
GLint h = gl_get_context()->zb->ysize;
GLint xoff = 0;
GLint yoff = 0;
GLint mult = textsize;
- for(GLint i = 0; text[i] != '\0' && y+7 < h; i++){
- if(text[i] != '\n' && text[i] < 127 && xoff+x < w)
- {
- renderchar(font8x8_basic[text[i]],x+xoff,y+yoff, p);
- xoff+=8*mult;
- }else if(text[i] == '\n'){
- xoff=0;
- yoff+=8*mult;
+ for (GLint i = 0; text[i] != '\0' && y + 7 < h; i++) {
+ if (text[i] != '\n' && text[i] < 127 && xoff + x < w) {
+ renderchar(font8x8_basic[text[i]], x + xoff, y + yoff, p);
+ xoff += 8 * mult;
+ } else if (text[i] == '\n') {
+ xoff = 0;
+ yoff += 8 * mult;
}
}
}
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -1,10 +1,7 @@
-#include <stdlib.h>
-#include "msghandling.h"
#include "../include/zbuffer.h"
+#include "msghandling.h"
+#include <stdlib.h>
-
-
-
#if TGL_FEATURE_RENDER_BITS == 32
#elif TGL_FEATURE_RENDER_BITS == 16
#else
@@ -11,18 +8,15 @@
#error "WRONG MODE!!!"
#endif
-
-
#if TGL_FEATURE_POLYGON_STIPPLE
-#define THE_X (((GLushort)(pp-pp1)))
-#define XSTIP(_a) ((THE_X+_a)& TGL_POLYGON_STIPPLE_MASK_X)
+#define THE_X (((GLushort)(pp - pp1)))
+#define XSTIP(_a) ((THE_X + _a) & TGL_POLYGON_STIPPLE_MASK_X)
#define YSTIP (the_y & TGL_POLYGON_STIPPLE_MASK_Y)
-//NOTES Divide by 8 to get the byte Get the actual bit
-#define STIPBIT(_a) (zb->stipplepattern[(XSTIP(_a) | (YSTIP<<TGL_POLYGON_STIPPLE_POW2_WIDTH))>>3] & (1<<(XSTIP(_a) & 7)))
+// NOTES Divide by 8 to get the byte Get the actual bit
+#define STIPBIT(_a) (zb->stipplepattern[(XSTIP(_a) | (YSTIP << TGL_POLYGON_STIPPLE_POW2_WIDTH)) >> 3] & (1 << (XSTIP(_a) & 7)))
#define STIPTEST(_a) !(zb->dostipple && !STIPBIT(_a))
-
#else
#define STIPTEST(_a) (1)
@@ -31,42 +25,32 @@
#endif
#if TGL_FEATURE_NO_DRAW_COLOR == 1
-#define NODRAWTEST(c) ( (c & TGL_COLOR_MASK) != TGL_NO_DRAW_COLOR)
+#define NODRAWTEST(c) ((c & TGL_COLOR_MASK) != TGL_NO_DRAW_COLOR)
#else
#define NODRAWTEST(c) (1)
#endif
-#define ZCMP(z,zpix,_a,c) ((z) >= (zpix) && STIPTEST(_a) && NODRAWTEST(c))
+#define ZCMP(z, zpix, _a, c) ((z) >= (zpix) && STIPTEST(_a) && NODRAWTEST(c))
-void ZB_fillTriangleFlat(ZBuffer *zb,
- ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
-{
+void ZB_fillTriangleFlat(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+ PIXEL color;
-
-
- PIXEL color;
-
-
#define INTERP_Z
+#define DRAW_INIT() \
+ { color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); }
-#define DRAW_INIT() \
-{ \
- color=RGB_TO_PIXEL(p2->r,p2->g,p2->b); \
-}
-
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a,color)) { \
- pp[_a]=color; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a, color)) { \
+ pp[_a] = color; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ }
-
#include "ztriangle.h"
}
@@ -75,115 +59,103 @@
* The code below is very tricky :)
*/
-void ZB_fillTriangleSmooth(ZBuffer *zb,
- ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
-{
+void ZB_fillTriangleSmooth(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
#if TGL_FEATURE_NO_DRAW_COLOR == 1
PIXEL c;
#endif
-//GLuint color;
+// GLuint color;
#define INTERP_Z
#define INTERP_RGB
-#define SAR_RND_TO_ZERO(v,n) (v / (1<<n))
+#define SAR_RND_TO_ZERO(v, n) (v / (1 << n))
-
#if TGL_FEATURE_RENDER_BITS == 32
-#define DRAW_INIT() \
-{ \
- \
-}
+#define DRAW_INIT() \
+ {}
#if TGL_FEATURE_NO_DRAW_COLOR != 1
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a,RGB_TO_PIXEL(or1, og1, ob1))) { \
- pp[_a] = RGB_TO_PIXEL(or1, og1, ob1); \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- og1+=dgdx; \
- or1+=drdx; \
- ob1+=dbdx; \
-}
-#else
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- c = RGB_TO_PIXEL(or1, og1, ob1); \
- if (ZCMP(zz,pz[_a],_a,c)) { \
- pp[_a] = c; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- og1+=dgdx; \
- or1+=drdx; \
- ob1+=dbdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a, RGB_TO_PIXEL(or1, og1, ob1))) { \
+ pp[_a] = RGB_TO_PIXEL(or1, og1, ob1); \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ og1 += dgdx; \
+ or1 += drdx; \
+ ob1 += dbdx; \
+ }
+#else
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ c = RGB_TO_PIXEL(or1, og1, ob1); \
+ if (ZCMP(zz, pz[_a], _a, c)) { \
+ pp[_a] = c; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ og1 += dgdx; \
+ or1 += drdx; \
+ ob1 += dbdx; \
+ }
#endif
-//END OF 32 bit mode
+// END OF 32 bit mode
#elif TGL_FEATURE_RENDER_BITS == 16
+#define DRAW_INIT() \
+ {}
+ /*
+ #define PUT_PIXEL(_a) \
+ { \
+ zz=z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz,pz[_a],_a)) { \
+ pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);\
+ pz[_a]=zz; \
+ }\
+ z+=dzdx; \
+ og1+=dgdx; \
+ or1+=drdx; \
+ ob1+=dbdx; \
+ }
+ */
-#define DRAW_INIT() \
-{ \
- \
-}
-
-
-
-/*
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a)) { \
- pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);\
- pz[_a]=zz; \
- }\
- z+=dzdx; \
- og1+=dgdx; \
- or1+=drdx; \
- ob1+=dbdx; \
-}
-*/
-
#if TGL_FEATURE_NO_DRAW_COLOR != 1
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a,0)) { \
- pp[_a] = RGB_TO_PIXEL(or1, og1, ob1); \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- og1+=dgdx; \
- or1+=drdx; \
- ob1+=dbdx; \
-}
-#else
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- c = RGB_TO_PIXEL(or1, og1, ob1); \
- if (ZCMP(zz,pz[_a],_a,c)) { \
- pp[_a] = c; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- og1+=dgdx; \
- or1+=drdx; \
- ob1+=dbdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a, 0)) { \
+ pp[_a] = RGB_TO_PIXEL(or1, og1, ob1); \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ og1 += dgdx; \
+ or1 += drdx; \
+ ob1 += dbdx; \
+ }
+#else
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ c = RGB_TO_PIXEL(or1, og1, ob1); \
+ if (ZCMP(zz, pz[_a], _a, c)) { \
+ pp[_a] = c; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ og1 += dgdx; \
+ or1 += drdx; \
+ ob1 += dbdx; \
+ }
#endif
-#endif
+#endif
//^ End of 16 bit mode stuff
#include "ztriangle.h"
-} //EOF smooth fill triangle
+} // EOF smooth fill triangle
-
//
//
// TEXTURE MAPPED TRIANGLES
@@ -193,18 +165,11 @@
//
//
+void ZB_setTexture(ZBuffer* zb, PIXEL* texture) { zb->current_texture = texture; }
+// Ignore this it is never used
+void ZB_fillTriangleMapping(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+ PIXEL* texture;
-
-void ZB_setTexture(ZBuffer *zb,PIXEL *texture)
-{
- zb->current_texture=texture;
-}
-//Ignore this it is never used
-void ZB_fillTriangleMapping(ZBuffer *zb,
- ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
-{
- PIXEL *texture;
-
#if TGL_FEATURE_NO_DRAW_COLOR == 1
PIXEL c;
#endif
@@ -211,37 +176,34 @@
#define INTERP_Z
#define INTERP_ST
-#define DRAW_INIT() \
-{ \
- texture=zb->current_texture; \
-}
+#define DRAW_INIT() \
+ { texture = zb->current_texture; }
-
#if TGL_FEATURE_NO_DRAW_COLOR != 1
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a,0)) { \
- pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- s+=dsdx; \
- t+=dtdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a, 0)) { \
+ pp[_a] = texture[((t & 0x3FC00000) | s) >> 14]; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ s += dsdx; \
+ t += dtdx; \
+ }
#else
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- c = texture[((t & 0x3FC00000) | s) >> 14];\
- if (ZCMP(zz,pz[_a],_a,c)) { \
- pp[_a]=c; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- s+=dsdx; \
- t+=dtdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ c = texture[((t & 0x3FC00000) | s) >> 14]; \
+ if (ZCMP(zz, pz[_a], _a, c)) { \
+ pp[_a] = c; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ s += dsdx; \
+ t += dtdx; \
+ }
#endif
#include "ztriangle.h"
}
@@ -252,14 +214,11 @@
* TODO: pipeline the division
*/
+#if 1 // IF 1
-#if 1 //IF 1
-
-void ZB_fillTriangleMappingPerspective(ZBuffer *zb,
- ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
-{
- PIXEL *texture;
- GLfloat fdzdx,fndzdx,ndszdx,ndtzdx;
+void ZB_fillTriangleMappingPerspective(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+ PIXEL* texture;
+ GLfloat fdzdx, fndzdx, ndszdx, ndtzdx;
#if TGL_FEATURE_NO_DRAW_COLOR == 1
PIXEL c;
#endif
@@ -268,122 +227,105 @@
#define NB_INTERP 8
-#define DRAW_INIT() \
-{ \
- texture=zb->current_texture;\
- fdzdx=(GLfloat)dzdx;\
- fndzdx=NB_INTERP * fdzdx;\
- ndszdx=NB_INTERP * dszdx;\
- ndtzdx=NB_INTERP * dtzdx;\
-}
+#define DRAW_INIT() \
+ { \
+ texture = zb->current_texture; \
+ fdzdx = (GLfloat)dzdx; \
+ fndzdx = NB_INTERP * fdzdx; \
+ ndszdx = NB_INTERP * dszdx; \
+ ndtzdx = NB_INTERP * dtzdx; \
+ }
#if TGL_FEATURE_NO_DRAW_COLOR != 1
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a,0)) { \
- pp[_a]=*(PIXEL *)((GLbyte *)texture+ \
- (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));\
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- s+=dsdx; \
- t+=dtdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a, 0)) { \
+ pp[_a] = *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH))); \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ s += dsdx; \
+ t += dtdx; \
+ }
#else
-#define PUT_PIXEL(_a) \
-{ \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- c= *(PIXEL *)((GLbyte *)texture+ \
- (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));\
- if (ZCMP(zz,pz[_a],_a,c)) { \
- pp[_a]=c; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- s+=dsdx; \
- t+=dtdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ c = *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH))); \
+ if (ZCMP(zz, pz[_a], _a, c)) { \
+ pp[_a] = c; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ s += dsdx; \
+ t += dtdx; \
+ }
#endif
+#define DRAW_LINE() \
+ { \
+ register GLushort* pz; \
+ register PIXEL* pp; \
+ register GLuint s, t, z, zz; \
+ register GLint n, dsdx, dtdx; \
+ GLfloat sz, tz, fz, zinv; \
+ n = (x2 >> 16) - x1; \
+ fz = (GLfloat)z1; \
+ zinv = 1.0 / fz; \
+ pp = (PIXEL*)((GLbyte*)pp1 + x1 * PSZB); \
+ pz = pz1 + x1; \
+ z = z1; \
+ sz = sz1; \
+ tz = tz1; \
+ while (n >= (NB_INTERP - 1)) { \
+ { \
+ GLfloat ss, tt; \
+ ss = (sz * zinv); \
+ tt = (tz * zinv); \
+ s = (GLint)ss; \
+ t = (GLint)tt; \
+ dsdx = (GLint)((dszdx - ss * fdzdx) * zinv); \
+ dtdx = (GLint)((dtzdx - tt * fdzdx) * zinv); \
+ fz += fndzdx; \
+ zinv = 1.0 / fz; \
+ } \
+ PUT_PIXEL(0); /*the_x++;*/ \
+ PUT_PIXEL(1); /*the_x++;*/ \
+ PUT_PIXEL(2); /*the_x++;*/ \
+ PUT_PIXEL(3); /*the_x++;*/ \
+ PUT_PIXEL(4); /*the_x++;*/ \
+ PUT_PIXEL(5); /*the_x++;*/ \
+ PUT_PIXEL(6); /*the_x++;*/ \
+ PUT_PIXEL(7); /*the_x-=7;*/ \
+ pz += NB_INTERP; \
+ pp = (PIXEL*)((GLbyte*)pp + NB_INTERP * PSZB); /*the_x+=NB_INTERP * PSZB;*/ \
+ n -= NB_INTERP; \
+ sz += ndszdx; \
+ tz += ndtzdx; \
+ } \
+ { \
+ GLfloat ss, tt; \
+ ss = (sz * zinv); \
+ tt = (tz * zinv); \
+ s = (GLint)ss; \
+ t = (GLint)tt; \
+ dsdx = (GLint)((dszdx - ss * fdzdx) * zinv); \
+ dtdx = (GLint)((dtzdx - tt * fdzdx) * zinv); \
+ } \
+ while (n >= 0) { \
+ PUT_PIXEL(0); /*the_x += PSZB;*/ \
+ pz += 1; \
+ pp = (PIXEL*)((GLbyte*)pp + PSZB); \
+ n -= 1; \
+ } \
+ }
-#define DRAW_LINE() \
-{ \
- register GLushort *pz; \
- register PIXEL *pp; \
- register GLuint s,t,z,zz; \
- register GLint n,dsdx,dtdx; \
- GLfloat sz,tz,fz,zinv; \
- n=(x2>>16)-x1; \
- fz=(GLfloat)z1;\
- zinv=1.0 / fz;\
- pp=(PIXEL *)((GLbyte *)pp1 + x1 * PSZB); \
- pz=pz1+x1; \
- z=z1; \
- sz=sz1;\
- tz=tz1;\
- while (n>=(NB_INTERP-1)) { \
- {\
- GLfloat ss,tt;\
- ss=(sz * zinv);\
- tt=(tz * zinv);\
- s=(GLint) ss;\
- t=(GLint) tt;\
- dsdx= (GLint)( (dszdx - ss*fdzdx)*zinv );\
- dtdx= (GLint)( (dtzdx - tt*fdzdx)*zinv );\
- fz+=fndzdx;\
- zinv=1.0 / fz;\
- }\
- PUT_PIXEL(0);/*the_x++;*/ \
- PUT_PIXEL(1);/*the_x++;*/ \
- PUT_PIXEL(2);/*the_x++;*/ \
- PUT_PIXEL(3);/*the_x++;*/ \
- PUT_PIXEL(4);/*the_x++;*/ \
- PUT_PIXEL(5);/*the_x++;*/ \
- PUT_PIXEL(6);/*the_x++;*/ \
- PUT_PIXEL(7);/*the_x-=7;*/ \
- pz+=NB_INTERP; \
- pp=(PIXEL *)((GLbyte *)pp + NB_INTERP * PSZB);/*the_x+=NB_INTERP * PSZB;*/\
- n-=NB_INTERP; \
- sz+=ndszdx;\
- tz+=ndtzdx;\
- } \
- {\
- GLfloat ss,tt;\
- ss=(sz * zinv);\
- tt=(tz * zinv);\
- s=(GLint) ss;\
- t=(GLint) tt;\
- dsdx= (GLint)( (dszdx - ss*fdzdx)*zinv );\
- dtdx= (GLint)( (dtzdx - tt*fdzdx)*zinv );\
- }\
- while (n>=0) { \
- PUT_PIXEL(0);/*the_x += PSZB;*/ \
- pz+=1; \
- pp=(PIXEL *)((GLbyte *)pp + PSZB);\
- n-=1; \
- } \
-}
-
#include "ztriangle.h"
}
-#endif //if 1
+#endif // if 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#if 0
/* slow but exact version (only there for reference, incorrect for 24
@@ -397,30 +339,27 @@
#define INTERP_Z
#define INTERP_STZ
-#define DRAW_INIT() \
-{ \
- texture=zb->current_texture; \
-}
+#define DRAW_INIT() \
+ { texture = zb->current_texture; }
-#define PUT_PIXEL(_a) \
-{ \
- GLfloat zinv; \
- GLint s,t; \
- zz=z >> ZB_POINT_Z_FRAC_BITS; \
- if (ZCMP(zz,pz[_a],_a)) { \
- zinv= 1.0 / (GLfloat) z; \
- s= (GLint) (sz * zinv); \
- t= (GLint) (tz * zinv); \
- pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; \
- pz[_a]=zz; \
- } \
- z+=dzdx; \
- sz+=dszdx; \
- tz+=dtzdx; \
-}
+#define PUT_PIXEL(_a) \
+ { \
+ GLfloat zinv; \
+ GLint s, t; \
+ zz = z >> ZB_POINT_Z_FRAC_BITS; \
+ if (ZCMP(zz, pz[_a], _a)) { \
+ zinv = 1.0 / (GLfloat)z; \
+ s = (GLint)(sz * zinv); \
+ t = (GLint)(tz * zinv); \
+ pp[_a] = texture[((t & 0x3FC00000) | s) >> 14]; \
+ pz[_a] = zz; \
+ } \
+ z += dzdx; \
+ sz += dszdx; \
+ tz += dtzdx; \
+ }
#include "ztriangle.h"
}
-
#endif
--- a/src/ztriangle.h
+++ b/src/ztriangle.h
@@ -3,364 +3,364 @@
*/
{
- ZBufferPoint *t,*pr1,*pr2,*l1,*l2;
- GLfloat fdx1, fdx2, fdy1, fdy2, fz, d1, d2;
- GLushort *pz1;
- PIXEL *pp1;
- GLint part,update_left,update_right;
+ ZBufferPoint *t, *pr1, *pr2, *l1, *l2;
+ GLfloat fdx1, fdx2, fdy1, fdy2, fz, d1, d2;
+ GLushort* pz1;
+ PIXEL* pp1;
+ GLint part, update_left, update_right;
- GLint nb_lines,dx1,dy1,tmp,dx2,dy2;
+ GLint nb_lines, dx1, dy1, tmp, dx2, dy2;
#if TGL_FEATURE_POLYGON_STIPPLE == 1
- GLushort the_y;
+ GLushort the_y;
#endif
- GLint error,derror;
- GLint x1,dxdy_min,dxdy_max;
-/* warning: x2 is multiplied by 2^16 */
- GLint x2,dx2dy2;
+ GLint error, derror;
+ GLint x1, dxdy_min, dxdy_max;
+ /* warning: x2 is multiplied by 2^16 */
+ GLint x2, dx2dy2;
#ifdef INTERP_Z
- GLint z1,dzdx,dzdy,dzdl_min,dzdl_max;
+ GLint z1, dzdx, dzdy, dzdl_min, dzdl_max;
#endif
#ifdef INTERP_RGB
- GLint r1,drdx,drdy,drdl_min,drdl_max;
- GLint g1,dgdx,dgdy,dgdl_min,dgdl_max;
- GLint b1,dbdx,dbdy,dbdl_min,dbdl_max;
+ GLint r1, drdx, drdy, drdl_min, drdl_max;
+ GLint g1, dgdx, dgdy, dgdl_min, dgdl_max;
+ GLint b1, dbdx, dbdy, dbdl_min, dbdl_max;
#endif
#ifdef INTERP_ST
- GLint s1,dsdx,dsdy,dsdl_min,dsdl_max;
- GLint t1,dtdx,dtdy,dtdl_min,dtdl_max;
+ GLint s1, dsdx, dsdy, dsdl_min, dsdl_max;
+ GLint t1, dtdx, dtdy, dtdl_min, dtdl_max;
#endif
#ifdef INTERP_STZ
- GLfloat sz1,dszdx,dszdy,dszdl_min,dszdl_max;
- GLfloat tz1,dtzdx,dtzdy,dtzdl_min,dtzdl_max;
+ GLfloat sz1, dszdx, dszdy, dszdl_min, dszdl_max;
+ GLfloat tz1, dtzdx, dtzdy, dtzdl_min, dtzdl_max;
#endif
- /* we sort the vertex with increasing y */
- if (p1->y < p0->y) {
- t = p0;
- p0 = p1;
- p1 = t;
- }
- if (p2->y < p0->y) {
- t = p2;
- p2 = p1;
- p1 = p0;
- p0 = t;
- } else if (p2->y < p1->y) {
- t = p1;
- p1 = p2;
- p2 = t;
- }
+ /* we sort the vertex with increasing y */
+ if (p1->y < p0->y) {
+ t = p0;
+ p0 = p1;
+ p1 = t;
+ }
+ if (p2->y < p0->y) {
+ t = p2;
+ p2 = p1;
+ p1 = p0;
+ p0 = t;
+ } else if (p2->y < p1->y) {
+ t = p1;
+ p1 = p2;
+ p2 = t;
+ }
- /* we compute dXdx and dXdy for all GLinterpolated values */
-
- fdx1 = p1->x - p0->x;
- fdy1 = p1->y - p0->y;
+ /* we compute dXdx and dXdy for all GLinterpolated values */
- fdx2 = p2->x - p0->x;
- fdy2 = p2->y - p0->y;
+ fdx1 = p1->x - p0->x;
+ fdy1 = p1->y - p0->y;
- fz = fdx1 * fdy2 - fdx2 * fdy1;
- if (fz == 0)
- return;
- fz = 1.0 / fz;
+ fdx2 = p2->x - p0->x;
+ fdy2 = p2->y - p0->y;
- fdx1 *= fz;
- fdy1 *= fz;
- fdx2 *= fz;
- fdy2 *= fz;
+ fz = fdx1 * fdy2 - fdx2 * fdy1;
+ if (fz == 0)
+ return;
+ fz = 1.0 / fz;
+ fdx1 *= fz;
+ fdy1 *= fz;
+ fdx2 *= fz;
+ fdy2 *= fz;
+
#ifdef INTERP_Z
- d1 = p1->z - p0->z;
- d2 = p2->z - p0->z;
- dzdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- dzdy = (GLint) (fdx1 * d2 - fdx2 * d1);
+ d1 = p1->z - p0->z;
+ d2 = p2->z - p0->z;
+ dzdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ dzdy = (GLint)(fdx1 * d2 - fdx2 * d1);
#endif
#ifdef INTERP_RGB
- d1 = p1->r - p0->r;
- d2 = p2->r - p0->r;
- drdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- drdy = (GLint) (fdx1 * d2 - fdx2 * d1);
+ d1 = p1->r - p0->r;
+ d2 = p2->r - p0->r;
+ drdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ drdy = (GLint)(fdx1 * d2 - fdx2 * d1);
- d1 = p1->g - p0->g;
- d2 = p2->g - p0->g;
- dgdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- dgdy = (GLint) (fdx1 * d2 - fdx2 * d1);
+ d1 = p1->g - p0->g;
+ d2 = p2->g - p0->g;
+ dgdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ dgdy = (GLint)(fdx1 * d2 - fdx2 * d1);
- d1 = p1->b - p0->b;
- d2 = p2->b - p0->b;
- dbdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- dbdy = (GLint) (fdx1 * d2 - fdx2 * d1);
+ d1 = p1->b - p0->b;
+ d2 = p2->b - p0->b;
+ dbdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ dbdy = (GLint)(fdx1 * d2 - fdx2 * d1);
#endif
-
+
#ifdef INTERP_ST
- d1 = p1->s - p0->s;
- d2 = p2->s - p0->s;
- dsdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- dsdy = (GLint) (fdx1 * d2 - fdx2 * d1);
-
- d1 = p1->t - p0->t;
- d2 = p2->t - p0->t;
- dtdx = (GLint) (fdy2 * d1 - fdy1 * d2);
- dtdy = (GLint) (fdx1 * d2 - fdx2 * d1);
+ d1 = p1->s - p0->s;
+ d2 = p2->s - p0->s;
+ dsdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ dsdy = (GLint)(fdx1 * d2 - fdx2 * d1);
+
+ d1 = p1->t - p0->t;
+ d2 = p2->t - p0->t;
+ dtdx = (GLint)(fdy2 * d1 - fdy1 * d2);
+ dtdy = (GLint)(fdx1 * d2 - fdx2 * d1);
#endif
#ifdef INTERP_STZ
- {
- GLfloat zz;
- zz=(GLfloat) p0->z;
- p0->sz= (GLfloat) p0->s * zz;
- p0->tz= (GLfloat) p0->t * zz;
- zz=(GLfloat) p1->z;
- p1->sz= (GLfloat) p1->s * zz;
- p1->tz= (GLfloat) p1->t * zz;
- zz=(GLfloat) p2->z;
- p2->sz= (GLfloat) p2->s * zz;
- p2->tz= (GLfloat) p2->t * zz;
+ {
+ GLfloat zz;
+ zz = (GLfloat)p0->z;
+ p0->sz = (GLfloat)p0->s * zz;
+ p0->tz = (GLfloat)p0->t * zz;
+ zz = (GLfloat)p1->z;
+ p1->sz = (GLfloat)p1->s * zz;
+ p1->tz = (GLfloat)p1->t * zz;
+ zz = (GLfloat)p2->z;
+ p2->sz = (GLfloat)p2->s * zz;
+ p2->tz = (GLfloat)p2->t * zz;
- d1 = p1->sz - p0->sz;
- d2 = p2->sz - p0->sz;
- dszdx = (fdy2 * d1 - fdy1 * d2);
- dszdy = (fdx1 * d2 - fdx2 * d1);
-
- d1 = p1->tz - p0->tz;
- d2 = p2->tz - p0->tz;
- dtzdx = (fdy2 * d1 - fdy1 * d2);
- dtzdy = (fdx1 * d2 - fdx2 * d1);
- }
+ d1 = p1->sz - p0->sz;
+ d2 = p2->sz - p0->sz;
+ dszdx = (fdy2 * d1 - fdy1 * d2);
+ dszdy = (fdx1 * d2 - fdx2 * d1);
+
+ d1 = p1->tz - p0->tz;
+ d2 = p2->tz - p0->tz;
+ dtzdx = (fdy2 * d1 - fdy1 * d2);
+ dtzdy = (fdx1 * d2 - fdx2 * d1);
+ }
#endif
- /* screen coordinates */
+ /* screen coordinates */
- pp1 = (PIXEL *) ((GLbyte *) zb->pbuf + zb->linesize * p0->y);
+ pp1 = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * p0->y);
#if TGL_FEATURE_POLYGON_STIPPLE == 1
- the_y = p0->y;
+ the_y = p0->y;
#endif
- pz1 = zb->zbuf + p0->y * zb->xsize;
+ pz1 = zb->zbuf + p0->y * zb->xsize;
- DRAW_INIT();
+ DRAW_INIT();
- for(part=0;part<2;part++) {
- if (part == 0) {
- if (fz > 0) {
- update_left=1;
- update_right=1;
- l1=p0;
- l2=p2;
- pr1=p0;
- pr2=p1;
- } else {
- update_left=1;
- update_right=1;
- l1=p0;
- l2=p1;
- pr1=p0;
- pr2=p2;
- }
- nb_lines = p1->y - p0->y;
- } else {
- /* second part */
- if (fz > 0) {
- update_left=0;
- update_right=1;
- pr1=p1;
- pr2=p2;
- } else {
- update_left=1;
- update_right=0;
- l1=p1;
- l2=p2;
- }
- nb_lines = p2->y - p1->y + 1;
- }
+ for (part = 0; part < 2; part++) {
+ if (part == 0) {
+ if (fz > 0) {
+ update_left = 1;
+ update_right = 1;
+ l1 = p0;
+ l2 = p2;
+ pr1 = p0;
+ pr2 = p1;
+ } else {
+ update_left = 1;
+ update_right = 1;
+ l1 = p0;
+ l2 = p1;
+ pr1 = p0;
+ pr2 = p2;
+ }
+ nb_lines = p1->y - p0->y;
+ } else {
+ /* second part */
+ if (fz > 0) {
+ update_left = 0;
+ update_right = 1;
+ pr1 = p1;
+ pr2 = p2;
+ } else {
+ update_left = 1;
+ update_right = 0;
+ l1 = p1;
+ l2 = p2;
+ }
+ nb_lines = p2->y - p1->y + 1;
+ }
- /* compute the values for the left edge */
+ /* compute the values for the left edge */
- if (update_left) {
- dy1 = l2->y - l1->y;
- dx1 = l2->x - l1->x;
- if (dy1 > 0)
- tmp = (dx1 << 16) / dy1;
- else
- tmp = 0;
- x1 = l1->x;
- error = 0;
- derror = tmp & 0x0000ffff;
- dxdy_min = tmp >> 16;
- dxdy_max = dxdy_min + 1;
-
+ if (update_left) {
+ dy1 = l2->y - l1->y;
+ dx1 = l2->x - l1->x;
+ if (dy1 > 0)
+ tmp = (dx1 << 16) / dy1;
+ else
+ tmp = 0;
+ x1 = l1->x;
+ error = 0;
+ derror = tmp & 0x0000ffff;
+ dxdy_min = tmp >> 16;
+ dxdy_max = dxdy_min + 1;
+
#ifdef INTERP_Z
- z1=l1->z;
- dzdl_min=(dzdy + dzdx * dxdy_min);
- dzdl_max=dzdl_min + dzdx;
+ z1 = l1->z;
+ dzdl_min = (dzdy + dzdx * dxdy_min);
+ dzdl_max = dzdl_min + dzdx;
#endif
#ifdef INTERP_RGB
- r1=l1->r;
- drdl_min=(drdy + drdx * dxdy_min);
- drdl_max=drdl_min + drdx;
-
- g1=l1->g;
- dgdl_min=(dgdy + dgdx * dxdy_min);
- dgdl_max=dgdl_min + dgdx;
-
- b1=l1->b;
- dbdl_min=(dbdy + dbdx * dxdy_min);
- dbdl_max=dbdl_min + dbdx;
+ r1 = l1->r;
+ drdl_min = (drdy + drdx * dxdy_min);
+ drdl_max = drdl_min + drdx;
+
+ g1 = l1->g;
+ dgdl_min = (dgdy + dgdx * dxdy_min);
+ dgdl_max = dgdl_min + dgdx;
+
+ b1 = l1->b;
+ dbdl_min = (dbdy + dbdx * dxdy_min);
+ dbdl_max = dbdl_min + dbdx;
#endif
#ifdef INTERP_ST
- s1=l1->s;
- dsdl_min=(dsdy + dsdx * dxdy_min);
- dsdl_max=dsdl_min + dsdx;
-
- t1=l1->t;
- dtdl_min=(dtdy + dtdx * dxdy_min);
- dtdl_max=dtdl_min + dtdx;
+ s1 = l1->s;
+ dsdl_min = (dsdy + dsdx * dxdy_min);
+ dsdl_max = dsdl_min + dsdx;
+
+ t1 = l1->t;
+ dtdl_min = (dtdy + dtdx * dxdy_min);
+ dtdl_max = dtdl_min + dtdx;
#endif
#ifdef INTERP_STZ
- sz1=l1->sz;
- dszdl_min=(dszdy + dszdx * dxdy_min);
- dszdl_max=dszdl_min + dszdx;
-
- tz1=l1->tz;
- dtzdl_min=(dtzdy + dtzdx * dxdy_min);
- dtzdl_max=dtzdl_min + dtzdx;
+ sz1 = l1->sz;
+ dszdl_min = (dszdy + dszdx * dxdy_min);
+ dszdl_max = dszdl_min + dszdx;
+
+ tz1 = l1->tz;
+ dtzdl_min = (dtzdy + dtzdx * dxdy_min);
+ dtzdl_max = dtzdl_min + dtzdx;
#endif
- }
+ }
- /* compute values for the right edge */
+ /* compute values for the right edge */
- if (update_right) {
- dx2 = (pr2->x - pr1->x);
- dy2 = (pr2->y - pr1->y);
- if (dy2>0)
- dx2dy2 = ( dx2 << 16) / dy2;
- else
- dx2dy2 = 0;
- x2 = pr1->x << 16;
- }
+ if (update_right) {
+ dx2 = (pr2->x - pr1->x);
+ dy2 = (pr2->y - pr1->y);
+ if (dy2 > 0)
+ dx2dy2 = (dx2 << 16) / dy2;
+ else
+ dx2dy2 = 0;
+ x2 = pr1->x << 16;
+ }
- /* we draw all the scan line of the part */
+ /* we draw all the scan line of the part */
- while (nb_lines>0) {
- nb_lines--;
+ while (nb_lines > 0) {
+ nb_lines--;
#ifndef DRAW_LINE
- /* generic draw line */
- {
- register PIXEL *pp;
- register GLint n;
+ /* generic draw line */
+ {
+ register PIXEL* pp;
+ register GLint n;
#ifdef INTERP_Z
- register GLushort *pz;
- register GLuint z,zz;
+ register GLushort* pz;
+ register GLuint z, zz;
#endif
#ifdef INTERP_RGB
- register GLuint or1,og1,ob1;
+ register GLuint or1, og1, ob1;
#endif
#ifdef INTERP_ST
- register GLuint s,t;
+ register GLuint s, t;
#endif
#ifdef INTERP_STZ
- GLfloat sz,tz;
+ GLfloat sz, tz;
#endif
- n=(x2 >> 16) - x1;
- /*the_x = x1; //Gek added this to make determining the X coordinate easier!*/
- pp=(PIXEL *)((GLbyte *)pp1 + x1 * PSZB);
+ n = (x2 >> 16) - x1;
+ /*the_x = x1; //Gek added this to make determining the X coordinate easier!*/
+ pp = (PIXEL*)((GLbyte*)pp1 + x1 * PSZB);
#ifdef INTERP_Z
- pz=pz1+x1;
- z=z1;
+ pz = pz1 + x1;
+ z = z1;
#endif
#ifdef INTERP_RGB
- or1 = r1;
- og1 = g1;
- ob1 = b1;
+ or1 = r1;
+ og1 = g1;
+ ob1 = b1;
#endif
#ifdef INTERP_ST
- s=s1;
- t=t1;
+ s = s1;
+ t = t1;
#endif
#ifdef INTERP_STZ
- sz=sz1;
- tz=tz1;
+ sz = sz1;
+ tz = tz1;
#endif
- while (n>=3) {
- PUT_PIXEL(0);/*the_x++;*/
- PUT_PIXEL(1);/*the_x++;*/
- PUT_PIXEL(2);/*the_x++;*/
- PUT_PIXEL(3);/*the_x++;*/
+ while (n >= 3) {
+ PUT_PIXEL(0); /*the_x++;*/
+ PUT_PIXEL(1); /*the_x++;*/
+ PUT_PIXEL(2); /*the_x++;*/
+ PUT_PIXEL(3); /*the_x++;*/
#ifdef INTERP_Z
- pz+=4;
+ pz += 4;
#endif
- pp=(PIXEL *)((GLbyte *)pp + 4 * PSZB);
- n-=4;
- }
- while (n>=0) {
- PUT_PIXEL(0);/*the_x++;*/
+ pp = (PIXEL*)((GLbyte*)pp + 4 * PSZB);
+ n -= 4;
+ }
+ while (n >= 0) {
+ PUT_PIXEL(0); /*the_x++;*/
#ifdef INTERP_Z
- pz+=1;
+ pz += 1;
#endif
- pp=(PIXEL *)((GLbyte *)pp + PSZB);
- n-=1;
- }
- }
- //the_y++;
+ pp = (PIXEL*)((GLbyte*)pp + PSZB);
+ n -= 1;
+ }
+ }
+ // the_y++;
#else
- DRAW_LINE();//the_y++;
+ DRAW_LINE(); // the_y++;
#endif
-
- /* left edge */
- error+=derror;
- if (error > 0) {
- error-=0x10000;
- x1+=dxdy_max;
+
+ /* left edge */
+ error += derror;
+ if (error > 0) {
+ error -= 0x10000;
+ x1 += dxdy_max;
#ifdef INTERP_Z
- z1+=dzdl_max;
-#endif
+ z1 += dzdl_max;
+#endif
#ifdef INTERP_RGB
- r1+=drdl_max;
- g1+=dgdl_max;
- b1+=dbdl_max;
+ r1 += drdl_max;
+ g1 += dgdl_max;
+ b1 += dbdl_max;
#endif
#ifdef INTERP_ST
- s1+=dsdl_max;
- t1+=dtdl_max;
+ s1 += dsdl_max;
+ t1 += dtdl_max;
#endif
#ifdef INTERP_STZ
- sz1+=dszdl_max;
- tz1+=dtzdl_max;
+ sz1 += dszdl_max;
+ tz1 += dtzdl_max;
#endif
- } else {
- x1+=dxdy_min;
+ } else {
+ x1 += dxdy_min;
#ifdef INTERP_Z
- z1+=dzdl_min;
-#endif
+ z1 += dzdl_min;
+#endif
#ifdef INTERP_RGB
- r1+=drdl_min;
- g1+=dgdl_min;
- b1+=dbdl_min;
+ r1 += drdl_min;
+ g1 += dgdl_min;
+ b1 += dbdl_min;
#endif
#ifdef INTERP_ST
- s1+=dsdl_min;
- t1+=dtdl_min;
+ s1 += dsdl_min;
+ t1 += dtdl_min;
#endif
#ifdef INTERP_STZ
- sz1+=dszdl_min;
- tz1+=dtzdl_min;
+ sz1 += dszdl_min;
+ tz1 += dtzdl_min;
#endif
- }
-
- /* right edge */
- x2+=dx2dy2;
+ }
- /* screen coordinates */
- pp1=(PIXEL *)((GLbyte *)pp1 + zb->linesize);
+ /* right edge */
+ x2 += dx2dy2;
+
+ /* screen coordinates */
+ pp1 = (PIXEL*)((GLbyte*)pp1 + zb->linesize);
#if TGL_FEATURE_POLYGON_STIPPLE == 1
- the_y++;
+ the_y++;
#endif
- pz1+=zb->xsize;
- }
- }
+ pz1 += zb->xsize;
+ }
+ }
}
#undef INTERP_Z
@@ -369,5 +369,5 @@
#undef INTERP_STZ
#undef DRAW_INIT
-#undef DRAW_LINE
+#undef DRAW_LINE
#undef PUT_PIXEL