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

Author Topic: App.display  (Read 2449 times)

0 Members and 1 Guest are viewing this topic.

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
App.display
« on: December 10, 2012, 07:17:00 pm »
In version 2.0 does the command App.display write to the screen the most recent App.draw item defined or does it re display all previous App.draw items.
Thanks a bunch.
Warren Trammell

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10850
    • View Profile
    • development blog
    • Email
Re: App.display
« Reply #1 on: December 10, 2012, 08:17:57 pm »
It will basically just swap the back and front buffer and whatever you've .draw() to the back buffer since the last .clear() will get displayed.
Note: You always need to call clear() and display() for every frame.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: App.display
« Reply #2 on: December 10, 2012, 10:20:36 pm »
I have written a few lines of code in C++ using version 2.0.
It fills the screen randomingly choosing one of 12 colors for each pixel.
I then sort line by line moving the darker colors to the left.
If I wait until all rows are sorted and then call App.display it works.
But if I call App.display after sorting each line, the final screen is different.
I am confused.
If anything I would expect the opposite results.
Any thought? Anyone? 
Thanks.
Warren
A 90 year old would be programmer with a new mac mini.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10850
    • View Profile
    • development blog
    • Email
Re: App.display
« Reply #3 on: December 10, 2012, 11:16:47 pm »
I've no idea what you're trying to do, what you'd expect to happen and what actually does happen. So unless you show a minimal and complete example, I can't help with the specific problem.

As for the general state, you should look at some SFML examples.
You usually separate the updating phase (i.e. moving lines and dots) from the drawing phase (calling draw() on your lines and dots). So you first update things and then clear() the screen, draw() the objects and display() them and this for every iteration.
Similar to this pseudo code:
while(window.isOpen())
{
    sf::Event event;
    while(window.pollEvent(event))
    {
          if(event.type == sf::Event::Close)
               window.close();
     }
     
     // Update your lines etc., e.g.
     sprite.move(20.f, 10.f);

     window.clear() // Clear the screen

     // Draw your  lines etc., e.g.
     window.draw(sprite);

     window.display() // Display everything
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: App.display
« Reply #4 on: December 11, 2012, 04:58:52 am »
// Main.cpp
// Basic colors
// December 6, 2012
// Random colors to fill screen
// Sort horizontal and then vertical
// Mark's input

#include <SFML/Graphics.hpp>
#include <time.h>
#include <iostream>
#include <sstream>

int data[2450][3],total[1350], wheel[12][3];

void quickSort(int[], int, int);
void q_sort(int[], int, int, int);

FILE *pFile;

int main()
{   
   pFile = fopen("//users//warren//programming//projects//basicolor.txt","r");
   
   int prnt, green, red, blue, x, y, z;
   int count,row,col;
   char buffer[10], string1[10], string2[10], string3[10];
   
   // Initialize random
   srand((unsigned int)time(NULL));
   
   // Create main window
   sf::RenderWindow App(sf::VideoMode(2500, 1350), "Basic Colors Graphics");
   
   // Clear screen
   App.clear(sf::Color(128, 128, 128));
            
   for(y = 0; y < 12; y++)          
       {
       for(x = 0; x < 3; x++)
      {
           fscanf(pFile,"%i",&wheel[y]
  • );

      }
       }
        // Fill screen with randow colors:
   for(y = 0; y < 1350; y++)
       {   
       for(x = 0; x < 2500; x++)
      {
           z = rand() % 12;
      red = wheel[z][0];
      green = wheel[z][1];
      blue = wheel[z][2];
         
      sf::Color choice(red,green,blue);
                sf::RectangleShape recShape;
                recShape.setSize(sf::Vector2f(1,1));
                recShape.setPosition(x, y);
                recShape.setFillColor(choice);
                App.draw(recShape);

      }
        App.display();
        }
             
         // Screen filled with random colors:

                    sf::Image Image = App.capture();               
                    for(count = 1; count < 1350; count++)
                        {
                        row = count;
                        // Sort by rows
                        y = row -1;
                     z = 0;
              for(x = 0; x < 1000; x++)
             {
             sf::Color color = Image.getPixel(x,y);
             data[z][0] = (int)color.r;
             data[z][1] = (int)color.g;
             data[z][2] = (int)color.b;
             sprintf(string1,"%i",(int)color.r);
             sprintf(string2,"%i",(int)color.g);
             sprintf(string3,"%i",(int)color.b);
             strcpy(buffer,string1);
             strcat(buffer,string2);
             strcat(buffer,string3);
                      
             total[z] = atoi(buffer);
             z++;
             }
         quickSort(total, z, 1);
         z = 0;
         for(x = 0; x < 1000; x++)
             {
             red = data[z][0];
             green = data[z][1];
             blue = data[z][2];
             sf::Color choice(red,green,blue);
                            sf::RectangleShape recShape;
                            recShape.setSize(sf::Vector2f(1,1));
                            recShape.setPosition(x, y);
                            recShape.setFillColor(choice);
                            App.draw(recShape);
                            z++;
             }
                App.display();
                }
                           

// Start game loop
        while (App.isOpen())
            {
            // Process events
            sf::Event Event;
            while (App.pollEvent(Event))
                {
                // Close window : exit
                if (Event.type == sf::Event::Closed)  App.close();

                //Escape key exit
                if((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))  App.close();
                }
            }
        return EXIT_SUCCESS;
}
//End of main



void quickSort(int total[], int size, int row)
{
   q_sort(total, 0, size - 1, row);
}
void q_sort(int total[], int left, int right, int row)
{
   int pivot, l_hold, r_hold;
   int piv0,piv1,piv2;
   l_hold = left;
   r_hold = right;
   pivot = total
;
   piv0 = data
[0];
   piv1 = data
[1];
   piv2 = data
[2];
   while (left < right)
   {
      while ((total
>= pivot) && (left < right)) right--;
      if (left != right)
      {
         total
= total
;
         data
[0] = data
[0];
         data
[1] = data
[1];
         data
[2] = data
[2];
         left++;
      }
      while ((total
<= pivot) && (left < right)) left++;
      if (left != right)
      {
         total
= total
;
         data
[0] = data
[0];
         data
[1] = data
[1];
         data
[2] = data
[2];
         right--;
      }
   }
   total
= pivot;
   data
[0] = piv0;
   data
[1] = piv1;
   data
[2] = piv2;
   pivot = left;
   piv0 = data
[0];
   piv1 = data
[1];
   piv2 = data
[2];
   left = l_hold;
   right = r_hold;
   if (left < pivot) q_sort(total, left, pivot-1,row);
   if (right > pivot) q_sort(total, pivot+1, right,row);
}



wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Graphics 2.0
« Reply #5 on: December 12, 2012, 12:33:33 am »
Here is a simpler version of the App.display problem I am having.

#include <SFML/Graphics.hpp>
#include <time.h>
#include <iostream>
#include <sstream>

int data[2560][3],total[1440], wheel[12][3];

void quickSort(int[], int, int);
void q_sort(int[], int, int, int);

FILE *pFile;

int main()
{   
   pFile = fopen("//users//warren//programming//projects//basicolor.txt","r");
   
   int prnt, green, red, blue, x, y, z = 0;
   int count = 0, row,col;
   char buffer[12], string1[12], string2[12], string3[12];
   
   // Initialize random
   srand((unsigned int)time(NULL));
   
   // Create main window
   sf::RenderWindow App(sf::VideoMode(2500, 1300), "Basic Colors Graphics");
   
   // Clear screen
   App.clear(sf::Color(128, 255, 128));
            
   for(y = 0; y < 12; y++)          
       {
       for(x = 0; x < 3; x++)
      {
           fscanf(pFile,"%i",&wheel[y]
  • );

      }
       }
   
        for(y = 200; y < 1200; y++)
            {   
       for(x = 400; x < 800; x++)
      {
      red = wheel[z][0];
      green = wheel[z][1];
      blue = wheel[z][2];
         
      sf::Color choice(red,green,blue);
                sf::RectangleShape recShape;
                recShape.setSize(sf::Vector2f(1,1));
                recShape.setPosition(x, y);
                recShape.setFillColor(choice);
                App.draw(recShape);
                count++;
                if (count > 10000)
                   {
                   z++;
                   count = 0;
                   }
                if(z > 11) z = 0;
      }
            App.display();
            }
             
// Start game loop
        while(App.isOpen())
            {
            // Process events
            sf::Event Event;
            while (App.pollEvent(Event))
                {
                // Close window : exit
                if (Event.type == sf::Event::Closed)  App.close();
                }
            }
        return EXIT_SUCCESS;
}
//End of main

Why does changing the range of the x variable to 400 to 1200 cause 12 different colors to be displayed?
Thanks
Warren

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Graphics 2.0
« Reply #6 on: December 12, 2012, 04:57:26 am »
Use the code tag for it, it's way easier to read that way: [ code=cpp ] [ /code ]

Also use ctime instead of time.h and you'll be able to call any function of it with the std namespace. Just as a small utility hint.

A better explanation of what you're doing, what's wrong and what's the desired outcome wouldn't hurt as well.
« Last Edit: December 12, 2012, 05:01:32 am by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: App.display
« Reply #7 on: December 12, 2012, 05:33:35 pm »
The object is to fill the screen with random colored pixels and then sort the pixels from left to right with the darkest on the left.  The program worked fine in version 1.6 but something was changed with the App.display command in 2.0 as it will only work in 2.0 with screen sizes of 1000 x 1000 pixels or less.  What was changed in App.display from 1.6 to 2.0?????
Warren

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: App.display
« Reply #8 on: December 13, 2012, 04:37:14 am »
As far as I know the changes from 1.6 to 2.0 are mainly the addition of sf::Vertex and sf::VertexArray as well as bug fixes and changes in name conventions, the display function keeps its previous functionality as the function in charge of making everything that was drawn in the window visible.

Also, a VertexArray with sf::points is the natural solution towards drawing plain pixels, not an sf::RectangleShape. The main loop should be bigger than it is in your code, it should cover the window.clear(), the draw calls and the display call as well. Don't be afraid of drawing and clearing every frame, SFML is designed to work that way.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!