From 9984353e26a8dc83292f4318d3b75844b411bb14 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 13 May 2021 16:48:47 +0200 Subject: [PATCH] Ensure code examples are autoformatted --- .github/workflows/deploy-docs.yml | 2 +- docs/api/audio.md | 12 +++++------ docs/api/graphics.md | 14 ++++++------- docs/requirements.txt | 1 + docs/tutorials/audio/recording.md | 14 ++++++------- docs/tutorials/audio/sounds.md | 5 ++--- docs/tutorials/audio/streams.md | 6 +++--- docs/tutorials/graphics/draw.md | 2 +- docs/tutorials/graphics/shader.md | 7 +++---- docs/tutorials/graphics/shape.md | 6 ++++-- docs/tutorials/graphics/sprite.md | 11 +++++----- docs/tutorials/graphics/text.md | 3 +-- docs/tutorials/graphics/transform.md | 8 +++---- docs/tutorials/graphics/vertex-array.md | 28 ++++++++++++------------- docs/tutorials/graphics/view.md | 4 ++-- docs/tutorials/network/ftp.md | 6 +++--- docs/tutorials/network/packet.md | 2 +- docs/tutorials/system/stream.md | 4 ++-- docs/tutorials/system/thread.md | 16 +++++++------- docs/tutorials/system/time.md | 6 +++--- docs/tutorials/window/events.md | 14 +++++-------- docs/tutorials/window/inputs.md | 2 +- docs/tutorials/window/opengl.md | 26 +++++++++++------------ docs/tutorials/window/window.md | 4 ++-- mkdocs.yml | 12 +++++++++++ 25 files changed, 111 insertions(+), 104 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index c03b8039..14c6f9e8 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -18,7 +18,7 @@ jobs: - name: Install dependencies run: pip install -r docs/requirements.txt - name: Build site - run: mkdocs build + run: LINT=1 mkdocs build - name: Deploy to gh-pages if: github.event_name == 'push' && github.ref == 'refs/heads/master' uses: oprypin/push-to-gh-pages@v3 diff --git a/docs/api/audio.md b/docs/api/audio.md index 5f60f650..cd0ceb3e 100644 --- a/docs/api/audio.md +++ b/docs/api/audio.md @@ -862,7 +862,7 @@ if SF::SoundBufferRecorder.available? # Record some audio data recorder = SF::SoundBufferRecorder.new recorder.start() - ... + [...] recorder.stop() # Get the buffer containing the captured audio data @@ -1020,7 +1020,7 @@ class CustomRecorder < SF::SoundRecorder def on_start() # optional # Initialize whatever has to be done before the capture starts - ... + [...] # Return true to start playing true @@ -1028,7 +1028,7 @@ class CustomRecorder < SF::SoundRecorder def on_process_samples(samples) # Do something with the new chunk of samples (store them, send them, ...) - ... + [...] # Return true to continue playing true @@ -1036,7 +1036,7 @@ class CustomRecorder < SF::SoundRecorder def on_stop() # optional # Clean up whatever has to be done after the capture ends - ... + [...] end end @@ -1047,7 +1047,7 @@ if (CustomRecorder.isAvailable()) if (!recorder.start()) return -1 - ... + [...] recorder.stop() end ``` @@ -1486,7 +1486,7 @@ Usage example: class CustomStream < SF::SoundStream def initialize(location : String) # Open the source and get audio settings - ... + [...] # Initialize the stream -- important! super(channel_count, sample_rate) diff --git a/docs/api/graphics.md b/docs/api/graphics.md index a8afa7a2..9a5c5623 100644 --- a/docs/api/graphics.md +++ b/docs/api/graphics.md @@ -203,7 +203,7 @@ circle.radius = 150 circle.outline_color = SF::Color::Red circle.outline_thickness = 5 circle.position = {10, 20} -... +[...] window.draw circle ``` @@ -580,7 +580,7 @@ polygon[2] = SF.vector2f(25, 5) polygon.outline_color = SF::Color::Red polygon.outline_thickness = 5 polygon.position = {10, 20} -... +[...] window.draw polygon ``` @@ -806,7 +806,7 @@ class MyDrawable # ... or draw with OpenGL directly glBegin(GL_QUADS) - ... + [...] glEnd() end @@ -1381,7 +1381,7 @@ rectangle.size = SF.vector2f(100, 50) rectangle.outline_color = SF::Color::Red rectangle.outline_thickness = 5 rectangle.position = {10, 20} -... +[...] window.draw rectangle ``` @@ -2301,16 +2301,16 @@ window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "SFML OpenGL") # Create a sprite and a text to display sprite = SF::Sprite.new text = SF::Text.new -... +[...] # Perform OpenGL initializations glMatrixMode(GL_PROJECTION) -... +[...] # Start the rendering loop while window.open? # Process events - ... + [...] # Draw a background sprite window.push_gl_states() diff --git a/docs/requirements.txt b/docs/requirements.txt index cb92793d..a0da534f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,3 +6,4 @@ git+https://github.com/oprypin/mkdocstrings-crystal@master git+https://github.com/oprypin/mkdocs-literate-nav@master git+https://github.com/oprypin/mkdocs-section-index@master git+https://github.com/oprypin/mkdocs-gen-files@master +git+https://github.com/oprypin/mkdocs-code-validator@master diff --git a/docs/tutorials/audio/recording.md b/docs/tutorials/audio/recording.md index 51a026aa..d83c5d16 100644 --- a/docs/tutorials/audio/recording.md +++ b/docs/tutorials/audio/recording.md @@ -12,7 +12,7 @@ This can be achieved with the very simple interface of the [SF::SoundBufferRecor # first check if an input audio device is available on the system if !SF::SoundBufferRecorder.available? # error: audio capture is not available on this system - ... + [...] end # create the recorder @@ -79,8 +79,8 @@ recorder = SF::SoundBufferRecorder.new # set the device unless recorder.device = input_device - # error: device selection failed - ... + # error: device selection failed + [...] end # use recorder as usual @@ -106,7 +106,7 @@ Here is the skeleton of a complete derived class: class MyRecorder < SF::SoundRecorder def on_start # optional # initialize whatever has to be done before the capture starts - ... + [...] # return true to start the capture, or false to cancel it true @@ -114,7 +114,7 @@ class MyRecorder < SF::SoundRecorder def on_process_samples(samples, sample_count) # do something useful with the new chunk of samples - ... + [...] # return true to continue the capture, or false to stop it true @@ -122,7 +122,7 @@ class MyRecorder < SF::SoundRecorder def on_stop # optional # clean up whatever has to be done after the capture is finished - ... + [...] end end ``` @@ -136,7 +136,7 @@ end recorder = MyRecorder.new recorder.start -... +[...] recorder.stop ``` diff --git a/docs/tutorials/audio/sounds.md b/docs/tutorials/audio/sounds.md index f728e513..d22fd2d0 100644 --- a/docs/tutorials/audio/sounds.md +++ b/docs/tutorials/audio/sounds.md @@ -36,7 +36,7 @@ Now that the audio data is loaded, we can play it with a [SF::Sound][] instance. ```crystal # load something into the sound buffer... -buffer = ... +buffer = [...] sound = SF::Sound.new(buffer) sound.play @@ -125,7 +125,7 @@ Remember that a music needs its source as long as it is played. A music file on ```crystal # we start with a music file in memory (imagine that we extracted it from a zip archive) -file_data = ... +file_data = [...] # we play it music = SF::Music.from_memory(file_data) @@ -136,4 +136,3 @@ file_data.clear # ERROR: the music was still streaming the contents of file_data! The behavior is now undefined ``` - diff --git a/docs/tutorials/audio/streams.md b/docs/tutorials/audio/streams.md index 8cdec2c3..dc140ce1 100644 --- a/docs/tutorials/audio/streams.md +++ b/docs/tutorials/audio/streams.md @@ -16,7 +16,7 @@ In order to define your own audio stream, you need to inherit from the [SF::Soun ```crystal class MyAudioStream < SF::SoundStream - def on_get_data() : Slice(Int16)? + def on_get_data : Slice(Int16)? end def on_seek(time_offset : Time) @@ -28,7 +28,7 @@ end ```crystal class MyAudioStream < SF::SoundStream - def get_data() + def get_data samples_array.to_slice end end @@ -82,7 +82,7 @@ class MyStream < SF::SoundStream super(buffer.channel_count, buffer.sample_rate) end - def on_get_data() + def on_get_data # number of samples to stream every time the function is called; # in a more robust implementation, it should be a fixed # amount of time rather than an arbitrary number of samples diff --git a/docs/tutorials/graphics/draw.md b/docs/tutorials/graphics/draw.md index 9cced882..19be0a19 100644 --- a/docs/tutorials/graphics/draw.md +++ b/docs/tutorials/graphics/draw.md @@ -117,7 +117,7 @@ thread.launch # the event/logic/whatever loop while window.open? - ... + [...] end ``` diff --git a/docs/tutorials/graphics/shader.md b/docs/tutorials/graphics/shader.md index c87d0715..061218b2 100644 --- a/docs/tutorials/graphics/shader.md +++ b/docs/tutorials/graphics/shader.md @@ -51,14 +51,14 @@ Shaders can also be loaded directly from strings, with the `from_memory` class m vertex_shader = " void main() { - ... + [...] } " fragment_shader = " void main() { - ... + [...] } " @@ -177,7 +177,7 @@ To activate a [SF::Shader][] for drawing (the equivalent of `glUseProgram`), you ```crystal shader = SF::Shader.new -... +[...] # bind the shader SF::Shader.bind(shader) @@ -187,4 +187,3 @@ SF::Shader.bind(shader) # bind no shader SF::Shader.bind(nil) ``` - diff --git a/docs/tutorials/graphics/shape.md b/docs/tutorials/graphics/shape.md index 0a5dd7ff..c2ae1f41 100644 --- a/docs/tutorials/graphics/shape.md +++ b/docs/tutorials/graphics/shape.md @@ -167,7 +167,7 @@ Line without thickness: ```crystal line = [ SF::Vertex.new(SF.vector2(10, 10)), - SF::Vertex.new(SF.vector2(150, 150)) + SF::Vertex.new(SF.vector2(150, 150)), ] window.draw(line, SF::Lines) @@ -200,14 +200,16 @@ class EllipseShape < SF::Shape def radius @radius end + def radius=(radius : SF::Vector2f) @radius = radius update end def point_count - 40 # fixed, but could be an attribute of the class if needed + 40 # fixed, but could be an attribute of the class if needed end + def get_point(index) angle = index * 2*Math::PI / point_count diff --git a/docs/tutorials/graphics/sprite.md b/docs/tutorials/graphics/sprite.md index d94264cb..343e5e01 100644 --- a/docs/tutorials/graphics/sprite.md +++ b/docs/tutorials/graphics/sprite.md @@ -109,7 +109,7 @@ sprite.texture_rect = SF.int_rect(10, 10, 32, 32) You can also change the color of a sprite. The color that you set is modulated (multiplied) with the texture of the sprite. This can also be used to change the global transparency (alpha) of the sprite. ```crystal -sprite.color = SF.color(0, 255, 0) # green +sprite.color = SF.color(0, 255, 0) # green sprite.color = SF.color(255, 255, 255, 128) # half transparent ``` @@ -122,15 +122,15 @@ Sprites can also be transformed: They have a position, an orientation and a scal ```crystal # position sprite.position = SF.vector2(10, 50) # absolute position -sprite.move(SF.vector2(5, 10)) # offset relative to the current position +sprite.move(SF.vector2(5, 10)) # offset relative to the current position # rotation sprite.rotation = 90 # absolute angle -sprite.rotate(15) # offset relative to the current angle +sprite.rotate(15) # offset relative to the current angle # scale sprite.scale = SF.vector2(0.5, 2.0) # absolute scale factor -sprite.scale(SF.vector2(1.5, 3.0)) # factor relative to the current scale +sprite.scale(SF.vector2(1.5, 3.0)) # factor relative to the current scale ``` By default, the origin for these three transformations is the top-left corner of the sprite. If you want to set the origin to a different point (for example the center of the sprite, or another corner), you can use the `origin=` method. @@ -156,7 +156,7 @@ If you're using OpenGL rather than the graphics entities of CrSFML, you can stil To bind a [SF::Texture][] for drawing (basically `glBindTexture`), you call the `bind` class method: ```crystal -texture = ... +texture = [...] # bind the texture SF::Texture.bind texture @@ -166,4 +166,3 @@ SF::Texture.bind texture # bind no texture SF::Texture.bind nil ``` - diff --git a/docs/tutorials/graphics/text.md b/docs/tutorials/graphics/text.md index ee7b69ac..a02cab8d 100644 --- a/docs/tutorials/graphics/text.md +++ b/docs/tutorials/graphics/text.md @@ -44,7 +44,7 @@ text.color = SF::Color::Red # set the text style text.style = (SF::Text::Bold | SF::Text::Underlined) -... +[...] # inside the main loop, between window.clear() and window.display() window.draw(text) @@ -87,4 +87,3 @@ line_spacing = font.get_line_spacing(character_size) kerning = font.get_kerning(character_1, character_2, character_size) ``` - diff --git a/docs/tutorials/graphics/transform.md b/docs/tutorials/graphics/transform.md index f7f90b06..03da3546 100644 --- a/docs/tutorials/graphics/transform.md +++ b/docs/tutorials/graphics/transform.md @@ -95,7 +95,7 @@ Note that changing the origin also changes where the entity is drawn on screen, ```crystal class MyGraphicalEntity < SF::Transformable - # ... + [...] end entity.position = SF.vector2(10, 30) @@ -169,14 +169,14 @@ The bounding box is very useful when implementing collision detection: Checks ag bounding_box = entity.global_bounds # check collision with a point -point = ... +point = [...] if bounding_box.contains? point # collision! end # check collision with another box (like the bounding box of another entity) -other_box = ... +other_box = [...] if bounding_box.intersects? other_box # collision! @@ -212,7 +212,7 @@ class Node end private def on_draw(target, transform) - ... + [...] end end diff --git a/docs/tutorials/graphics/vertex-array.md b/docs/tutorials/graphics/vertex-array.md index 1a7837c1..bfd953fe 100644 --- a/docs/tutorials/graphics/vertex-array.md +++ b/docs/tutorials/graphics/vertex-array.md @@ -67,7 +67,7 @@ Note that you don't have to use the [SF::VertexArray][] class. It's just defined ```crystal vertices = [ SF::Vertex.new(...), - SF::Vertex.new(...) + SF::Vertex.new(...), ] window.draw(vertices, SF::Lines) @@ -99,10 +99,10 @@ quad = SF::VertexArray.new(SF::Quads, 4) # define it as a rectangle, located at (10, 10) and with size 100x100 # define its texture area to be a 25x50 rectangle starting at (0, 0) -quad.append SF::Vertex.new({ 10, 10}, tex_coords: { 0, 0}) -quad.append SF::Vertex.new({110, 10}, tex_coords: {25, 0}) +quad.append SF::Vertex.new({10, 10}, tex_coords: {0, 0}) +quad.append SF::Vertex.new({110, 10}, tex_coords: {25, 0}) quad.append SF::Vertex.new({110, 110}, tex_coords: {25, 50}) -quad.append SF::Vertex.new({ 10, 110}, tex_coords: { 0, 50}) +quad.append SF::Vertex.new({10, 110}, tex_coords: {0, 50}) ``` Texture coordinates are defined in *pixels* (just like the `texture_rect` of sprites and shapes). They are *not* normalized (between 0 and 1), as people who are used to OpenGL programming might expect. @@ -110,10 +110,10 @@ Texture coordinates are defined in *pixels* (just like the `texture_rect` of spr Vertex arrays are low-level entities, they only deal with geometry and do not store additional attributes like a texture. To draw a vertex array with a texture, you must pass it directly to the `draw` method, through a [SF::RenderStates][] object: ```crystal -vertices = ... # SF::VertexArray -texture = ... # SF::Texture +vertices = [...] # SF::VertexArray +texture = [...] # SF::Texture -... +[...] states = SF::RenderStates.new states.texture = texture @@ -126,10 +126,10 @@ window.draw(vertices, states) Transforming is similar to texturing. The transform is not stored in the vertex array, you must pass it to the `draw` method. ```crystal -vertices = ... # SF::VertexArray -transform = ... # SF::Transform +vertices = [...] # SF::VertexArray +transform = [...] # SF::Transform -... +[...] states = SF::RenderStates.new states.transform = transform @@ -244,7 +244,7 @@ class TileMap < SF::Transformable def draw(target, states) # apply the transform - states.transform *= transform() + states.transform *= transform # apply the tileset texture states.texture = @tileset @@ -270,7 +270,7 @@ level = [ 0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0, 0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0, 2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1 + 0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, ] # create the tilemap from the level definition @@ -303,6 +303,7 @@ struct Particle def initialize(@velocity, @lifetime, @position) @total_lifetime = @lifetime end + property velocity : SF::Vector2f property lifetime : SF::Time property position : SF::Vector2f @@ -353,7 +354,7 @@ class ParticleSystem < SF::Transformable end # apply the transform - states.transform *= transform() + states.transform *= transform # draw the vertex array target.draw(vertices, SF::Points, states) @@ -385,7 +386,6 @@ clock = SF::Clock.new # run the main loop while window.open? - # handle events while event = window.poll_event if event.is_a? SF::Event::Closed diff --git a/docs/tutorials/graphics/view.md b/docs/tutorials/graphics/view.md index 391ff3bb..cb1d1469 100644 --- a/docs/tutorials/graphics/view.md +++ b/docs/tutorials/graphics/view.md @@ -135,7 +135,7 @@ window.draw(some_sprite) # want to do visibility checks? retrieve the view current_view = window.view -... +[...] ``` The view remains active until you set another one. This means that there is always a view which defines what appears in the target, and where it is drawn. If you don't explicitly set any view, the render-target uses its own default view, which matches its size 1:1. You can get the default view of a render-target with the `default_view` method. This can be useful if you want to define your own view based on it, or restore it to draw fixed entities (like a GUI) on top of your scene. @@ -162,7 +162,7 @@ If, instead of this default behavior, you'd like to show more/less stuff dependi ```crystal # the event loop while event = window.poll_event - ... + [...] # catch the resize events if event.is_a? SF::Event::Resized diff --git a/docs/tutorials/network/ftp.md b/docs/tutorials/network/ftp.md index 0d5abbf2..d773a1e7 100644 --- a/docs/tutorials/network/ftp.md +++ b/docs/tutorials/network/ftp.md @@ -19,7 +19,7 @@ Every method of the [SF::Ftp][] class wraps an FTP command, and returns a standa ```crystal ftp = SF::Ftp.new -... +[s...] response = ftp.login("username", "password") # just an example, could be any method @@ -177,7 +177,7 @@ ftp.upload("local_file_name.pdf", "remote/destination/path", SF::Ftp::Binary) FTP servers usually close connections that are inactive for a while. If you want to avoid being disconnected, you can send a no-op command periodically: ```crystal -ftp.keep_alive() +ftp.keep_alive ``` ## Disconnecting from the FTP server @@ -185,5 +185,5 @@ ftp.keep_alive() You can close the connection with the server at any moment with the `disconnect` method. ```crystal -ftp.disconnect() +ftp.disconnect ``` diff --git a/docs/tutorials/network/packet.md b/docs/tutorials/network/packet.md index 4233aab6..e3712c30 100644 --- a/docs/tutorials/network/packet.md +++ b/docs/tutorials/network/packet.md @@ -21,7 +21,7 @@ x = 10_u16 s = "hello" d = 0.6_f64 -packet = SF::Packet.new() +packet = SF::Packet.new packet.write(x) packet.write(s) packet.write(d) diff --git a/docs/tutorials/system/stream.md b/docs/tutorials/system/stream.md index 2a7d0fb3..ede3fae2 100644 --- a/docs/tutorials/system/stream.md +++ b/docs/tutorials/system/stream.md @@ -16,8 +16,8 @@ The [SF::InputStream][] class declares four virtual methods: abstract class InputStream abstract def read(data : Slice) : Int64 abstract def seek(position : Int) : Int64 - abstract def tell() : Int64 - abstract def size() : Int64 + abstract def tell : Int64 + abstract def size : Int64 end ``` diff --git a/docs/tutorials/system/thread.md b/docs/tutorials/system/thread.md index c7e742e0..f3c91473 100644 --- a/docs/tutorials/system/thread.md +++ b/docs/tutorials/system/thread.md @@ -34,7 +34,7 @@ end thread = SF::Thread.new(->func) # run it -thread.launch() +thread.launch # the main thread continues to run... SF.sleep SF.seconds(0.15) @@ -72,7 +72,7 @@ Once you've created a [SF::Thread][] instance, you must start it with the `launc ```crystal thread = SF::Thread.new(->func) -thread.launch() +thread.launch ``` `launch` calls the function that you passed to the constructor in a new thread, and returns immediately so that the calling thread can continue to run. @@ -82,15 +82,15 @@ thread.launch() A thread automatically stops when its entry point function returns. If you want to wait for a thread to finish from another thread, you can call its `wait` method. ```crystal -thread = SF::Thread(->func) +thread = SF::Thread.new(->func) # start the thread -thread.launch() +thread.launch -... +[...] # block execution until the thread is finished -thread.wait() +thread.wait ``` The `wait` method is also implicitly called by the destructor of [SF::Thread][], so that a thread cannot remain alive (and out of control) after its owner [SF::Thread][] instance is destroyed. Keep this in mind when you manage your threads (see the last section of this tutorial). @@ -219,8 +219,8 @@ def start_thread SF::Thread.new(->func).launch end -start_thread() -# ... +start_thread +[...] ``` Programmers who write this kind of code expect the `start_thread` function to start a thread that will live on its own and be destroyed when the threaded function ends. This is not what happens. The threaded function appears to block the main thread, as if the thread wasn't working. diff --git a/docs/tutorials/system/time.md b/docs/tutorials/system/time.md index d9913272..5c2e58b4 100644 --- a/docs/tutorials/system/time.md +++ b/docs/tutorials/system/time.md @@ -21,7 +21,7 @@ Note that these three times are all equal. Similarly, a [SF::Time][] can be converted back to either seconds, milliseconds or microseconds: ```crystal -time = ... +time = [...] microseconds = time.as_microseconds milliseconds = time.as_milliseconds @@ -33,7 +33,7 @@ seconds = time.as_seconds [SF::Time][] is just an amount of time, so it supports arithmetic operations such as addition, subtraction, comparison, etc. Times can also be negative. ```crystal -t1 = ... +t1 = [...] t2 = t1 * 2 t3 = t1 + t2 t4 = -t3 @@ -74,6 +74,6 @@ clock = SF::Clock.new while window.open? elapsed = clock.restart update_game(elapsed) - ... + [...] end ``` diff --git a/docs/tutorials/window/events.md b/docs/tutorials/window/events.md index db04ad79..9891e986 100644 --- a/docs/tutorials/window/events.md +++ b/docs/tutorials/window/events.md @@ -58,14 +58,11 @@ To be clear, here is what a typical event loop looks like: while event = window.poll_event # check the type of the event... case event - # window closed - when SF::Event::Closed - window.close - # key pressed - when SF::Event::KeyPressed - ... - # we don't process other types of events - end + when SF::Event::Closed # window closed + window.close + when SF::Event::KeyPressed # key pressed + [...] + end # we don't process other types of events end ``` @@ -301,4 +298,3 @@ when SF::Event::JoystickDisconnected puts "joystick disconnected: #{event.joystick_id}" end ``` - diff --git a/docs/tutorials/window/inputs.md b/docs/tutorials/window/inputs.md index c1127ad2..1e43ab95 100644 --- a/docs/tutorials/window/inputs.md +++ b/docs/tutorials/window/inputs.md @@ -71,7 +71,7 @@ You can check whether a joystick is connected or not: ```crystal if SF::Joystick.connected?(0) # joystick number 0 is connected - ... + [...] end ``` diff --git a/docs/tutorials/window/opengl.md b/docs/tutorials/window/opengl.md index c201ff01..2d296573 100644 --- a/docs/tutorials/window/opengl.md +++ b/docs/tutorials/window/opengl.md @@ -19,15 +19,15 @@ Since SFML is based on OpenGL, its windows are ready for OpenGL calls without an ```crystal @[Link("GL")] # Use @[Link(framework: "OpenGL")] on Mac OSX lib GL - fun enable = glEnable(cap : Int32) - TEXTURE_2D = 3553 + fun enable = glEnable(cap : Int32) + TEXTURE_2D = 3553 end window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "OpenGL") # it works out of the box GL.enable(GL::TEXTURE_2D) -... +[...] ``` In case you think it is *too* automatic, [SF::Window][]'s constructor has an extra argument that allows you to change the settings of the underlying OpenGL context. This argument is an instance of the structure, it provides access to the following settings: @@ -44,8 +44,8 @@ settings = SF::ContextSettings.new( ) window = SF::RenderWindow.new( - SF::VideoMode.new(800, 600), - "OpenGL", settings: settings + SF::VideoMode.new(800, 600), + "OpenGL", settings: settings ) ``` @@ -76,9 +76,9 @@ lib GL fun enable = glEnable(cap : Int32) fun viewport = glViewport(x : Int32, y : Int32, width : Int32, height : Int32) fun clear = glClear(mask : Int32) - TEXTURE_2D = 3553 + TEXTURE_2D = 3553 COLOR_BUFFER_BIT = 16384 - DEPTH_BUFFER_BIT = 256 + DEPTH_BUFFER_BIT = 256 end GL.enable(GL::TEXTURE_2D) @@ -158,7 +158,7 @@ The only way to avoid conflicts between SFML and your own OpenGL states, is to s The easiest solution is to let CrSFML do it for you, with the `push_gl_states`/`pop_gl_states` methods: ```crystal -glDraw... +glDraw(...) window.push_gl_states @@ -166,23 +166,23 @@ window.draw(...) window.pop_gl_states -glDraw... +glDraw(...) ``` Since it has no knowledge about your OpenGL code, SFML can't optimize these steps and as a result it saves/restores all available OpenGL states and matrices. This may be acceptable for small projects, but it might also be too slow for bigger programs that require maximum performance. In this case, you can handle saving and restoring the OpenGL states yourself, with `glPushAttrib`/`glPopAttrib`, `glPushMatrix`/`glPopMatrix`, etc. If you do this, you'll still need to restore SFML's own states before drawing. This is done with the `reset_gl_states` method. ```crystal -glDraw... +glDraw(...) -glPush... +glPush(...) window.reset_gl_states window.draw(...) -glPop... +glPop(...) -glDraw... +glDraw(...) ``` By saving and restoring OpenGL states yourself, you can manage only the ones that you really need which leads to reducing the number of unnecessary driver calls. diff --git a/docs/tutorials/window/window.md b/docs/tutorials/window/window.md index fd96ef3d..850ff943 100644 --- a/docs/tutorials/window/window.md +++ b/docs/tutorials/window/window.md @@ -15,7 +15,7 @@ require "crsfml" window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "My window") -... +[...] ``` The first argument, the *video mode*, defines the size of the window (the inner size, without the title bar and borders). Here, we create a window with a size of 800x600 pixels. @@ -114,7 +114,7 @@ size = window.size width = size.x height = size.y -... +[...] ``` You can refer to the API documentation for a complete list of [SF::Window][]'s methods. diff --git a/mkdocs.yml b/mkdocs.yml index 3c56887a..de37ae71 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -42,3 +42,15 @@ plugins: crystal_docs_flags: [--source-refname=master] - literate-nav - section-index + - code-validator: + enabled: false + enable_on_env: LINT + identifiers: + crystal: + validators: + - crystal tool format --check - + crystal-play: + language: crystal + validators: + - crystal tool format --check - + - crystal build --no-codegen $<