Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Nov 18, 2024
1 parent a5ba019 commit 1394e47
Show file tree
Hide file tree
Showing 62 changed files with 1,310 additions and 375 deletions.
1 change: 1 addition & 0 deletions glfw/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ video tutorials.
- Jonas Ådahl
- Lasse Öörni
- Leonard König
- Grzesiek11
- All the unmentioned and anonymous contributors in the GLFW community, for bug
reports, patches, feedback, testing and encouragement

4 changes: 4 additions & 0 deletions glfw/deps/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef BUILD_MONOLITHIC

#include "getopt.h"

#include <stddef.h>
Expand Down Expand Up @@ -228,3 +230,5 @@ int getopt_long(int argc, char* const argv[], const char* optstring,
++optind;
return retval;
}

#endif // BUILD_MONOLITHIC
6 changes: 6 additions & 0 deletions glfw/deps/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#ifndef INCLUDED_GETOPT_PORT_H
#define INCLUDED_GETOPT_PORT_H


#ifdef BUILD_MONOLITHIC
#error "Error: make sure to point an include search path to the libgetopt library BEFORE including the glfw/deps/ search path, for otherwise you'll include the DISABLED alternative getopt implementation in glfw/depts/ !"
#endif


#if defined(__cplusplus)
extern "C" {
#endif
Expand Down
4 changes: 2 additions & 2 deletions glfw/deps/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -5682,7 +5682,7 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {

#endif /* NK_NUKLEAR_H_ */

#ifdef NK_IMPLEMENTATION
//#ifdef NK_IMPLEMENTATION

#ifndef NK_INTERNAL_H
#define NK_INTERNAL_H
Expand Down Expand Up @@ -6018,7 +6018,7 @@ NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_prop




#ifdef NK_IMPLEMENTATION

/* ===============================================================
*
Expand Down
91 changes: 50 additions & 41 deletions glfw/examples/boing.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@

#if defined(_MSC_VER)
// Make MS math.h define M_PI
#define _USE_MATH_DEFINES
#if !defined(_USE_MATH_DEFINES)
#define _USE_MATH_DEFINES
#endif
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifndef BUILD_MONOLITHIC
#define GLAD_GL_IMPLEMENTATION
#endif
#include <glad/gl.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
Expand All @@ -49,16 +53,16 @@
*****************************************************************************/

/* Prototypes */
void init( void );
void display( void );
void reshape( GLFWwindow* window, int w, int h );
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods );
void mouse_button_callback( GLFWwindow* window, int button, int action, int mods );
void cursor_position_callback( GLFWwindow* window, double x, double y );
void DrawBoingBall( void );
void BounceBall( double dt );
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
void DrawGrid( void );
static void init( void );
static void display( void );
static void reshape( GLFWwindow* window, int w, int h );
static void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods );
static void mouse_button_callback( GLFWwindow* window, int button, int action, int mods );
static void cursor_position_callback( GLFWwindow* window, double x, double y );
static void DrawBoingBall( void );
static void BounceBall( double dt );
static void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
static void DrawGrid( void );

#define RADIUS 70.f
#define STEP_LONGITUDE 22.5f /* 22.5 makes 8 bands like original Boing */
Expand Down Expand Up @@ -91,21 +95,21 @@ typedef enum { DRAW_BALL, DRAW_BALL_SHADOW } DRAW_BALL_ENUM;
typedef struct {float x; float y; float z;} vertex_t;

/* Global vars */
int windowed_xpos, windowed_ypos, windowed_width, windowed_height;
int width, height;
GLfloat deg_rot_y = 0.f;
GLfloat deg_rot_y_inc = 2.f;
int override_pos = GLFW_FALSE;
GLfloat cursor_x = 0.f;
GLfloat cursor_y = 0.f;
GLfloat ball_x = -RADIUS;
GLfloat ball_y = -RADIUS;
GLfloat ball_x_inc = 1.f;
GLfloat ball_y_inc = 2.f;
DRAW_BALL_ENUM drawBallHow;
double t;
double t_old = 0.f;
double dt;
static int windowed_xpos, windowed_ypos, windowed_width, windowed_height;
static int width, height;
static GLfloat deg_rot_y = 0.f;
static GLfloat deg_rot_y_inc = 2.f;
static int override_pos = GLFW_FALSE;
static GLfloat cursor_x = 0.f;
static GLfloat cursor_y = 0.f;
static GLfloat ball_x = -RADIUS;
static GLfloat ball_y = -RADIUS;
static GLfloat ball_x_inc = 1.f;
static GLfloat ball_y_inc = 2.f;
static DRAW_BALL_ENUM drawBallHow;
static double t;
static double t_old = 0.f;
static double dt;

/* Random number generator */
#ifndef RAND_MAX
Expand All @@ -116,7 +120,7 @@ double dt;
/*****************************************************************************
* Truncate a degree.
*****************************************************************************/
GLfloat TruncateDeg( GLfloat deg )
static GLfloat TruncateDeg( GLfloat deg )
{
if ( deg >= 360.f )
return (deg - 360.f);
Expand All @@ -128,23 +132,23 @@ GLfloat TruncateDeg( GLfloat deg )
* Convert a degree (360-based) into a radian.
* 360' = 2 * PI
*****************************************************************************/
double deg2rad( double deg )
static double deg2rad( double deg )
{
return deg / 360 * (2 * M_PI);
}

/*****************************************************************************
* 360' sin().
*****************************************************************************/
double sin_deg( double deg )
static double sin_deg( double deg )
{
return sin( deg2rad( deg ) );
}

/*****************************************************************************
* 360' cos().
*****************************************************************************/
double cos_deg( double deg )
static double cos_deg( double deg )
{
return cos( deg2rad( deg ) );
}
Expand All @@ -154,7 +158,7 @@ double cos_deg( double deg )
*
* c = a x b
*****************************************************************************/
void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
static void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
{
GLfloat u1, u2, u3;
GLfloat v1, v2, v3;
Expand All @@ -179,7 +183,7 @@ void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
/*****************************************************************************
* init()
*****************************************************************************/
void init( void )
static void init( void )
{
/*
* Clear background.
Expand All @@ -193,7 +197,7 @@ void init( void )
/*****************************************************************************
* display()
*****************************************************************************/
void display(void)
static void display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
Expand All @@ -214,7 +218,7 @@ void display(void)
/*****************************************************************************
* reshape()
*****************************************************************************/
void reshape( GLFWwindow* window, int w, int h )
static void reshape( GLFWwindow* window, int w, int h )
{
mat4x4 projection, view;

Expand All @@ -237,7 +241,7 @@ void reshape( GLFWwindow* window, int w, int h )
glLoadMatrixf((const GLfloat*) view);
}

void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods )
static void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods )
{
if (action != GLFW_PRESS)
return;
Expand Down Expand Up @@ -273,7 +277,7 @@ static void set_ball_pos ( GLfloat x, GLfloat y )
ball_y = y - (height / 2);
}

void mouse_button_callback( GLFWwindow* window, int button, int action, int mods )
static void mouse_button_callback( GLFWwindow* window, int button, int action, int mods )
{
if (button != GLFW_MOUSE_BUTTON_LEFT)
return;
Expand All @@ -289,7 +293,7 @@ void mouse_button_callback( GLFWwindow* window, int button, int action, int mods
}
}

void cursor_position_callback( GLFWwindow* window, double x, double y )
static void cursor_position_callback( GLFWwindow* window, double x, double y )
{
cursor_x = (float) x;
cursor_y = (float) y;
Expand All @@ -306,7 +310,7 @@ void cursor_position_callback( GLFWwindow* window, double x, double y )
* The ball is built by stacking latitudinal circles. Each circle is composed
* of a widely-separated set of points, so that each facet is noticeably large.
*****************************************************************************/
void DrawBoingBall( void )
static void DrawBoingBall( void )
{
GLfloat lon_deg; /* degree of longitude */
double dt_total, dt2;
Expand Down Expand Up @@ -383,7 +387,7 @@ void DrawBoingBall( void )
/*****************************************************************************
* Bounce the ball.
*****************************************************************************/
void BounceBall( double delta_t )
static void BounceBall( double delta_t )
{
GLfloat sign;
GLfloat deg;
Expand Down Expand Up @@ -436,7 +440,7 @@ void BounceBall( double delta_t )
* Parms: long_lo, long_hi
* Low and high longitudes of slice, resp.
*****************************************************************************/
void DrawBoingBallBand( GLfloat long_lo,
static void DrawBoingBallBand( GLfloat long_lo,
GLfloat long_hi )
{
vertex_t vert_ne; /* "ne" means south-east, so on */
Expand Down Expand Up @@ -540,7 +544,7 @@ void DrawBoingBallBand( GLfloat long_lo,
* Draw the purple grid of lines, behind the Boing ball.
* When the Workbench is dropped to the bottom, Boing shows 12 rows.
*****************************************************************************/
void DrawGrid( void )
static void DrawGrid( void )
{
int row, col;
const int rowTotal = 12; /* must be divisible by 2 */
Expand Down Expand Up @@ -621,6 +625,11 @@ void DrawGrid( void )
* main()
*======================================================================*/


#ifdef BUILD_MONOLITHIC
#define main glfw_boing_example_main
#endif

int main( void )
{
GLFWwindow* window;
Expand Down
17 changes: 12 additions & 5 deletions glfw/examples/gears.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@

#if defined(_MSC_VER)
// Make MS math.h define M_PI
#define _USE_MATH_DEFINES
#if !defined(_USE_MATH_DEFINES)
#define _USE_MATH_DEFINES
#endif
#endif

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifndef BUILD_MONOLITHIC
#define GLAD_GL_IMPLEMENTATION
#endif
#include <glad/gl.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
Expand Down Expand Up @@ -163,7 +167,6 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glVertex3f(r0 * (float) cos(angle), r0 * (float) sin(angle), width * 0.5f);
}
glEnd();

}


Expand Down Expand Up @@ -212,7 +215,7 @@ static void animate(void)


/* change view angle, exit upon ESC */
void key( GLFWwindow* window, int k, int s, int action, int mods )
static void key( GLFWwindow* window, int k, int s, int action, int mods )
{
if( action != GLFW_PRESS ) return;

Expand Down Expand Up @@ -245,7 +248,7 @@ void key( GLFWwindow* window, int k, int s, int action, int mods )


/* new window size */
void reshape( GLFWwindow* window, int width, int height )
static void reshape( GLFWwindow* window, int width, int height )
{
GLfloat h = (GLfloat) height / (GLfloat) width;
GLfloat xmax, znear, zfar;
Expand Down Expand Up @@ -301,8 +304,12 @@ static void init(void)
}


#ifdef BUILD_MONOLITHIC
#define main glfw_gears_example_main
#endif

/* program entry */
int main(int argc, char *argv[])
int main(int argc, const char **argv)
{
GLFWwindow* window;
int width, height;
Expand Down
9 changes: 8 additions & 1 deletion glfw/examples/heightmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include <assert.h>
#include <stddef.h>

#ifndef BUILD_MONOLITHIC
#define GLAD_GL_IMPLEMENTATION
#endif
#include <glad/gl.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
Expand Down Expand Up @@ -398,7 +400,12 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}

int main(int argc, char** argv)

#ifdef BUILD_MONOLITHIC
#define main glfw_heightmap_example_main
#endif

int main(int argc, const char** argv)
{
GLFWwindow* window;
int iter;
Expand Down
Loading

0 comments on commit 1394e47

Please sign in to comment.