Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using SFML with Visual C#  (Read 10890 times)

0 Members and 1 Guest are viewing this topic.

The Phantom

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Using SFML with Visual C#
« on: July 27, 2012, 10:51:54 pm »
I’m trying to use SFML with Visual C# 2010 Express. Here’s what I did:
  • I created an empty project and added a source file;
  • I copied the contents of the example from the documentation file provided with SFML;
  • I renamed the namespace in that example, and I commented out the parts for a sprite and a music file;
  • I replaced "arial.ttf" with an absolute path, to be sure it can find it;
  • In Solution Explorer, I right-clicked the project, chose Add Reference, and on the Browse tab selected the sfmlnet-audio.dll, sfmlnet-graphics.dll and sfmlnet-window.dll from SFML’s lib folder;
  • I added csfml-audio.dll, csfml-graphics.dll and csfml-window.dll from SFML’s extlib folder to the project, and in their properties I changed Copy to Output Directory to Copy if newer.
(I found out about the last two steps in this thread.)

The problem is, only a blank console window appears. Although this problem is mentioned in the thread linked above, no solution to it seems to be provided. So I’m asking, what’s wrong here?

Here’s the entire code:

using System;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace SFMLTest {
   class Program {
      static void OnClose(object sender, EventArgs e) {
         // Close the window when OnClose event is received
         RenderWindow window = (RenderWindow) sender;
         window.Close();
      }

      static void Main(string[] args) {
         // Create the main window
         RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML window");
         app.Closed += new EventHandler(OnClose);

         // Load a sprite to display
         // Image image = new Image("cute_image.jpg");
         // Sprite sprite = new Sprite(image);

         // Create a graphical string to display
         Font arial = new Font(@"C:\Users\The Phantom\Documents\Necessary\arial.ttf");
         String2D text = new String2D("Hello SFML.Net", arial);

         // Load a music to play
         // Music music = new Music("nice_music.ogg");
         // music.Play();

         // Start the game loop
         while(app.IsOpened()) {
            // Process events
            app.DispatchEvents();

            // Clear screen
            app.Clear();

            // Draw the sprite
            // app.Draw(sprite);

            // Draw the string
            app.Draw(text);

            // Update the window
            app.Display();
         }
      }
   }
}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Using SFML with Visual C#
« Reply #1 on: July 28, 2012, 01:23:39 am »
Everything you are doing is correct, except one minor detail. You are using SFML 1.6. SFML 1.6 contains an ATI graphics card bug that causes issues. That I is probably your trouble with the window not showing. To fix it download the SFML.Net 2.0 RC and try that. It should fix all of your trouble  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

The Phantom

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Using SFML with Visual C#
« Reply #2 on: July 28, 2012, 09:50:21 am »
Thank you, SFML 2.0 RC soved the problem!

 

anything