From 8bcec054ceb9df76ad396606c7ab7753fe52a28a Mon Sep 17 00:00:00 2001 From: Lewnidas Asthenides Date: Tue, 16 Mar 2021 20:18:42 +0200 Subject: [PATCH] Fix sf::Clock issue on win32 on gl_mandel.cpp --- .gitignore | 5 ++++- gl_mandel.cpp | 44 +++++++++++++++++++++++++++++++++++++------- newton_software.cpp | 4 ++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 04a78ec..4506e4c 100755 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ *.ttf *.o *.key -*.crt \ No newline at end of file +*.crt +/windows +*.exe +*.dll \ No newline at end of file diff --git a/gl_mandel.cpp b/gl_mandel.cpp index 4a6b688..eb411d3 100644 --- a/gl_mandel.cpp +++ b/gl_mandel.cpp @@ -61,7 +61,6 @@ GLuint compileShader(GLuint type, std::string& src) return s_id; } - GLuint createProgram(std::string vertexShader, std::string fragmentShader) { GLuint program = glCreateProgram(); @@ -173,6 +172,7 @@ class c_map { speed.move = 100.0f; } + template sf::Vector2f toCartesian(sf::Vector2 pixel_pos) { float centerX = mid.x - offset.x; @@ -227,6 +227,7 @@ void initMap() { oper[sf::Keyboard::S] = [](sf::Clock clock) {world.offset.y += world.speed.move * clock.getElapsedTime().asSeconds(); }; oper[sf::Keyboard::LShift] = [](sf::Clock clock) { + // std::cout << clock.getElapsedTime().asSeconds() << "\n"; world.ZoomIntoPoint(cur ? world.mpos : sf::Vector2i(world.mid.x, world.mid.y), world.speed.zoom * clock.getElapsedTime().asSeconds()); }; @@ -311,6 +312,8 @@ void main() { int iter = 0; const int max_iter = 50; + + for (int i=0; i < max_iter; i++) { a_2 = _z.real * _z.real; b_2 = _z.imag * _z.imag; @@ -328,8 +331,6 @@ void main() { iter = i; break; } - - } float value = float(iter) / float(max_iter); @@ -371,6 +372,12 @@ void main() { FragColor = vec4(sin(smooth_3), sin(smooth_), cos(smooth_2), 1.0); break; } + case 6: { + float smooth_ = float(iter) + 1.0 - log(abs(sqrt(a_2 + b_2))) / log(2.0); + vec3 val = 0.5 + 0.5*cos( 3.0 + smooth_*0.15 + vec3(0.0, 0.6, 1.0)); + FragColor = vec4( 1.0 * sin(float(iter)) * val, 1); + break; + } } } )glsl"; @@ -422,6 +429,22 @@ void updateUniforms() { glUniform1i(algLocation, ALGO); } +typedef unsigned int uint; + +/* + +# Windows (x86 and x86_64) +function crun($file) { + $file_=python -c "print('${file}'.rsplit('.', 1)[0])" + g++ -c -O3 "${file_}.cpp" -I C:\Users\progr\Downloads\glew-2.1.0-win32\glew-2.1.0\include -I C:\Users\progr\Downloads\SFML-2.5.1-windows-vc15-32-bit\SFML-2.5.1\include + g++ "${file_}.o" -o "${file_}.exe" -L C:\Users\progr\Downloads\glew-2.1.0\glew-2.1.0\lib -L C:\Users\progr\Downloads\SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit\SFML-2.5.1\lib -lsfml-graphics -lsfml-window -lsfml-system -lglew32 -lopengl32 + $exec="${file_}.exe" + & $exec +} + +*/ + + void parseArgv(int argc, char* argv[]) { std::map setts = { @@ -501,8 +524,11 @@ int main(int argc, char* argv[]) { sf::Vector2u initial_pos; bool isFullScreen = false; + GAME_CLOCK.restart(); FPS_CLOCK.restart(); + + while (running) { while (window.pollEvent(event)) { @@ -534,6 +560,9 @@ int main(int argc, char* argv[]) { case sf::Keyboard::Num6: ALGO = 5; break; + case sf::Keyboard::Num7: + ALGO = 6; + break; case sf::Keyboard::Enter: { world.init(world.res.x, world.res.y); world.rotation = 0; @@ -576,7 +605,6 @@ int main(int argc, char* argv[]) { } } - glUseProgram(program); glBindVertexArray(VAO); // this line is new @@ -585,7 +613,7 @@ int main(int argc, char* argv[]) { glDrawArrays(GL_TRIANGLES, 0, 2 * TRIANGLE_VERTICES); world.mpos = sf::Mouse::getPosition(window); - orbitControl(GAME_CLOCK); + gltSetText(ZOOM_TEXT, to_scientic(world.zoom).c_str() ); @@ -606,11 +634,13 @@ int main(int argc, char* argv[]) { } } - + + orbitControl(GAME_CLOCK); frames++; + // Note: On Windows Sf::Clock().restart() must be before window.display(); + GAME_CLOCK.restart(); window.display(); - GAME_CLOCK.restart(); } END: NULL; diff --git a/newton_software.cpp b/newton_software.cpp index 761621a..ef066ba 100644 --- a/newton_software.cpp +++ b/newton_software.cpp @@ -13,6 +13,10 @@ function run2 { */ +// sys/types.h +typedef unsigned int uint; +typedef unsigned char u_char; + #include #include #define WIDTH 800