ref: ae22b98cfa98bd66b8e89101b4c15f5dff33c1e7
parent: 3201b4c5faf9949c1a4e655d4894c8cc4353869e
author: MHS <gek@katherine>
date: Mon Apr 5 13:05:37 EDT 2021
Automatic commit.
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -66,12 +66,13 @@
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
-if(override_drawmodes == 1)
- glBegin(GL_LINES);
-else if (override_drawmodes == 2)
- glBegin(GL_POINTS);
-else
- {glBegin(GL_QUAD_STRIP);}
+ if (override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else {
+ 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);
@@ -82,7 +83,7 @@
glEnd();
/* draw front sides of teeth */
- if(override_drawmodes == 1)
+ if (override_drawmodes == 1)
glBegin(GL_LINES);
else if (override_drawmodes == 2)
glBegin(GL_POINTS);
@@ -102,7 +103,7 @@
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
- if(override_drawmodes == 1)
+ if (override_drawmodes == 1)
glBegin(GL_LINES);
else if (override_drawmodes == 2)
glBegin(GL_POINTS);
@@ -118,7 +119,7 @@
glEnd();
/* draw back sides of teeth */
- if(override_drawmodes == 1)
+ if (override_drawmodes == 1)
glBegin(GL_LINES);
else if (override_drawmodes == 2)
glBegin(GL_POINTS);
@@ -136,7 +137,7 @@
glEnd();
/* draw outward faces of teeth */
- if(override_drawmodes == 1)
+ if (override_drawmodes == 1)
glBegin(GL_LINES);
else if (override_drawmodes == 2)
glBegin(GL_POINTS);
@@ -171,9 +172,8 @@
glEnd();
-
/* draw inside radius cylinder */
- if(override_drawmodes == 1)
+ if (override_drawmodes == 1)
glBegin(GL_LINES);
else if (override_drawmodes == 2)
glBegin(GL_POINTS);
@@ -197,7 +197,7 @@
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 );
+ // glRotatef( view_rotz, 0.0, 0.0, 1.0 );
glPushMatrix();
glTranslatef(-3.0, -2.0, 0.0);
@@ -223,7 +223,7 @@
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 pos[4] = {5, 5, -10, 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};
@@ -233,15 +233,14 @@
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
// glLightfv( GL_LIGHT0, GL_AMBIENT, white);
- glLightfv( GL_LIGHT0, GL_SPECULAR, white);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, white);
glEnable(GL_CULL_FACE);
-
+
glEnable(GL_LIGHT0);
- //glEnable(GL_DEPTH_TEST);
-
+ // glEnable(GL_DEPTH_TEST);
glEnable(GL_POLYGON_STIPPLE);
-// glDisable(GL_POLYGON_STIPPLE);
+ // glDisable(GL_POLYGON_STIPPLE);
glPolygonStipple(stipplepattern);
glPointSize(10.0f);
glTextSize(GL_TEXT_SIZE24x24);
@@ -292,26 +291,26 @@
winSizeY = atoi(argv[i]);
if (!strcmp(larg, "-fps"))
fps = strtoull(argv[i], 0, 10);
- if (!strcmp(argv[i],"-flat"))
+ if (!strcmp(argv[i], "-flat"))
flat = 1;
- if (!strcmp(argv[i],"-smooth"))
+ if (!strcmp(argv[i], "-smooth"))
flat = 0;
- if (!strcmp(argv[i],"-blend"))
+ if (!strcmp(argv[i], "-blend"))
blending = 1;
- if (!strcmp(argv[i],"-nospecular"))
+ if (!strcmp(argv[i], "-nospecular"))
setenspec = 0;
- if (!strcmp(argv[i],"-lines"))
+ if (!strcmp(argv[i], "-lines"))
override_drawmodes = 1;
- if (!strcmp(argv[i],"-points"))
+ if (!strcmp(argv[i], "-points"))
override_drawmodes = 2;
- if (!strcmp(argv[i],"-nosdl"))
+ if (!strcmp(argv[i], "-nosdl"))
noSDL = 1;
- if (!strcmp(argv[i],"-notext"))
+ if (!strcmp(argv[i], "-notext"))
dotext = 0;
larg = argv[i];
}
}
- if(!noSDL){
+ if (!noSDL) {
#ifdef PLAY_MUSIC
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
#else
@@ -320,17 +319,19 @@
fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
return 1;
}
- } else if(SDL_Init(0) < 0) fprintf(stderr, "ERROR: cannot initialize SDL without video.\n");
+ } else if (SDL_Init(0) < 0)
+ fprintf(stderr, "ERROR: cannot initialize SDL without video.\n");
#ifdef PLAY_MUSIC
- if(!noSDL) ainit(0);
+ if (!noSDL)
+ ainit(0);
#endif
SDL_Surface* screen = NULL;
- if(!noSDL)
- if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
- fprintf(stderr, "ERROR: Video mode set failed.\n");
- return 1;
- }
- if(!noSDL){
+ if (!noSDL)
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ if (!noSDL) {
printf("\nRMASK IS %u", screen->format->Rmask);
printf("\nGMASK IS %u", screen->format->Gmask);
printf("\nBMASK IS %u", screen->format->Bmask);
@@ -337,14 +338,14 @@
printf("\nAMASK IS %u", screen->format->Amask);
}
#if TGL_FEATURE_RENDER_BITS == 32
- if(!noSDL)
- 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");
- }
+ if (!noSDL)
+ 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
- if(!noSDL){
+ if (!noSDL) {
printf("\nRSHIFT IS %u", screen->format->Rshift);
printf("\nGSHIFT IS %u", screen->format->Gshift);
printf("\nBSHIFT IS %u", screen->format->Bshift);
@@ -352,76 +353,85 @@
}
fflush(stdout);
#ifdef PLAY_MUSIC
-
+
track* myTrack = NULL;
- if(!noSDL) myTrack = lmus("WWGW.mp3");
- if(!noSDL) mplay(myTrack, -1, 1000);
+ if (!noSDL)
+ myTrack = lmus("WWGW.mp3");
+ if (!noSDL)
+ mplay(myTrack, -1, 1000);
#endif
- if(!noSDL) SDL_ShowCursor(SDL_DISABLE);
- if(!noSDL) SDL_WM_SetCaption(argv[0], 0);
+ if (!noSDL)
+ SDL_ShowCursor(SDL_DISABLE);
+ if (!noSDL)
+ SDL_WM_SetCaption(argv[0], 0);
// initialize TinyGL:
// unsigned int pitch;
- //int mode;
- if(!noSDL)
- 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;
- }
+ // int mode;
+ if (!noSDL)
+ 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 = NULL;
- if(TGL_FEATURE_RENDER_BITS == 32)
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
+ if (TGL_FEATURE_RENDER_BITS == 32)
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
else
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
- if(!frameBuffer){printf("\nZB_open failed!");exit(1);}
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
+ if (!frameBuffer) {
+ printf("\nZB_open failed!");
+ exit(1);
+ }
glInit(frameBuffer);
- //Print version info
- printf("\nVersion string:\n%s",glGetString(GL_VERSION));
- printf("\nVendor string:\n%s",glGetString(GL_VENDOR));
- printf("\nRenderer string:\n%s",glGetString(GL_RENDERER));
- printf("\nExtensions string:\n%s",glGetString(GL_EXTENSIONS));
- printf("\nLicense string:\n%s",glGetString(GL_LICENSE));
+ // Print version info
+ printf("\nVersion string:\n%s", glGetString(GL_VERSION));
+ printf("\nVendor string:\n%s", glGetString(GL_VENDOR));
+ printf("\nRenderer string:\n%s", glGetString(GL_RENDERER));
+ printf("\nExtensions string:\n%s", glGetString(GL_EXTENSIONS));
+ printf("\nLicense string:\n%s", glGetString(GL_LICENSE));
// initialize GL:
glClearColor(0.0, 0.0, 0.0, 0.0);
glViewport(0, 0, winSizeX, winSizeY);
-if(flat) glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH);
-//TESTING BLENDING...
- //glDisable(GL_DEPTH_TEST);
+ if (flat)
+ glShadeModel(GL_FLAT);
+ else
+ glShadeModel(GL_SMOOTH);
+ // TESTING BLENDING...
+ // glDisable(GL_DEPTH_TEST);
-
- //glDisable( GL_LIGHTING );
+ // glDisable( GL_LIGHTING );
glEnable(GL_LIGHTING);
- //glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ZERO);
+ // glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ZERO);
glBlendEquation(GL_FUNC_ADD);
- if(blending){
+ if (blending) {
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
glBlendEquation(GL_FUNC_ADD);
- }else{
+ } else {
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
@@ -435,7 +445,10 @@
glTranslatef(0.0, 0.0, -45.0);
initScene();
- if(setenspec) glSetEnableSpecular(GL_TRUE); else glSetEnableSpecular(GL_FALSE);
+ if (setenspec)
+ glSetEnableSpecular(GL_TRUE);
+ else
+ glSetEnableSpecular(GL_FALSE);
// variables for timing:
unsigned int frames = 0;
unsigned int tNow = SDL_GetTicks();
@@ -443,61 +456,64 @@
// main loop:
int isRunning = 1;
- //float test = 0;
+ // float test = 0;
while (isRunning) {
++frames;
- //Depending on SDL to give us ticks even without a window open...
+ // Depending on SDL to give us ticks even without a window open...
tNow = SDL_GetTicks();
- // test = TEST_fastInvSqrt(tNow);
- // printf("\n%f",test);
+ // test = TEST_fastInvSqrt(tNow);
+ // printf("\n%f",test);
// do event handling:
- if(!noSDL){
- 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;
+ if (!noSDL) {
+ 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 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:
+ case SDL_QUIT:
isRunning = 0;
- default:
break;
}
- break;
- case SDL_QUIT:
- isRunning = 0;
- break;
- }
}
// draw scene:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
- if(dotext){
+ if (dotext) {
glDrawText((unsigned char*)"RED text", 0, 0, 0xFF0000);
glDrawText((unsigned char*)"GREEN text", 0, 24, 0x00FF00);
- glDrawText((unsigned char*)"\xa2" "BLUE text" "\xa1", 0, 48, 0xFF);
+ glDrawText((unsigned char*)"\xa2"
+ "BLUE text"
+ "\xa1",
+ 0, 48, 0xFF);
}
// swap buffers:
- if(!noSDL)
- 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 (!noSDL)
+ 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)
@@ -507,25 +523,27 @@
((DATONE & 0x000000FF) >> 16) << screen->format->Bshift;
}
#endif
-
- if(!noSDL) ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if(!noSDL)
+
+ if (!noSDL)
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (!noSDL)
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
- if(!noSDL)SDL_Flip(screen);
- if(!noSDL)
+ if (!noSDL)
+ SDL_Flip(screen);
+ if (!noSDL)
if (fps > 0)
if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
}
// check for error conditions:
- if(!noSDL){
- char* sdl_error = SDL_GetError();
- if (sdl_error[0] != '\0') {
- fprintf(stderr, "SDL ERROR: \"%s\"\n", sdl_error);
- SDL_ClearError();
+ if (!noSDL) {
+ 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,
@@ -536,18 +554,21 @@
}
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);
+ // glDeleteList(gear1);
+ // glDeleteList(gear2);
+ // glDeleteList(gear3);
ZB_close(frameBuffer);
glClose();
- if(!noSDL)
- if (SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ if (!noSDL)
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- if(!noSDL)mhalt();
- if(!noSDL)Mix_FreeMusic(myTrack);
- if(!noSDL)acleanup();
+ if (!noSDL)
+ mhalt();
+ if (!noSDL)
+ Mix_FreeMusic(myTrack);
+ if (!noSDL)
+ acleanup();
#endif
SDL_Quit();
return 0;
--- a/SDL_Examples/helloworld.c
+++ b/SDL_Examples/helloworld.c
@@ -37,7 +37,7 @@
int winSizeY = 480;
void draw() {
- //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D,tex);
// time_passed += 0.0166666;
@@ -61,7 +61,7 @@
}
void draw2() {
- //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int x = 0;
// Select and setup the projection matrix
glMatrixMode(GL_PROJECTION);
@@ -130,14 +130,14 @@
winSizeY = atoi(argv[i]);
if (!strcmp(larg, "-fps"))
fps = strtoull(argv[i], 0, 10);
- if (!strcmp(argv[i],"-nosdl"))
+ if (!strcmp(argv[i], "-nosdl"))
noSDL = 1;
- if (!strcmp(argv[i],"-2"))
+ if (!strcmp(argv[i], "-2"))
do2 = 1;
larg = argv[i];
}
}
- if(!noSDL){
+ if (!noSDL) {
#ifdef PLAY_MUSIC
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
#else
@@ -146,17 +146,19 @@
fprintf(stderr, "ERROR: cannot initialize SDL video.\n");
return 1;
}
- } else if(SDL_Init(0) < 0) fprintf(stderr, "ERROR: cannot initialize SDL without video.\n");
+ } else if (SDL_Init(0) < 0)
+ fprintf(stderr, "ERROR: cannot initialize SDL without video.\n");
#ifdef PLAY_MUSIC
- if(!noSDL)ainit(0);
+ if (!noSDL)
+ ainit(0);
#endif
SDL_Surface* screen = NULL;
- if(!noSDL)
- if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
- fprintf(stderr, "ERROR: Video mode set failed.\n");
- return 1;
- }
- if(!noSDL){
+ if (!noSDL)
+ if ((screen = SDL_SetVideoMode(winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0) {
+ fprintf(stderr, "ERROR: Video mode set failed.\n");
+ return 1;
+ }
+ if (!noSDL) {
printf("\nRMASK IS %u", screen->format->Rmask);
printf("\nGMASK IS %u", screen->format->Gmask);
printf("\nBMASK IS %u", screen->format->Bmask);
@@ -163,14 +165,14 @@
printf("\nAMASK IS %u", screen->format->Amask);
}
#if TGL_FEATURE_RENDER_BITS == 32
- if(!noSDL)
- 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");
- }
+ if (!noSDL)
+ 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
- if(!noSDL){
+ if (!noSDL) {
printf("\nRSHIFT IS %u", screen->format->Rshift);
printf("\nGSHIFT IS %u", screen->format->Gshift);
printf("\nBSHIFT IS %u", screen->format->Bshift);
@@ -179,46 +181,50 @@
fflush(stdout);
#ifdef PLAY_MUSIC
track* myTrack = NULL;
- if(!noSDL) myTrack = lmus("WWGW.mp3");
- if(!noSDL) mplay(myTrack, -1, 1000);
+ if (!noSDL)
+ myTrack = lmus("WWGW.mp3");
+ if (!noSDL)
+ mplay(myTrack, -1, 1000);
#endif
- if(!noSDL)SDL_ShowCursor(SDL_DISABLE);
- if(!noSDL)SDL_WM_SetCaption(argv[0], 0);
+ if (!noSDL)
+ SDL_ShowCursor(SDL_DISABLE);
+ if (!noSDL)
+ SDL_WM_SetCaption(argv[0], 0);
// initialize TinyGL:
// unsigned int pitch;
int mode;
- if(!noSDL)
- switch (screen->format->BitsPerPixel) {
- case 8:
- fprintf(stderr, "ERROR: Palettes are currently not supported.\n");
- fprintf(stderr, "\nUnsupported by maintainer!!!");
- return 1;
- case 16:
+ if (!noSDL)
+ 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_5R6G5B;
+ // return 1;
+ break;
+ case 24:
- fprintf(stderr, "\nUnsupported by maintainer!!!");
- mode = ZB_MODE_RGB24;
- return 1;
- break;
- case 32:
+ fprintf(stderr, "\nUnsupported by maintainer!!!");
+ mode = ZB_MODE_RGB24;
+ return 1;
+ break;
+ case 32:
- mode = ZB_MODE_RGBA;
- break;
- default:
- return 1;
- break;
- }
+ mode = ZB_MODE_RGBA;
+ break;
+ default:
+ return 1;
+ break;
+ }
ZBuffer* frameBuffer = NULL;
- if(TGL_FEATURE_RENDER_BITS == 32)
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
+ if (TGL_FEATURE_RENDER_BITS == 32)
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
else
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
glInit(frameBuffer);
// initialize GL:
@@ -266,24 +272,24 @@
// draw scene:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if(do2)
+ if (do2)
draw2();
else
draw();
glDrawText((unsigned char*)"Hello World!\nFrom TinyGL", 0, 0, 0x00FFFFFF);
// swap buffers:
- if(!noSDL)
- 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
+ if (!noSDL)
+ 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
#if TGL_FEATURE_RENDER_BITS == 32
if (needsRGBAFix)
for (int i = 0; i < frameBuffer->xsize * frameBuffer->ysize; i++) {
@@ -292,21 +298,26 @@
((DATONE & 0x00FF0000) >> 16) << screen->format->Bshift;
}
#endif
- if(!noSDL) ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
- if(!noSDL) if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
- if(!noSDL) SDL_Flip(screen);
- if(!noSDL) if (fps > 0)
- if ((1000 / fps) > (SDL_GetTicks() - tNow)) {
- SDL_Delay((1000 / fps) - (SDL_GetTicks() - tNow)); // Yay stable framerate!
- }
+ if (!noSDL)
+ ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
+ if (!noSDL)
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ if (!noSDL)
+ SDL_Flip(screen);
+ if (!noSDL)
+ 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();
+ 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,
@@ -319,13 +330,16 @@
// cleanup:
ZB_close(frameBuffer);
glClose();
- if(!noSDL)
- if (SDL_WasInit(SDL_INIT_VIDEO))
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ if (!noSDL)
+ if (SDL_WasInit(SDL_INIT_VIDEO))
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef PLAY_MUSIC
- if(!noSDL)mhalt();
- if(!noSDL)Mix_FreeMusic(myTrack);
- if(!noSDL)acleanup();
+ if (!noSDL)
+ mhalt();
+ if (!noSDL)
+ Mix_FreeMusic(myTrack);
+ if (!noSDL)
+ acleanup();
#endif
SDL_Quit();
return 0;
--- a/SDL_Examples/menu.c
+++ b/SDL_Examples/menu.c
@@ -25,11 +25,10 @@
#endif
#include <SDL/SDL.h>
-//Gek's OpenIMGUI standard.
+// Gek's OpenIMGUI standard.
#define OPENIMGUI_IMPL
#include "../include-demo/openimgui.h"
-
#ifndef M_PI
#define M_PI 3.14159265
#endif
@@ -38,16 +37,20 @@
int winSizeY = 480;
double tpassed = 0;
int isRunning = 1;
-int dirbstates[4] = {0,0,0,0}; //up,down,left,right
-int mousepos[2] = {0,0};
-int using_cursorkeys = 0; //Switches to cursor keys upon pressing a key.
-int mb = 0; //cursor button
-int mb2 = 0; //cursor second button.
+int dirbstates[4] = {0, 0, 0, 0}; // up,down,left,right
+int mousepos[2] = {0, 0};
+int using_cursorkeys = 0; // Switches to cursor keys upon pressing a key.
+int mb = 0; // cursor button
+int mb2 = 0; // cursor second button.
-#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
@@ -55,147 +58,152 @@
#define E_WINW e->window.data1
#define E_WINH e->window.data2
-vec3 mouse_to_normal(int mx, int my){
+vec3 mouse_to_normal(int mx, int my) {
vec3 r;
- r.d[0] = mx / (float) winSizeX;
- r.d[1] = my / (float) winSizeY;
+ r.d[0] = mx / (float)winSizeX;
+ r.d[1] = my / (float)winSizeY;
return r;
}
-void drawBox(GLfloat x, GLfloat y, GLfloat xdim, GLfloat ydim){ //0,0 is top left, 1,1 is bottom right
+void drawBox(GLfloat x, GLfloat y, GLfloat xdim, GLfloat ydim) { // 0,0 is top left, 1,1 is bottom right
- x*=2;xdim*=2;
- y*=2;ydim*=2;
+ x *= 2;
+ xdim *= 2;
+ y *= 2;
+ ydim *= 2;
glBegin(GL_TRIANGLES);
// TRIANGLE 1,
- glTexCoord2f(0, 0);
- glVertex3f(-1+x, 1-y-ydim, 0.5); //Bottom Left Corner
+ glTexCoord2f(0, 0);
+ glVertex3f(-1 + x, 1 - y - ydim, 0.5); // Bottom Left Corner
glTexCoord2f(1, -1);
- glVertex3f(-1+x+xdim, 1-y , 0.5); //Top Right Corner
+ glVertex3f(-1 + x + xdim, 1 - y, 0.5); // Top Right Corner
glTexCoord2f(0, -1);
- glVertex3f(-1+x, 1-y, 0.5); //Top Left
+ glVertex3f(-1 + x, 1 - y, 0.5); // Top Left
// TRIANGLE 2
glTexCoord2f(0, 0);
- glVertex3f(-1+x, 1-y-ydim, 0.5); //Bottom Left Corner
+ glVertex3f(-1 + x, 1 - y - ydim, 0.5); // Bottom Left Corner
glTexCoord2f(1, 0);
- glVertex3f(-1+x+xdim, 1-y-ydim, 0.5);
+ glVertex3f(-1 + x + xdim, 1 - y - ydim, 0.5);
glTexCoord2f(1, -1);
- glVertex3f(-1+x+xdim, 1-y , 0.5); //Top Right Corner
+ glVertex3f(-1 + x + xdim, 1 - y, 0.5); // Top Right Corner
glEnd();
return;
}
-
-
-void drawMouse(){
- if(!omg_cb)
- glColor3f(0.7,0.7,0.7);
+void drawMouse() {
+ if (!omg_cb)
+ glColor3f(0.7, 0.7, 0.7);
else
- glColor3f(1.0,0.1,0.1);
- //if(!using_cursorkeys)
- drawBox(omg_cursorpos[0],omg_cursorpos[1], 0.03, 0.03);
- //else
+ glColor3f(1.0, 0.1, 0.1);
+ // if(!using_cursorkeys)
+ drawBox(omg_cursorpos[0], omg_cursorpos[1], 0.03, 0.03);
+ // else
// drawBox(omg_cursorpos_presuck[0],omg_cursorpos_presuck[1], 0.03, 0.03);
}
-void drawTB(const char* text, GLuint textcolor, GLfloat x, GLfloat y, GLint size, float* tw, float* th){
- size = (size>64)?64:((size<8)?8:size);
- size >>= 3; //divide by 8 to get the GLTEXTSIZE
- if(!size || !text) return;
- int mw = 0, h = 1, cw = 0; //max width, height, current width
- for(int i = 0; text[i] != '\0' && (text[i] & 127);i++){
- if(text[i] != '\n')
- cw++;
- else
- {cw = 0; h++;}
- if(mw<cw)mw=cw;
+void drawTB(const char* text, GLuint textcolor, GLfloat x, GLfloat y, GLint size, float* tw, float* th) {
+ size = (size > 64) ? 64 : ((size < 8) ? 8 : size);
+ size >>= 3; // divide by 8 to get the GLTEXTSIZE
+ if (!size || !text)
+ return;
+ int mw = 0, h = 1, cw = 0; // max width, height, current width
+ for (int i = 0; text[i] != '\0' && (text[i] & 127); i++) {
+ if (text[i] != '\n')
+ cw++;
+ else {
+ cw = 0;
+ h++;
+ }
+ if (mw < cw)
+ mw = cw;
}
- float w = (size)*8*(mw) / (float)winSizeX;
- float bw = 3*size/(float)winSizeX;
- float h_ = (size)*8*(h)/(float)winSizeY;
- float bh = 3*size/(float)winSizeY;
- drawBox(x,y, w, h_);
- *tw = w+bw;
- *th = h_+bh;
+ float w = (size)*8 * (mw) / (float)winSizeX;
+ float bw = 3 * size / (float)winSizeX;
+ float h_ = (size)*8 * (h) / (float)winSizeY;
+ float bh = 3 * size / (float)winSizeY;
+ drawBox(x, y, w, h_);
+ *tw = w + bw;
+ *th = h_ + bh;
glTextSize(size);
- glDrawText((unsigned char*)text, x*winSizeX, y*winSizeY, textcolor);
+ glDrawText((unsigned char*)text, x * winSizeX, y * winSizeY, textcolor);
return;
}
-int omg_box(float x, float y, float xdim, float ydim, int sucks, float buttonjumpx, float buttonjumpy, int hints){
- //hints is the color of the box.
- float r = ((hints & 0xFF0000)>>16) / 255.0;
- float g = ((hints & 0xFF00)>>8) / 255.0;
- float b = ((hints & 0xFF)) / 255.0;
- glColor3f(r,g,b);
- drawBox(x,y,xdim,ydim);
+int omg_box(float x, float y, float xdim, float ydim, int sucks, float buttonjumpx, float buttonjumpy, int hints) {
+ // hints is the color of the box.
+ float r = ((hints & 0xFF0000) >> 16) / 255.0;
+ float g = ((hints & 0xFF00) >> 8) / 255.0;
+ float b = ((hints & 0xFF)) / 255.0;
+ glColor3f(r, g, b);
+ drawBox(x, y, xdim, ydim);
omg_box_suck(x, y, xdim, ydim, sucks, buttonjumpx, buttonjumpy);
return omg_box_retval(x, y, xdim, ydim);
}
-int omg_textbox(float x, float y, const char* text, int textsize, int sucks, float buttonjumpx, float buttonjumpy, int hints, int hintstext){
- float r = ((hints & 0xFF0000)>>16) / 255.0;
- float g = ((hints & 0xFF00)>>8) / 255.0;
- float b = ((hints & 0xFF)) / 255.0;
- glColor3f(r,g,b);
+int omg_textbox(float x, float y, const char* text, int textsize, int sucks, float buttonjumpx, float buttonjumpy, int hints, int hintstext) {
+ float r = ((hints & 0xFF0000) >> 16) / 255.0;
+ float g = ((hints & 0xFF00) >> 8) / 255.0;
+ float b = ((hints & 0xFF)) / 255.0;
+ glColor3f(r, g, b);
float xdim = 0, ydim = 0;
- drawTB(text, (GLuint)hintstext, x,y,textsize, &xdim, &ydim);
+ drawTB(text, (GLuint)hintstext, x, y, textsize, &xdim, &ydim);
omg_box_suck(x, y, xdim, ydim, sucks, buttonjumpx, buttonjumpy);
return omg_box_retval(x, y, xdim, ydim);
}
-int haveclicked = 0; //For our toggleable movable button.
-vec3 tbcoords = (vec3){{0.4,0.4,0}};
-vec3 slidcoords = (vec3){{0.1,0.8,0}};
+int haveclicked = 0; // For our toggleable movable button.
+vec3 tbcoords = (vec3){{0.4, 0.4, 0}};
+vec3 slidcoords = (vec3){{0.1, 0.8, 0}};
float slidmoffset = 0;
-int slidersliding = 0; //Is the slider being slid?
+int slidersliding = 0; // Is the slider being slid?
void draw() {
- if(mb2){ //Use an additional input to move gui elements for testing- right click moves the button.
+ if (mb2) { // Use an additional input to move gui elements for testing- right click moves the button.
tbcoords.d[0] = omg_cursorpos[0];
- tbcoords.d[1] = omg_cursorpos[1];
+ tbcoords.d[1] = omg_cursorpos[1];
haveclicked = 0;
}
- if(omg_textbox(0.01, 0, "\nEntry 1\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2 )
+ if (omg_textbox(0.01, 0, "\nEntry 1\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
puts("Entry 1");
- if(omg_textbox(0.01, 0.2, "\nEntry 2\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
+ if (omg_textbox(0.01, 0.2, "\nEntry 2\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
puts("Entry 2");
- if(omg_textbox(0.01, 0.4, "\nEntry 3\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
+ if (omg_textbox(0.01, 0.4, "\nEntry 3\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
puts("Entry 3");
- if(omg_textbox(0.01, 0.6, "\nQuit\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2)
- {puts("Quitting...");isRunning = 0;}
-
- if(
- omg_textbox(tbcoords.d[0], tbcoords.d[1], "\nClick me and I toggle color!\n", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked?0xFF0000:0x00) && omg_cb == 1)
- {puts("Detected click! EVENT FIRED!\n");haveclicked = !haveclicked; }
- //A slider element
- if(
- omg_textbox(slidcoords.d[0], slidcoords.d[1], "\n Slider \n", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked?0xFF0000:0x00)
- && omg_cb ==1
- ){
- slidersliding = 1;
- slidmoffset = omg_cursorpos[0] - slidcoords.d[0];
+ if (omg_textbox(0.01, 0.6, "\nQuit\n", 24, 1, 0.4, 0.2, 0xFFFFFF, 0) && omg_cb == 2) {
+ puts("Quitting...");
+ isRunning = 0;
}
- if(omg_cb == 2)
- slidersliding = 0;
- //Handle the slider sliding behavior.
- if(slidersliding){
- if(using_cursorkeys){
- if(omg_udlr[3]){
- slidcoords.d[0] = clampf(slidcoords.d[0] + 0.05,0.1,0.7);
+
+ if (omg_textbox(tbcoords.d[0], tbcoords.d[1], "\nClick me and I toggle color!\n", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked ? 0xFF0000 : 0x00) &&
+ omg_cb == 1) {
+ puts("Detected click! EVENT FIRED!\n");
+ haveclicked = !haveclicked;
+ }
+ // A slider element
+ if (omg_textbox(slidcoords.d[0], slidcoords.d[1], "\n Slider \n", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked ? 0xFF0000 : 0x00) && omg_cb == 1) {
+ slidersliding = 1;
+ slidmoffset = omg_cursorpos[0] - slidcoords.d[0];
+ }
+ if (omg_cb == 2)
+ slidersliding = 0;
+ // Handle the slider sliding behavior.
+ if (slidersliding) {
+ if (using_cursorkeys) {
+ if (omg_udlr[3]) {
+ slidcoords.d[0] = clampf(slidcoords.d[0] + 0.05, 0.1, 0.7);
}
- if(omg_udlr[2]){
- slidcoords.d[0] = clampf(slidcoords.d[0] - 0.05,0.1,0.7);
+ if (omg_udlr[2]) {
+ slidcoords.d[0] = clampf(slidcoords.d[0] - 0.05, 0.1, 0.7);
}
omg_cursorpos[0] = slidcoords.d[0] + slidmoffset;
omg_cursorpos[1] = slidcoords.d[1];
} else {
- //Move the element to the cursorposition's x.
- slidcoords.d[0] = clampf(omg_cursorpos[0]- slidmoffset,0.1,0.7);
+ // Move the element to the cursorposition's x.
+ slidcoords.d[0] = clampf(omg_cursorpos[0] - slidmoffset, 0.1, 0.7);
}
printf("Slider's value is %f\n", slidcoords.d[0]);
}
@@ -211,11 +219,11 @@
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_CULL_FACE);
+ glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
- //glEnable(GL_LIGHTING);
- //glEnable(GL_TEXTURE_2D);
+ // glEnable(GL_LIGHTING);
+ // glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
// glEnable( GL_LIGHT0 );
@@ -226,64 +234,83 @@
glEnable(GL_NORMALIZE);
}
-
-
-
-
BEGIN_EVENT_HANDLER
- case SDL_KEYDOWN:
- using_cursorkeys = 1;
- switch(E_KEYSYM){
- case SDLK_ESCAPE:
- case SDLK_q:
- isRunning = 0;
- break;
- case SDLK_UP: dirbstates[0] = 1; break;
- case SDLK_DOWN: dirbstates[1] = 1; break;
- case SDLK_LEFT: dirbstates[2] = 1; break;
- case SDLK_RIGHT:dirbstates[3] = 1; break;
- case SDLK_SPACE: case SDLK_RETURN:
- mb = 1;
- break;
- default: break;
- }
+case SDL_KEYDOWN:
+using_cursorkeys = 1;
+switch (E_KEYSYM) {
+case SDLK_ESCAPE:
+case SDLK_q:
+ isRunning = 0;
break;
- case SDL_KEYUP:
- using_cursorkeys = 1;
- switch(E_KEYSYM){
- case SDLK_SPACE: case SDLK_RETURN:
- mb = 0;
- break;
- case SDLK_UP: dirbstates[0] = 0; break;
- case SDLK_DOWN: dirbstates[1] = 0; break;
- case SDLK_LEFT: dirbstates[2] = 0; break;
- case SDLK_RIGHT:dirbstates[3] = 0; break;
- default: break;
- }
+case SDLK_UP:
+ dirbstates[0] = 1;
break;
- case SDL_QUIT:isRunning = 0;break;
- case SDL_MOUSEBUTTONDOWN:
- if(E_BUTTON==SDL_BUTTON_LEFT) mb = 1;
- if(E_BUTTON==SDL_BUTTON_RIGHT) {
- mb2 = 1;
- }
- break;
- case SDL_MOUSEBUTTONUP:
- if(E_BUTTON==SDL_BUTTON_LEFT) mb = 0;
- if(E_BUTTON==SDL_BUTTON_RIGHT) mb2 = 0;
- break;
- case SDL_MOUSEMOTION:
- using_cursorkeys = 0;
- mousepos[0] = E_MOTION.x;
- mousepos[1] = E_MOTION.y;
+case SDLK_DOWN:
+ dirbstates[1] = 1;
break;
+case SDLK_LEFT:
+ dirbstates[2] = 1;
+ break;
+case SDLK_RIGHT:
+ dirbstates[3] = 1;
+ break;
+case SDLK_SPACE:
+case SDLK_RETURN:
+ mb = 1;
+ break;
+default:
+ break;
+}
+break;
+case SDL_KEYUP:
+using_cursorkeys = 1;
+switch (E_KEYSYM) {
+case SDLK_SPACE:
+case SDLK_RETURN:
+ mb = 0;
+ break;
+case SDLK_UP:
+ dirbstates[0] = 0;
+ break;
+case SDLK_DOWN:
+ dirbstates[1] = 0;
+ break;
+case SDLK_LEFT:
+ dirbstates[2] = 0;
+ break;
+case SDLK_RIGHT:
+ dirbstates[3] = 0;
+ break;
+default:
+ break;
+}
+break;
+case SDL_QUIT:
+isRunning = 0;
+break;
+case SDL_MOUSEBUTTONDOWN:
+if (E_BUTTON == SDL_BUTTON_LEFT)
+ mb = 1;
+if (E_BUTTON == SDL_BUTTON_RIGHT) {
+ mb2 = 1;
+}
+break;
+case SDL_MOUSEBUTTONUP:
+if (E_BUTTON == SDL_BUTTON_LEFT)
+ mb = 0;
+if (E_BUTTON == SDL_BUTTON_RIGHT)
+ mb2 = 0;
+break;
+case SDL_MOUSEMOTION:
+using_cursorkeys = 0;
+mousepos[0] = E_MOTION.x;
+mousepos[1] = E_MOTION.y;
+break;
END_EVENT_HANDLER
-
int main(int argc, char** argv) {
// initialize SDL video:
-
-
+
unsigned int fps = 0;
char needsRGBAFix = 0;
if (argc > 2) {
@@ -331,7 +358,7 @@
printf("\nBSHIFT IS %u", screen->format->Bshift);
printf("\nASHIFT IS %u\n", screen->format->Ashift);
fflush(stdout);
-
+
#ifdef PLAY_MUSIC
track* myTrack = NULL;
myTrack = lmus("WWGW.mp3");
@@ -381,25 +408,26 @@
unsigned int tLastFps = tNow;
// main loop:
-
+
while (isRunning) {
++frames;
- tpassed += frames * 16.666666/1000.0;
+ tpassed += frames * 16.666666 / 1000.0;
tNow = SDL_GetTicks();
// do event handling:
SDL_Event ev;
- while (SDL_PollEvent(&ev)) events(&ev);
- if(using_cursorkeys)
+ while (SDL_PollEvent(&ev))
+ events(&ev);
+ if (using_cursorkeys)
omg_update_keycursor(dirbstates[0], dirbstates[1], dirbstates[2], dirbstates[3], mb);
- else{
+ else {
vec3 r = mouse_to_normal(mousepos[0], mousepos[1]);
omg_update_mcursor(r.d[0], r.d[1], mb);
}
// draw scene:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //This is where we render our GUI!
+ // This is where we render our GUI!
draw();
- //glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x000000FF);
+ // 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());
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -51,8 +51,8 @@
float* texcoords;
} ModelArray;
-void FreeModelArray(){
- if(!ModelArrayLoaded){
+void FreeModelArray() {
+ if (!ModelArrayLoaded) {
ModelArray.points = NULL;
ModelArray.normals = NULL;
ModelArray.npoints = 0;
@@ -61,10 +61,14 @@
return;
}
ModelArrayLoaded = 0;
- if(ModelArray.points) free(ModelArray.points);
- if(ModelArray.normals) free(ModelArray.normals);
- if(ModelArray.texcoords) free(ModelArray.texcoords);
- if(ModelArray.colors) free(ModelArray.colors);
+ if (ModelArray.points)
+ free(ModelArray.points);
+ if (ModelArray.normals)
+ free(ModelArray.normals);
+ if (ModelArray.texcoords)
+ free(ModelArray.texcoords);
+ if (ModelArray.colors)
+ free(ModelArray.colors);
ModelArray.npoints = 0;
return;
}
@@ -73,27 +77,24 @@
vec3 a;
a.d[1] = (float)mousex * mouseratiox;
a.d[2] = (float)mousey * mouseratioy;
-
-
vec3 right = normalizev3(crossv3(camforw, camup));
right.d[1] = 0;
- //vec3 forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
-
+ // vec3 forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
+
camforw = normalizev3(rotatev3(camforw, right, -a.d[2]));
- //up = glm::normalize(glm::cross(forward, right));
+ // up = glm::normalize(glm::cross(forward, right));
camup = normalizev3(crossv3(right, camforw));
-
- //Perform the rotation about the Y axis last.
- static const vec3 UP = (vec3){{0,1,0}};
- static const vec3 DOWN = (vec3){{0,-1,0}};
- if(dotv3(UP, camup)<0){
+ // Perform the rotation about the Y axis last.
+ static const vec3 UP = (vec3){{0, 1, 0}};
+ static const vec3 DOWN = (vec3){{0, -1, 0}};
+ if (dotv3(UP, camup) < 0) {
camforw = normalizev3(rotatev3(camforw, DOWN, -a.d[1]));
camup = normalizev3(rotatev3(camup, DOWN, -a.d[1]));
} else {
camforw = normalizev3(rotatev3(camforw, UP, -a.d[1]));
- camup = normalizev3(rotatev3(camup,UP, -a.d[1]));
+ camup = normalizev3(rotatev3(camup, UP, -a.d[1]));
}
}
@@ -114,40 +115,40 @@
// f_ as float and not double!
// Remember that!
vec3* points, uint npoints, vec3* colors, vec3* normals, vec3* texcoords) {
- if (!points)return;
+ if (!points)
+ return;
FreeModelArray();
ModelArrayLoaded = 1;
ModelArray.npoints = npoints;
ModelArray.points = malloc(sizeof(float) * npoints * 3);
- if(normals)
+ if (normals)
ModelArray.normals = malloc(sizeof(float) * npoints * 3);
- if(texcoords)
+ if (texcoords)
ModelArray.texcoords = malloc(sizeof(float) * npoints * 2);
- if(colors)
+ if (colors)
ModelArray.colors = malloc(sizeof(float) * npoints * 3);
for (uint i = 0; i < npoints; i++) {
if (colors) { // Fix for TinyGL color interpolation.
- ModelArray.colors[i*3+0] = colors[i].d[0];
- ModelArray.colors[i*3+1] = colors[i].d[1];
- ModelArray.colors[i*3+2] = colors[i].d[2];
+ ModelArray.colors[i * 3 + 0] = colors[i].d[0];
+ ModelArray.colors[i * 3 + 1] = colors[i].d[1];
+ ModelArray.colors[i * 3 + 2] = colors[i].d[2];
}
- if (texcoords){
- ModelArray.texcoords[i*2+0] = texcoords[i].d[0];
- ModelArray.texcoords[i*2+1] = texcoords[i].d[1];
+ if (texcoords) {
+ ModelArray.texcoords[i * 2 + 0] = texcoords[i].d[0];
+ ModelArray.texcoords[i * 2 + 1] = texcoords[i].d[1];
}
- if (normals){
- ModelArray.normals[i*3+0] = normals[i].d[0];
- ModelArray.normals[i*3+1] = normals[i].d[1];
- ModelArray.normals[i*3+2] = normals[i].d[2];
+ if (normals) {
+ ModelArray.normals[i * 3 + 0] = normals[i].d[0];
+ ModelArray.normals[i * 3 + 1] = normals[i].d[1];
+ ModelArray.normals[i * 3 + 2] = normals[i].d[2];
}
- ModelArray.points[i*3+0] = points[i].d[0];
- ModelArray.points[i*3+1] = points[i].d[1];
- ModelArray.points[i*3+2] = points[i].d[2];
+ ModelArray.points[i * 3 + 0] = points[i].d[0];
+ ModelArray.points[i * 3 + 1] = points[i].d[1];
+ ModelArray.points[i * 3 + 2] = points[i].d[2];
}
}
-
-//Without display list
+// Without display list
void drawModelArrays(
// HUGE important note! these depend on the math library using
// f_ as float and not double!
@@ -196,9 +197,6 @@
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,
@@ -304,7 +302,7 @@
char needsRGBAFix = 0;
unsigned int count = 40;
GLuint modelDisplayList = 0;
- GLuint buffers[4]; //pos,color,normal,texcoord
+ GLuint buffers[4]; // pos,color,normal,texcoord
int dlExists = 0;
int doTextures = 1;
char* modelName = "extrude.obj";
@@ -327,11 +325,11 @@
modelName = argv[i];
if (!strcmp(argv[i], "-notexture") || !strcmp(larg, "-notexture"))
doTextures = 0;
- if(!strcmp(argv[i],"-arrays"))
+ if (!strcmp(argv[i], "-arrays"))
testingModelArrays = 1;
- if(!strcmp(argv[i],"-copy"))
+ if (!strcmp(argv[i], "-copy"))
testingCopyImage2D = 1;
- if(!strcmp(argv[i],"-blend"))
+ if (!strcmp(argv[i], "-blend"))
doblend = 1;
larg = argv[i];
}
@@ -403,10 +401,10 @@
}
ZBuffer* frameBuffer = NULL;
- if(TGL_FEATURE_RENDER_BITS == 32)
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
+ if (TGL_FEATURE_RENDER_BITS == 32)
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
else
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
glInit(frameBuffer);
srand(time(NULL));
@@ -415,15 +413,16 @@
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glSetEnableSpecular(0);
-static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};static GLfloat pos[4] = {5, 5, 10, 0.0}; // Light at infinity.
-
+ static GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
+ 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);
-
- //glDisable( GL_LIGHTING );
+
+ // glDisable( GL_LIGHTING );
glEnable(GL_LIGHT0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
@@ -437,7 +436,7 @@
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
- //glDisable(GL_LIGHTING);
+ // glDisable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
// glDisable(GL_DEPTH_TEST);
double t = 0;
@@ -455,9 +454,9 @@
} else {
m = tobj_tomodel(&omodel);
printf("\nHas %d points.\n", m.npoints);
- if(!testingModelArrays){
- modelDisplayList = createModelDisplayList(m.d, m.npoints, m.c, m.n, m.t);
- dlExists = 1;
+ if (!testingModelArrays) {
+ modelDisplayList = createModelDisplayList(m.d, m.npoints, m.c, m.n, m.t);
+ dlExists = 1;
} else {
LoadModelArrays(m.d, m.npoints, m.c, m.n, m.t);
/*
@@ -472,44 +471,32 @@
if(ModelArray.texcoords)glTexCoordPointer(2,GL_FLOAT,0,ModelArray.texcoords);
*/
glGenBuffers(4, buffers);
- for(int i = 0; i < 4; i++){
- printf("\nBuffer %d is %d", i , buffers[i]);
- if(buffers[i] == 0){
+ for (int i = 0; i < 4; i++) {
+ printf("\nBuffer %d is %d", i, buffers[i]);
+ if (buffers[i] == 0) {
printf("\nBuffer allocation failed for buffer %d!\n", i);
return 1;
}
}
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
- glBufferData(GL_ARRAY_BUFFER,
- sizeof(GLfloat) * 3 * ModelArray.npoints,
- ModelArray.points,
- GL_STATIC_DRAW);
- if(glMapBuffer(GL_ARRAY_BUFFER,0) == NULL)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * ModelArray.npoints, ModelArray.points, GL_STATIC_DRAW);
+ if (glMapBuffer(GL_ARRAY_BUFFER, 0) == NULL)
printf("\nglBufferData failed for buffer %d!\n", 0);
- glBindBufferAsArray(GL_VERTEX_BUFFER, buffers[0],GL_FLOAT,3,0);
- if(ModelArray.colors){
+ glBindBufferAsArray(GL_VERTEX_BUFFER, buffers[0], GL_FLOAT, 3, 0);
+ if (ModelArray.colors) {
glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
- glBufferData(GL_ARRAY_BUFFER,
- sizeof(GLfloat) * 3 * ModelArray.npoints,
- ModelArray.colors,
- GL_STATIC_DRAW);
- glBindBufferAsArray(GL_COLOR_BUFFER, buffers[1],GL_FLOAT,3,0);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * ModelArray.npoints, ModelArray.colors, GL_STATIC_DRAW);
+ glBindBufferAsArray(GL_COLOR_BUFFER, buffers[1], GL_FLOAT, 3, 0);
}
- if(ModelArray.normals){
+ if (ModelArray.normals) {
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
- glBufferData(GL_ARRAY_BUFFER,
- sizeof(GLfloat) * 3 * ModelArray.npoints,
- ModelArray.normals,
- GL_STATIC_DRAW);
- glBindBufferAsArray(GL_NORMAL_BUFFER, buffers[2],GL_FLOAT,3,0);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * ModelArray.npoints, ModelArray.normals, GL_STATIC_DRAW);
+ glBindBufferAsArray(GL_NORMAL_BUFFER, buffers[2], GL_FLOAT, 3, 0);
}
- if(ModelArray.texcoords){
+ if (ModelArray.texcoords) {
glBindBuffer(GL_ARRAY_BUFFER, buffers[3]);
- glBufferData(GL_ARRAY_BUFFER,
- sizeof(GLfloat) * 2 * ModelArray.npoints,
- ModelArray.texcoords,
- GL_STATIC_DRAW);
- glBindBufferAsArray(GL_TEXTURE_COORD_BUFFER,buffers[3],GL_FLOAT,2,0);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 2 * ModelArray.npoints, ModelArray.texcoords, GL_STATIC_DRAW);
+ glBindBufferAsArray(GL_TEXTURE_COORD_BUFFER, buffers[3], GL_FLOAT, 2, 0);
}
}
freemodel(&m);
@@ -522,9 +509,9 @@
int sw = 0, sh = 0, sc = 0; // sc goes unused.
#if TGL_FEATURE_NO_DRAW_COLOR == 1
uchar* source_data = stbi_load("tex_hole.png", &sw, &sh, &sc, 3);
-#else
+#else
uchar* source_data = stbi_load("tex.jpg", &sw, &sh, &sc, 3);
-#endif
+#endif
if (source_data) {
tex = loadRGBTexture(source_data, sw, sh);
free(source_data);
@@ -531,7 +518,7 @@
}
// tex =
}
- //glDisable(GL_LIGHTING);
+ // glDisable(GL_LIGHTING);
// glEnable( GL_NORMALIZE );
// variables for timing:
unsigned int frames = 0;
@@ -569,7 +556,7 @@
glPushMatrix(); // Pushing on the LookAt Matrix.
vec3 right = normalizev3(crossv3(camforw, camup));
- //right.d[1] = 0;
+ // 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])
@@ -586,18 +573,20 @@
glBindTexture(GL_TEXTURE_2D, tex);
// glDisable(GL_BLEND);
// Testing blending for textured triangles.
- //glDisable(GL_DEPTH_TEST);
- if(doblend){
+ // glDisable(GL_DEPTH_TEST);
+ if (doblend) {
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
- }else {glDisable(GL_BLEND);}
+ } else {
+ glDisable(GL_BLEND);
+ }
glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR);
glBlendEquation(GL_FUNC_ADD);
// glDisable(GL_TEXTURE_2D);
// printf("\nNew triangle!\n");
if (!dlExists) {
- if(!testingModelArrays){
+ if (!testingModelArrays) {
glDisable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
// glColor3f(0,0,1);
@@ -617,18 +606,18 @@
glEnable(GL_TEXTURE_2D);
// glDisable(GL_TEXTURE_2D);
glEnable(GL_POLYGON_STIPPLE);
- //puts("\nUSING ARRAYS!");
+ // puts("\nUSING ARRAYS!");
// glDisable(GL_COLOR_MATERIAL);
for (unsigned int i = 0; i < count; i++) {
glPushMatrix();
- mat4 horiz_translation = translate((vec3){{8.0 * (i%10),0.0,0.0}});
- mat4 vert_translation = translate((vec3){{0.0,8.0 * (i/10),0.0}});
- const mat4 ztranslation = translate((vec3){{0,0,-10}});
- mat4 total_translation = multm4(multm4(horiz_translation, vert_translation),ztranslation);
+ mat4 horiz_translation = translate((vec3){{8.0 * (i % 10), 0.0, 0.0}});
+ mat4 vert_translation = translate((vec3){{0.0, 8.0 * (i / 10), 0.0}});
+ const mat4 ztranslation = translate((vec3){{0, 0, -10}});
+ mat4 total_translation = multm4(multm4(horiz_translation, vert_translation), ztranslation);
glMultMatrixf(total_translation.d);
- //glTranslatef((float)(i % 10) * 8.0, (float)(i / 10) * 8.0, -10);
+ // glTranslatef((float)(i % 10) * 8.0, (float)(i / 10) * 8.0, -10);
glBegin(GL_TRIANGLES);
- for(uint j = 0; j < ModelArray.npoints; j++)
+ for (uint j = 0; j < ModelArray.npoints; j++)
glArrayElement(j);
glEnd();
glPopMatrix();
@@ -644,12 +633,12 @@
// glDisable(GL_COLOR_MATERIAL);
for (unsigned int i = 0; i < count; i++) {
glPushMatrix();
- mat4 horiz_translation = translate((vec3){{8.0 * (i%10),0.0,0.0}});
- mat4 vert_translation = translate((vec3){{0.0,8.0 * (i/10),0.0}});
- const mat4 ztranslation = translate((vec3){{0,0,-10}});
- mat4 total_translation = multm4(multm4(horiz_translation, vert_translation),ztranslation);
+ mat4 horiz_translation = translate((vec3){{8.0 * (i % 10), 0.0, 0.0}});
+ mat4 vert_translation = translate((vec3){{0.0, 8.0 * (i / 10), 0.0}});
+ const mat4 ztranslation = translate((vec3){{0, 0, -10}});
+ mat4 total_translation = multm4(multm4(horiz_translation, vert_translation), ztranslation);
glMultMatrixf(total_translation.d);
- //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,
@@ -675,18 +664,16 @@
fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
return 1;
}
- if(testingCopyImage2D && doTextures){
+ if (testingCopyImage2D && doTextures) {
glBindTexture(GL_TEXTURE_2D, tex);
glReadBuffer(GL_FRONT);
- glCopyTexImage2D(
- GL_TEXTURE_2D, //1
- 0,//2
- GL_RGBA, //3
- 0,//4
- 256,//5
- 256,//6
- 256,
- 0);
+ glCopyTexImage2D(GL_TEXTURE_2D, // 1
+ 0, // 2
+ GL_RGBA, // 3
+ 0, // 4
+ 256, // 5
+ 256, // 6
+ 256, 0);
}
/*
printf("\nRMASK IS %u",screen->format->Rmask);
@@ -729,7 +716,8 @@
// cleanup:
glDeleteTextures(1, &tex);
// glDeleteList(modelDisplayList);
- if(dlExists) glDeleteLists(modelDisplayList, 1);
+ if (dlExists)
+ glDeleteLists(modelDisplayList, 1);
FreeModelArray();
ZB_close(frameBuffer);
glClose();
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -1,7 +1,7 @@
/* texture.c */
/*
* Texture test written by Gek
- *
+ *
*/
//#define PLAY_MUSIC
@@ -56,7 +56,7 @@
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);
- if(!do1D)
+ if (!do1D)
glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
else
glTexImage1D(GL_TEXTURE_1D, 0, 3, w, 0, GL_RGB, GL_UNSIGNED_BYTE, buf + Row1D * w * 3);
@@ -63,13 +63,13 @@
return t;
}
-GLuint postProcessingStep(GLint x, GLint y, GLuint pixel, GLushort z){
+GLuint postProcessingStep(GLint x, GLint y, GLuint pixel, GLushort z) {
#if TGL_FEATURE_RENDER_BITS == 32
-//32 bit pixel
- return pixel & 0x8F8F8F; //Half color mode.
+ // 32 bit pixel
+ return pixel & 0x8F8F8F; // Half color mode.
#else
-//16 bit mode
- return pixel & (63<<5); //Solid green
+ // 16 bit mode
+ return pixel & (63 << 5); // Solid green
#endif
}
@@ -78,9 +78,9 @@
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
-
- if(dorect)
- glColor3f(1.0,1.0,1.0);
+
+ if (dorect)
+ glColor3f(1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
// TRIANGLE 1,
glTexCoord2f(0, 0);
@@ -89,7 +89,7 @@
glTexCoord2f(1 * texture_mult, -1 * texture_mult);
glVertex3f(1, 1, 0.5);
- glTexCoord2f(0, -1* texture_mult);
+ glTexCoord2f(0, -1 * texture_mult);
glVertex3f(-1, 1, 0.5);
// TRIANGLE 2
glTexCoord2f(0, 0);
@@ -101,27 +101,23 @@
glTexCoord2f(1 * texture_mult, -1 * texture_mult);
glVertex3f(1, 1, 0.5);
glEnd();
- if(dorect)
- {
- //glDisable(GL_DEPTH_TEST);glDepthMask(GL_FALSE);
- glDisable(GL_TEXTURE_2D);
- glColor3f(1.0,0,0);
- glRectf(0, 0, 1, 1);
- //glEnable(GL_DEPTH_TEST);glDepthMask(GL_TRUE);
- }
- if(doPostProcess) glPostProcess(postProcessingStep); //do a post processing step on the rendered geometry.
+ if (dorect) {
+ // glDisable(GL_DEPTH_TEST);glDepthMask(GL_FALSE);
+ glDisable(GL_TEXTURE_2D);
+ glColor3f(1.0, 0, 0);
+ glRectf(0, 0, 1, 1);
+ // glEnable(GL_DEPTH_TEST);glDepthMask(GL_TRUE);
+ }
+ if (doPostProcess)
+ glPostProcess(postProcessingStep); // do a post processing step on the rendered geometry.
}
-
-
void initScene() {
-
-
glEnable(GL_CULL_FACE);
// glDisable( GL_CULL_FACE );
glDisable(GL_BLEND);
- //glEnable(GL_LIGHTING);
+ // glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
// glEnable( GL_LIGHT0 );
@@ -172,7 +168,7 @@
fps = strtoull(argv[i], 0, 10);
if (!strcmp(larg, "-texscale"))
texture_mult = atof(argv[i]);
- if (!strcmp(larg, "-1D")){
+ if (!strcmp(larg, "-1D")) {
do1D = 1;
Row1D = atoi(argv[i]);
}
@@ -212,7 +208,7 @@
printf("\nBSHIFT IS %u", screen->format->Bshift);
printf("\nASHIFT IS %u\n", screen->format->Ashift);
fflush(stdout);
-
+
#ifdef PLAY_MUSIC
track* myTrack = NULL;
myTrack = lmus("WWGW.mp3");
@@ -223,7 +219,6 @@
// initialize TinyGL:
-
switch (screen->format->BitsPerPixel) {
case 16:
@@ -238,10 +233,10 @@
break;
}
ZBuffer* frameBuffer = NULL;
- if(TGL_FEATURE_RENDER_BITS == 32)
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
+ if (TGL_FEATURE_RENDER_BITS == 32)
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_RGBA, 0);
else
- frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
+ frameBuffer = ZB_open(winSizeX, winSizeY, ZB_MODE_5R6G5B, 0);
glInit(frameBuffer);
// initialize GL:
@@ -289,22 +284,20 @@
}
// draw scene:
-
+
draw();
glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x000000FF);
- glPixelZoom(2.0,0.7);
- glRasterPos3f(0,-1,fabs(sinf(frames_notreset/200.0)));
+ glPixelZoom(2.0, 0.7);
+ glRasterPos3f(0, -1, fabs(sinf(frames_notreset / 200.0)));
{
GLint xsize, ysize;
- void* data = glGetTexturePixmap(tex2, 0, &xsize, &ysize);
- //for(int i = 0; i < winSizeX; i++)
- //for(int j = 0; j < winSizeY; j++){
- //glPlotPixel(i,j,rand() & 0xFFFFFF);
+ void* data = glGetTexturePixmap(tex2, 0, &xsize, &ysize);
+ // for(int i = 0; i < winSizeX; i++)
+ // for(int j = 0; j < winSizeY; j++){
+ // glPlotPixel(i,j,rand() & 0xFFFFFF);
//}
- if(data)
- glDrawPixels(xsize,ysize, GL_RGB,
- (TGL_FEATURE_RENDER_BITS==32)?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT, data
- );
+ if (data)
+ glDrawPixels(xsize, ysize, GL_RGB, (TGL_FEATURE_RENDER_BITS == 32) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, data);
}
// swap buffers:
if (SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen) < 0)) {
--- a/include-demo/stringutil.h
+++ b/include-demo/stringutil.h
@@ -22,6 +22,14 @@
#define strcataf2 strcatallocf2
#define strcatafb strcatallocfb
#endif
+
+#ifndef LOOP
+
+//Loop without errors!
+#define LOOP(v, e)\
+for(unsigned long long v = 0, __internal_##v = 0; __internal_##v < e; __internal_##v++, v = __internal_##v)
+
+#endif
//Strcat but with malloc.
static inline char* strcatalloc(const char* s1, const char* s2){
char* d = NULL; d = STRUTIL_ALLOC(strlen(s1) + strlen(s2) + 1);