Renamed / moved / updated the SFML.Net examples (still in progress... having troubles with SVN)
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1560 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
002902319c
commit
2d83514452
28 changed files with 103 additions and 121 deletions
|
@ -7,7 +7,7 @@ Imports Tao.FreeGlut
|
|||
|
||||
Module OpenGL
|
||||
|
||||
Dim WithEvents App As RenderWindow
|
||||
Dim WithEvents window As RenderWindow
|
||||
|
||||
''' <summary>
|
||||
''' Entry point of application
|
||||
|
@ -15,26 +15,25 @@ Module OpenGL
|
|||
Sub Main()
|
||||
|
||||
' Create main window
|
||||
App = New RenderWindow(New VideoMode(800, 600), "SFML.Net OpenGL (Visual Basic)")
|
||||
App.PreserveOpenGLStates(True)
|
||||
window = New RenderWindow(New VideoMode(800, 600), "SFML.Net OpenGL (Visual Basic)")
|
||||
|
||||
' Create a sprite for the background
|
||||
Dim BackgroundImage = New Image("datas/opengl/background.jpg")
|
||||
Dim Background = New Sprite(BackgroundImage)
|
||||
Dim backgroundImage = New Image("resources/background.jpg")
|
||||
Dim background = New Sprite(backgroundImage)
|
||||
|
||||
' Create a text to display
|
||||
Dim Text = New String2D("This is a rotating cube")
|
||||
Text.Position = New Vector2(250.0F, 300.0F)
|
||||
Text.Color = New Color(128, 0, 128)
|
||||
Dim text = New Text("SFML / OpenGL demo")
|
||||
text.Position = New Vector2(250.0F, 450.0F)
|
||||
text.Color = New Color(255, 255, 255, 170)
|
||||
|
||||
' Load an OpenGL texture.
|
||||
' We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
||||
' We could directly use a SFML.Graphics.Image as an OpenGL texture (with its Bind() member function),
|
||||
' but here we want more control on it (generate mipmaps, ...) so we create a new one
|
||||
Dim Texture = 0
|
||||
Using TempImage = New Image("datas/opengl/texture.jpg")
|
||||
Gl.glGenTextures(1, Texture)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture)
|
||||
Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, TempImage.Width, TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels)
|
||||
Dim texture = 0
|
||||
Using tempImage = New Image("resources/texture.jpg")
|
||||
Gl.glGenTextures(1, texture)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture)
|
||||
Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, tempImage.Width, tempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, tempImage.Pixels)
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR)
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR)
|
||||
End Using
|
||||
|
@ -51,108 +50,93 @@ Module OpenGL
|
|||
|
||||
' Bind our texture
|
||||
Gl.glEnable(Gl.GL_TEXTURE_2D)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture)
|
||||
Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)
|
||||
|
||||
Dim Time = 0.0F
|
||||
Dim time = 0.0F
|
||||
|
||||
' Start game loop
|
||||
While (App.IsOpened())
|
||||
While (window.IsOpened())
|
||||
|
||||
' Process events
|
||||
App.DispatchEvents()
|
||||
window.DispatchEvents()
|
||||
|
||||
' Draw background
|
||||
App.Draw(Background)
|
||||
window.SaveGLStates()
|
||||
window.Draw(background)
|
||||
window.RestoreGLStates()
|
||||
|
||||
' Clear depth buffer
|
||||
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
' We get the position of the mouse cursor, so that we can move the box accordingly
|
||||
Dim x = window.Input.GetMouseX() * 200.0F / window.Width - 100.0F
|
||||
Dim y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F
|
||||
|
||||
' Apply some transformations
|
||||
Time += App.GetFrameTime()
|
||||
time += window.GetFrameTime()
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW)
|
||||
Gl.glLoadIdentity()
|
||||
Gl.glTranslatef(0.0F, 0.0F, -200.0F)
|
||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F)
|
||||
Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F)
|
||||
Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F)
|
||||
Gl.glTranslatef(x, y, -100.0F)
|
||||
Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F)
|
||||
Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F)
|
||||
Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F)
|
||||
|
||||
' Draw a cube
|
||||
Dim size = 20.0F
|
||||
Gl.glBegin(Gl.GL_QUADS)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(-size, -size, -size)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(-size, size, -size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(size, size, -size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(size, -size, -size)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(-size, -size, size)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(-size, size, size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(size, size, size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(size, -size, size)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(-size, -size, -size)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(-size, size, -size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(-size, size, size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(-size, -size, size)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(size, -size, -size)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(size, size, -size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(size, size, size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(size, -size, size)
|
||||
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(-size, -size, size)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(-size, -size, -size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(size, -size, -size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(size, -size, size)
|
||||
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 1) : Gl.glVertex3f(-size, size, size)
|
||||
Gl.glTexCoord2f(0, 0) : Gl.glVertex3f(-size, size, -size)
|
||||
Gl.glTexCoord2f(1, 0) : Gl.glVertex3f(size, size, -size)
|
||||
Gl.glTexCoord2f(1, 1) : Gl.glVertex3f(size, size, size)
|
||||
|
||||
Gl.glEnd()
|
||||
|
||||
' Draw some text on top of our OpenGL object
|
||||
App.Draw(Text)
|
||||
window.SaveGLStates()
|
||||
window.Draw(text)
|
||||
window.RestoreGLStates()
|
||||
|
||||
' Finally, display the rendered frame on screen
|
||||
App.Display()
|
||||
window.Display()
|
||||
|
||||
End While
|
||||
|
||||
' Don't forget to destroy our texture
|
||||
Gl.glDeleteTextures(1, Texture)
|
||||
Gl.glDeleteTextures(1, texture)
|
||||
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Function called when the window is closed
|
||||
''' </summary>
|
||||
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles App.Closed
|
||||
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.Closed
|
||||
Dim window = CType(sender, RenderWindow)
|
||||
window.Close()
|
||||
End Sub
|
||||
|
@ -160,7 +144,7 @@ Module OpenGL
|
|||
''' <summary>
|
||||
''' Function called when a key is pressed
|
||||
''' </summary>
|
||||
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles App.KeyPressed
|
||||
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles window.KeyPressed
|
||||
Dim window = CType(sender, RenderWindow)
|
||||
If e.Code = KeyCode.Escape Then
|
||||
window.Close()
|
||||
|
@ -170,7 +154,7 @@ Module OpenGL
|
|||
''' <summary>
|
||||
''' Function called when the window is resized
|
||||
''' </summary>
|
||||
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles App.Resized
|
||||
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.Resized
|
||||
Gl.glViewport(0, 0, e.Width, e.Height)
|
||||
End Sub
|
||||
|
||||
|
|
BIN
dotnet/examples/visualbasic/resources/background.jpg
Normal file
BIN
dotnet/examples/visualbasic/resources/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
BIN
dotnet/examples/visualbasic/resources/texture.jpg
Normal file
BIN
dotnet/examples/visualbasic/resources/texture.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{98552080-F688-46B4-A2FF-1AC7C50ECBE8}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<OutputPath>.\</OutputPath>
|
||||
<DocumentationFile>visualbasic.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
@ -37,13 +37,13 @@
|
|||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="sfmlnet-graphics, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="sfmlnet2-graphics, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sfmlnet-graphics.dll</HintPath>
|
||||
<HintPath>..\..\lib\sfmlnet2-graphics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="sfmlnet-window, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="sfmlnet2-window, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sfmlnet-window.dll</HintPath>
|
||||
<HintPath>..\..\lib\sfmlnet2-window.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue