Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

Igor Morgado igormorgado

🙃
View GitHub Profile
View gamecontroller_powerlevel.c
#include <SDL2/SDL.h>
int main(void) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
SDL_Window *window = SDL_CreateWindow("Controllers", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_bool is_running = SDL_TRUE;
SDL_GameController *ctrl;
View check_gamecontroller.c
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
/*
*
* STRUCTS, Enums and Typedefs
*
*/
View joystick_testid.c
#include <SDL2/SDL.h>
void list_joysticks();
int main(void) {
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
int sdl_flags = SDL_INIT_JOYSTICK;
int is_running = 1;
SDL_Init(sdl_flags);
View dump_texture_to_file2.c
int dump_texture_to_file(SDL_Renderer *renderer, SDL_Texture *texture, const char *filename)
{
SDL_Log("%s: ENTERING\n", __func__);
Uint32 format = 0;
int access = 0;
int width = 0;
int height = 0;
int retval = 0;
View dump_texture_to_file.c
void dump_texture_to_file(SDL_Renderer *renderer, SDL_Texture *texture, const char *filename)
{
SDL_Log("%s: ENTERING\n", __func__);
Uint32 format;
int access;
int width;
int height;
SDL_QueryTexture(texture, &format, &access, &width, &height);
View mouseevents.c
#include <SDL2/SDL.h>
int main(void) {
SDL_bool quit = SDL_FALSE;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("Mouse events", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 127, 127, 127, 255);
SDL_RenderClear(renderer);
SDL_Event event;
View cache_friendly.c
#include <stdint.h>
#include <glib.h>
#include <gmodule.h>
struct entity {
int32_t value; // 4 bytes
char name[12]; // 12 bytes
};
View gist:8c492021ae6b15c5979015ea0afb9bf3
#include <glib.h>
#include <glib/gi18n.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
typedef int32_t i32;
// A sample object data
struct data
View test.ui
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="open_recent_menu">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<object class="GtkMenu" id="options_menu">
<property name="visible">True</property>
@igormorgado
igormorgado / A_readme
Last active Oct 16, 2019
Simple GObject usage.
View A_readme
How to use G_DECLARE_DERIVATIVE_TYPE and/or G_DECLARE_FINAL_TYPE in this code to reduce the "boilerplate code"?
Right now, errors building the code:
pet-dog.c: In function ‘pet_dog_print’:
pet-dog.c:17:36: error: invalid type argument of ‘->’ (have ‘PetBaseClass’ {aka ‘struct _PetBaseClass’})
PET_DOG_GET_CLASS(self)->parent->print(self);
^~
pet-dog.c: In function ‘pet_dog_class_init’:
pet-dog.c:86:27: warning: assignment to ‘void (*)(PetBase *)’ {aka ‘void (*)(struct _PetBase *)’} from incompatible pointer type ‘void (*)(PetDog *)’ {aka ‘void (*)(struct _PetDog *)’} [-Wincompatible-pointer-types]