Fix: Small fix for dependencies

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-11-05 23:17:48 +00:00
parent d92557ebda
commit 47e9700a4a
5 changed files with 231 additions and 137 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
WEATHER_API_KEY=b5337f9628db3b0949f914f3864834b4
LOCAL=Lisbond

20
imgui.ini Normal file
View File

@ -0,0 +1,20 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
[Window][API Key Status]
Pos=60,60
Size=201,51
[Window][Status]
Pos=24,27
Size=234,142
[Window][Debug Window]
Pos=23,27
Size=370,226
[Window][Weather Data]
Pos=30,266
Size=862,225

54
include/http_get.c Normal file
View File

@ -0,0 +1,54 @@
#include "http_get.h"
// Callback for libcurl to write response into our struct
static size_t write_callback(void *data, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct Memory *mem = (struct Memory *)userp;
char *ptr = realloc(mem->response, mem->size + realsize + 1);
if(ptr == NULL) {
// Out of memory!
fprintf(stderr, "realloc() failed\n");
return 0;
}
mem->response = ptr;
memcpy(&(mem->response[mem->size]), data, realsize);
mem->size += realsize;
mem->response[mem->size] = '\0';
return realsize;
}
// Function: GET request, returns heap string (caller must free)
char *http_get(const char *url) {
CURL *curl;
CURLcode res;
struct Memory chunk;
chunk.response = malloc(1); // start with empty buffer
chunk.size = 0;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // follow redirects
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
free(chunk.response);
chunk.response = NULL;
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return chunk.response;
}

29
include/http_get.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef HTTP_GET_H
#define HTTP_GET_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#ifdef __cplusplus
extern "C" {
#endif
// Struct to hold response data
struct Memory {
char *response;
size_t size;
};
// Callback for libcurl to write response into our struct
static size_t write_callback(void *data, size_t size, size_t nmemb, void *userp);
// Function: GET request, returns heap string (caller must free)
char *http_get(const char *url);
#ifdef __cplusplus
}
#endif
#endif // HTTP_GET_H

View File

@ -1,12 +1,12 @@
#include <iostream>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
// glad and GLFW
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glad/glad.h>
// glm math
#include <glm/glm.hpp>
@ -25,7 +25,8 @@ const float SCR_HEIGHT = 1200.0f;
int main(void) {
// Initialize GLFW
if (!glfwInit()) return -1;
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
@ -56,18 +57,10 @@ int main(void) {
// ----- Vertex Data -----
// Cube
// Positions
float vertices[] = {
// positions
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f
};
float vertices[] = {// positions
-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f};
unsigned int indices[] = {
0, 1, 2,
2, 3, 0
};
unsigned int indices[] = {0, 1, 2, 2, 3, 0};
GLuint VAO, VBO, EBO;
glGenVertexArrays(1, &VAO);
@ -116,7 +109,6 @@ int main(void) {
glUniformMatrix4fv((int)viewLoc, 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv((int)projLoc, 1, GL_FALSE, glm::value_ptr(projection));
GLint resLoc = glGetUniformLocation(shaderProgram, "u_resolution");
glUniform2f(resLoc, SCR_WIDTH, SCR_HEIGHT); // hardcode for now
@ -150,12 +142,14 @@ int main(void) {
// Scroll to zoom in/out
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) {
scale += 0.01f;
if (scale > 10.0f) scale = 10.0f; // Max zoom
if (scale > 10.0f)
scale = 10.0f; // Max zoom
}
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
scale -= 0.01f;
if (scale < 0.1f) scale = 0.1f; // Min zoom
if (scale < 0.1f)
scale = 0.1f; // Min zoom
}
// --- FPS Counter ---
@ -164,11 +158,7 @@ int main(void) {
if (delta >= 1.0) { // print every ~1 second
fps = double(frameCount) / delta;
std::cout << "FPS: " << fps
<< " Time: " << timeValue
<< " Scale: " << scale
<< " Mouse: (" << mousePos[0] << ", " << mousePos[1] << ")"
<< std::endl;
std::cout << "FPS: " << fps << " Time: " << timeValue << " Scale: " << scale << " Mouse: (" << mousePos[0] << ", " << mousePos[1] << ")" << std::endl;
frameCount = 0;
lastTime = currentTime;
@ -199,4 +189,3 @@ int main(void) {
glfwTerminate();
return 0;
}