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

Author Topic: Vertex Texture and Vertex Color not working in C#  (Read 1314 times)

0 Members and 1 Guest are viewing this topic.

yolan51

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Vertex Texture and Vertex Color not working in C#
« on: March 19, 2023, 06:27:23 pm »
Hi , i can't find out how to use Vertex  Texxcord in c# without using vertex.Color ! which is slightly modifying the images color !

i saw this page : https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php in C++ but it seems to behave differently than C# equivalent.

I cant draw/render  unless i use a color on my vertex , i dont know why ! Any clue is appreciated !

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

namespace TestingVertexQuad
{

    public class Program
    {
        static void Main(string[] args)
        {

            RenderWindow myRenderWindow = new RenderWindow(new VideoMode(1024, 800), "SMFL QUADS TESTING");
            Texture texture = new Texture("C:\\Users\\yolan\\source\\repos\\TestingVertexQuad\\RPG_Character.png");
            texture.Smooth= true;
            RenderStates myRenderState = new RenderStates(texture);
           
            myRenderWindow.Closed += OnClose;
            myRenderWindow.KeyPressed += myKeyPress;
            myRenderWindow.KeyReleased += myKeyReleased;

            VertexArray vertArray1 = new VertexArray(PrimitiveType.Quads, 4 * 1000);
     

            Vertex ver1 = new Vertex();
            Vertex ver2 = new Vertex();
            Vertex ver3 = new Vertex();
            Vertex ver4 = new Vertex();

            ver1.Position = new Vector2f(700f, 700f);
            ver1.TexCoords = new Vector2f(0f, 0f);
            ver1.Color = new Color(255,255,255,255);
            ver2.Position = new Vector2f(750f, 700f);
            ver2.TexCoords = new Vector2f(50f, 0f);
            ver2.Color = new Color(255, 255, 255, 255);
            ver3.Position = new Vector2f(750f,775f);
            ver3.TexCoords = new Vector2f(50f, 75f);
            ver3.Color = new Color(255, 255, 255, 255);
            ver4.Position = new Vector2f(700f,775f);
            ver4.TexCoords = new Vector2f(0f, 75f);
            ver4.Color = new Color(255, 255, 255, 255);
            Sprite sprite = new Sprite(texture);
           
            vertArray1.Append(ver1);
            vertArray1.Append(ver2);
            vertArray1.Append(ver3);
            vertArray1.Append(ver4);

            while (myRenderWindow.IsOpen)
            {

                myRenderWindow.DispatchEvents();


                myRenderWindow.Clear(Color.White);

                myRenderWindow.Draw(sprite);
                myRenderWindow.Draw(vertArray1, myRenderState);
                myRenderWindow.Display();
            }


        }
        internal static void OnClose(object sender, EventArgs e)
        {
            // Close the window when OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            Console.WriteLine(e.GetType());
            window.Close();

        }

        internal static void OnResize(object sender, SizeEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            FloatRect visibleArea = new FloatRect(0, 0, e.Width, e.Height);
            window.SetView(new View(visibleArea));
        }
        internal static void myKeyPress(object sender, KeyEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            //Player pl = Player.getInstance();
            // Close the window when OnClose event is received
            if (e.Code == Keyboard.Key.W)
            {
                //pl.IsMovingUp = true;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.A)
            {
                //pl.IsMovingLeft = true;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.S)
            {
                //pl.IsMovingDown = true;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.D)
            {
                //pl.IsMovingRight = true;

                Console.WriteLine(" TEST " + e.Code);
            }

        }
        internal static void myKeyReleased(object sender, KeyEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            //Player pl = Player.getInstance();
            // Close the window when OnClose event is received
            if (e.Code == Keyboard.Key.W)
            {
                //pl.IsMovingUp = false;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.A)
            {
                //pl.IsMovingLeft = false;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.S)
            {
                //pl.IsMovingDown = false;

                Console.WriteLine(" TEST " + e.Code);
            }
            if (e.Code == Keyboard.Key.D)
            {
               // pl.IsMovingRight = false;

                Console.WriteLine(" TEST " + e.Code);
            }

        }
        internal static void myMouseKeyPressed(object sender, MouseButtonEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            //Player pl = Player.getInstance();
            Vector2i pixelPos = Mouse.GetPosition(window);

            // convert it to world coordinates
            Vector2f worldPos = window.MapPixelToCoords(pixelPos);


            // convert it to world coordinates

            // Close the window when OnClose event is received
            if (e.Button == Mouse.Button.Left)
            {

                //pl.IsLeftMousePressed = true;

               // pl.MousePositionX = worldPos.X;
               // pl.MousePositionY = worldPos.Y;


            }
            if (e.Button == Mouse.Button.Right)
            {
               // pl.IsRightMousePressed = true;


            }

        }
        internal static void myMouseReleased(object sender, MouseButtonEventArgs e)
        {

            //Player pl = Player.getInstance();
            // Close the window when OnClose event is received
            if (e.Button == Mouse.Button.Left)
            {

               // pl.IsLeftMousePressed = false;

            }
            if (e.Button == Mouse.Button.Right)
            {
                //pl.IsRightMousePressed = false;

            }

        }
        internal static void myMouseKeyMoving(object sender, MouseMoveEventArgs e)
        {


            RenderWindow window = (RenderWindow)sender;
            //Player pl = Player.getInstance();
            Vector2i pixelPos = Mouse.GetPosition(window);

            // convert it to world coordinates
            Vector2f worldPos = window.MapPixelToCoords(pixelPos, window.DefaultView);
            //pl.MousePositionX = worldPos.X;
            //pl.MousePositionY = worldPos.Y;

        }
    }
   
}
 
« Last Edit: March 20, 2023, 09:34:25 pm by eXpl0it3r »

yolan51

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Vertex Texture and Vertex Color not working in C#
« Reply #1 on: March 19, 2023, 09:04:57 pm »
After Looking at others question on the forum i found out that  some Vertex constructor put Vertex.Color to White.  So it seems that white color do little or no effect on the texture . Have a nice day !