IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

Différence utilisation mémoire entre sdl et xcb


Sujet :

SDL

  1. #1
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut Différence utilisation mémoire entre sdl et xcb
    Salut à tous.

    J'ai remarqué une (grande) différence de mémoire utilisé entre xcb et sdl.
    Pour faire un simple rectangle: sdl: 40 mb, xcb: 1.4 mb.

    Je sais que sdl est un niveau plus haut que xcb, mais la mémoire est-elle justifié ?
    Y a t il une technique courante à faire pour la rendre bas ou ça restera comme cela (à 40mb) ?

    Je me demandes si sdl utilise un truc en plus.

    Car j'ai ce 40 mb généralement quand j'ajoutes un contexte opengl (dans xlib).

    Mais là je n'en ai pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    maFenetre = SDL_CreateWindow("Teste SDL 2.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 100, 100, SDL_WINDOW_SHOWN);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    renderer =  SDL_CreateRenderer(maFenetre, 0, SDL_RENDERER_SOFTWARE);

    Qu'en pensez vous ?

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Je pense que vous pouvez réduire la mémoire utilisée en créant un SDL_RENDERER qui n'est pas software (logiciel).
    Sinon, 40 Mo cela me semble beaucoup. Comment déterminez vous la mémoire utilisée par le programme ? Pouvez-vous montrer le code plus complet ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  3. #3
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut
    Bonjour.

    Je détermine grâce à un logiciel console: top et logiciel graphique: lxtask, qui me montre qu'il utilise:
    - RSS: 43 mb
    - VM-Size: 76 mb

    Avec xcb:
    - RSS: 1.5 mb
    - VM-Size: 2.3 mb

    J'ai essayé les 4 modes ci-dessous, mais même résultat:
    - SDL_RENDERER_PRESENTVSYNC
    - SDL_RENDERER_ACCELERATED
    - SDL_RENDERER_SOFTWARE
    - SDL_RENDERER_TARGETTEXTURE

    Code sdl:
    gcc main.c -o main -l SDL2
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    #include <stdio.h>
    #include <SDL2/SDL.h>
     
     
    int main(int argc, char **argv)
    {	
    	if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    	{
    		printf("Erreur lors de l'initialisation de la SDL\n\n");
    		SDL_Quit();
    		return -1;
    	}
     
    	SDL_Window* fenetre = 0;
    	fenetre = SDL_CreateWindow(
    	"Test SDL 2.0",
    	SDL_WINDOWPOS_CENTERED,
    	SDL_WINDOWPOS_CENTERED,
    	100,
    	100,
    	SDL_WINDOW_SHOWN
    	);
     
    	if(fenetre == 0)
    	{
    		printf("Erreur lors de la creation de la fenêtre\n\n");
    		SDL_Quit();
    		return -1;
    	}
     
    	SDL_Renderer* renderer = NULL;
    	renderer =  SDL_CreateRenderer(fenetre, 0, SDL_RENDERER_SOFTWARE);
    	SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    	SDL_RenderClear(renderer);
    	SDL_Rect r;
    	r.x = 35;
    	r.y = 35;
    	r.w = 30;
    	r.h = 30;
    	SDL_SetRenderDrawColor( renderer, 0, 0, 255, 255 );
    	SDL_RenderFillRect(renderer, &r);
    	SDL_RenderPresent(renderer);
     
    	SDL_Delay(10000);
     
    	SDL_DestroyWindow(fenetre);
    	SDL_Quit();
     
    	return 0;
    }

    Code xcb:
    gcc xcb.c -o xcb -l xcb
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    #include <stdlib.h>
    #include <stdio.h>
     
    #include <xcb/xcb.h>
     
    int
    main ()
    {
      xcb_connection_t    *c;
      xcb_screen_t        *screen;
      xcb_drawable_t       win;
      xcb_gcontext_t       foreground;
      xcb_generic_event_t *e;
      uint32_t             mask = 0;
      uint32_t             values[2];
     
      /* geometric objects */
      xcb_point_t          points[] = {
        {10, 10},
        {10, 20},
        {20, 10},
        {20, 20}};
     
      xcb_point_t          polyline[] = {
        {50, 10},
        { 5, 20},     /* rest of points are relative */
        {25,-20},
        {10, 10}};
     
      xcb_segment_t        segments[] = {
        {100, 10, 140, 30},
        {200, 20, 240, 10}};
     
      xcb_rectangle_t      rectangles[] = {
        { 10, 50, 40, 20},
        { 20, 150, 50, 120},
        { 80, 50, 10, 40}};
     
      xcb_arc_t            arcs[] = {
        {10, 100, 60, 40, 0, 90 << 6},
        {90, 100, 55, 40, 0, 270 << 6}};
     
      /* Open the connection to the X server */
      c = xcb_connect (NULL, NULL);
     
      /* Get the first screen */
      screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
     
      /* Create black (foreground) graphic context */
      win = screen->root;
     
      foreground = xcb_generate_id (c);
      mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
      values[0] = screen->black_pixel;
      values[1] = 0;
      xcb_create_gc (c, foreground, win, mask, values);
     
      /* Ask for our window's Id */
      win = xcb_generate_id(c);
     
      /* Create the window */
      mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
      values[0] = screen->white_pixel;
      values[1] = XCB_EVENT_MASK_EXPOSURE;
      xcb_create_window (c,                             /* Connection          */
                         XCB_COPY_FROM_PARENT,          /* depth               */
                         win,                           /* window Id           */
                         screen->root,                  /* parent window       */
                         0, 0,                          /* x, y                */
                         350, 350,                      /* width, height       */
                         10,                            /* border_width        */
                         XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
                         screen->root_visual,           /* visual              */
                         mask, values);                 /* masks */
     
      /* Map the window on the screen */
      xcb_map_window (c, win);
     
     
      /* We flush the request */
      xcb_flush (c);
     
      while ((e = xcb_wait_for_event (c))) {
        switch (e->response_type & ~0x80) {
        case XCB_EXPOSE: {
          /* We draw the points */
          xcb_poly_point (c, XCB_COORD_MODE_ORIGIN, win, foreground, 4, points);
     
          /* We draw the polygonal line */
          xcb_poly_line (c, XCB_COORD_MODE_PREVIOUS, win, foreground, 4, polyline);
     
          /* We draw the segements */
          xcb_poly_segment (c, win, foreground, 2, segments);
     
          /* We draw the rectangles */
          xcb_poly_rectangle (c, win, foreground, 3, rectangles);
     
          /* We draw the arcs */
          xcb_poly_arc (c, win, foreground, 2, arcs);
     
          /* We flush the request */
          xcb_flush (c);
     
          break;
        }
        default: {
          /* Unknown event type, ignore it */
          break;
        }
        }
        /* Free the Generic Event */
        free (e);
      }
     
      return 0;
    }

  4. #4
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut
    Sur ce teste,
    - j'ouvre ma fenêtre et contenu vide pendant 8 secondes: 42.6 mb
    - j'ajoute un contexte opengl dans la fenêtre et affiche un triangle opengl pendant 8 secondes: 43.1 mb
    - je termines d'afficher mon triangle opengl, supprime le contexte opengl et attend pendant 8 secondes: 42.x mb
    - j'ajoute sdl_render et affiche un carré pendant 8 secondes: 43.3 mb

    Donc tous ce passe sur 40 mb.
    Vu que lors d'un nouveau context opengl il n'augmente pas 40 mb de mémoire, je crois que par défaut il m'ouvre un contexte (opengl il me semble ou je sais pas) en arrière plan.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    #include "stdio.h"
    #include <GL/gl.h>
    #include <SDL2/SDL.h>
     
    int main(int argc, char **argv)
    {	
    	if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    	{
    		printf("Erreur lors de l'initialisation de la SDL\n\n");
    		SDL_Quit();
    		return -1;
    	}
     
    	SDL_Window* fenetre = 0;
    	fenetre = SDL_CreateWindow(
    	"Test SDL 2.0",
    	SDL_WINDOWPOS_UNDEFINED,
    	SDL_WINDOWPOS_UNDEFINED,
    	100,
    	100, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
     
    	if(fenetre == 0)
    	{
    		printf("Erreur lors de la creation de la fenêtre\n\n");
    		SDL_Quit();
    		return -1;
    	}
     
    	SDL_Delay(8000); // 8 secondes
     
    // teste Context opengl
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GLContext contexteOpenGL = 0;
    contexteOpenGL = SDL_GL_CreateContext(fenetre);
    float vertices[] = {-0.5, -0.5,   0.0, 0.5,   0.5, -0.5};
    int terminer = 0;
    while(!terminer)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    	glEnableVertexAttribArray(0);
    	glDrawArrays(GL_TRIANGLES, 0, 3);
    	glDisableVertexAttribArray(0);
    	SDL_GL_SwapWindow(fenetre);
    	SDL_Delay(8000); // 8 secondes
    	terminer = 1;
    }
    SDL_GL_DeleteContext(contexteOpenGL);
    // teste Context opengl
     
    	SDL_Delay(8000); // 8 secondes
     
     
    	SDL_Renderer* renderer = NULL;
    	renderer =  SDL_CreateRenderer(fenetre, 0, SDL_RENDERER_SOFTWARE);
    	SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    	SDL_RenderClear(renderer);
    	SDL_Rect r;
    	r.x = 35;
    	r.y = 35;
    	r.w = 30;
    	r.h = 30;
    	SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
    	SDL_RenderFillRect(renderer, &r);
    	SDL_RenderPresent(renderer);
     
    	SDL_Delay(8000); // 8 secondes
     
    	SDL_DestroyWindow(fenetre);
    	SDL_Quit();
     
    	return 0;
    }
    D'après un de mes anciens messages sur un autre forum: http://fr.sfml-dev.org/forums/index....74445#msg74445
    SDL 1.2 consommait 4-5 mb, une fois le contexte opengl ajouter il consommait 40 mb.

  5. #5
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Alors la question serait : combien le programme xcb prend en mémoire si on y rajoute un contexte OpenGL ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  6. #6
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut
    Pour être honnête j'ai jamais appris xlib/xcb donc je fais des copier coller d'internet mais normalement tout est bon.
    J'ai fait le teste sur xlib, si je me trompes pas xcb ne supporte pas encore opengl, xlib c'est celui qui est pondu par X xcb c'est juste l'équivalent de xlib qui cherche à le remplacer avec une meilleur utilisation, mais dans la base c'est pareil.


    En résumer:
    xlib c'est comme xcb: 1.4-1.8 mb
    xlib + opengl: 40 mb


    Voici les codes:
    gcc xlib.c -o xlib -l X11
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    /*
     * color-drawing.c - demonstrate drawing of pixels, lines, arcs, etc, using
     *		      different foreground colors, in a window.
     */
     
    #include <X11/Xlib.h>
     
    #include <stdio.h>
    #include <stdlib.h>		/* getenv(), etc. */
    #include <unistd.h>		/* sleep(), etc.  */
     
    /*
     * function: create_simple_window. Creates a window with a white background
     *           in the given size.
     * input:    display, size of the window (in pixels), and location of the window
     *           (in pixels).
     * output:   the window's ID.
     * notes:    window is created with a black border, 2 pixels wide.
     *           the window is automatically mapped after its creation.
     */
    Window
    create_simple_window(Display* display, int width, int height, int x, int y)
    {
      int screen_num = DefaultScreen(display);
      int win_border_width = 2;
      Window win;
     
      /* create a simple window, as a direct child of the screen's */
      /* root window. Use the screen's black and white colors as   */
      /* the foreground and background colors of the window,       */
      /* respectively. Place the new window's top-left corner at   */
      /* the given 'x,y' coordinates.                              */
      win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
                                x, y, width, height, win_border_width,
                                BlackPixel(display, screen_num),
                                WhitePixel(display, screen_num));
     
      /* make the window actually appear on the screen. */
      XMapWindow(display, win);
     
      /* flush all pending requests to the X server. */
      XFlush(display);
     
      return win;
    }
     
    GC
    create_gc(Display* display, Window win, int reverse_video)
    {
      GC gc;				/* handle of newly created GC.  */
      unsigned long valuemask = 0;		/* which values in 'values' to  */
    					/* check when creating the GC.  */
      XGCValues values;			/* initial values for the GC.   */
      unsigned int line_width = 2;		/* line width for the GC.       */
      int line_style = LineSolid;		/* style for lines drawing and  */
      int cap_style = CapButt;		/* style of the line's edje and */
      int join_style = JoinBevel;		/*  joined lines.		*/
      int screen_num = DefaultScreen(display);
     
      gc = XCreateGC(display, win, valuemask, &values);
      if (gc < 0) {
    	fprintf(stderr, "XCreateGC: \n");
      }
     
      /* allocate foreground and background colors for this GC. */
      if (reverse_video) {
        XSetForeground(display, gc, WhitePixel(display, screen_num));
        XSetBackground(display, gc, BlackPixel(display, screen_num));
      }
      else {
        XSetForeground(display, gc, BlackPixel(display, screen_num));
        XSetBackground(display, gc, WhitePixel(display, screen_num));
      }
     
      /* define the style of lines that will be drawn using this GC. */
      XSetLineAttributes(display, gc,
                         line_width, line_style, cap_style, join_style);
     
      /* define the fill style for the GC. to be 'solid filling'. */
      XSetFillStyle(display, gc, FillSolid);
     
      return gc;
    }
     
    int main(int argc, char* argv[])
    {
      Display* display;		/* pointer to X Display structure.           */
      int screen_num;		/* number of screen to place the window on.  */
      Window win;			/* pointer to the newly created window.      */
      unsigned int display_width,
                   display_height;	/* height and width of the X display.        */
      unsigned int width, height;	/* height and width for the new window.      */
      char *display_name = getenv("DISPLAY");  /* address of the X display.      */
      GC gc;			/* GC (graphics context) used for drawing    */
    				/*  in our window.			     */
      Colormap screen_colormap;     /* color map to use for allocating colors.   */
      XColor red, brown, blue, yellow, green;
    				/* used for allocation of the given color    */
    				/* map entries.                              */
      Status rc;			/* return status of various Xlib functions.  */
     
      /* open connection with the X server. */
      display = XOpenDisplay(display_name);
      if (display == NULL) {
        fprintf(stderr, "%s: cannot connect to X server '%s'\n",
                argv[0], display_name);
        exit(1);
      }
     
      /* get the geometry of the default screen for our display. */
      screen_num = DefaultScreen(display);
      display_width = DisplayWidth(display, screen_num);
      display_height = DisplayHeight(display, screen_num);
     
      /* make the new window occupy 1/9 of the screen's size. */
      width = (display_width / 3);
      height = (display_height / 3);
      printf("window width - '%d'; height - '%d'\n", width, height);
     
      /* create a simple window, as a direct child of the screen's   */
      /* root window. Use the screen's white color as the background */
      /* color of the window. Place the new window's top-left corner */
      /* at the given 'x,y' coordinates.                             */
      win = create_simple_window(display, width, height, 0, 0);
     
      /* allocate a new GC (graphics context) for drawing in the window. */
      gc = create_gc(display, win, 0);
      XSync(display, False);
     
      /* get access to the screen's color map. */
      screen_colormap = DefaultColormap(display, DefaultScreen(display));
     
      /* allocate the set of colors we will want to use for the drawing. */
      rc = XAllocNamedColor(display, screen_colormap, "red", &red, &red);
      if (rc == 0) {
        fprintf(stderr, "XAllocNamedColor - failed to allocated 'red' color.\n");
        exit(1);
      }
      rc = XAllocNamedColor(display, screen_colormap, "brown", &brown, &brown);
      if (rc == 0) {
        fprintf(stderr, "XAllocNamedColor - failed to allocated 'brown' color.\n");
        exit(1);
      }
      rc = XAllocNamedColor(display, screen_colormap, "blue", &blue, &blue);
      if (rc == 0) {
        fprintf(stderr, "XAllocNamedColor - failed to allocated 'blue' color.\n");
        exit(1);
      }
      rc = XAllocNamedColor(display, screen_colormap, "yellow", &yellow, &yellow);
      if (rc == 0) {
        fprintf(stderr, "XAllocNamedColor - failed to allocated 'yellow' color.\n");
        exit(1);
      }
      rc = XAllocNamedColor(display, screen_colormap, "green", &green, &green);
      if (rc == 0) {
        fprintf(stderr, "XAllocNamedColor - failed to allocated 'green' color.\n");
        exit(1);
      }
     
      /* draw one pixel near each corner of the window */
      /* draw the pixels in a red color. */
      XSetForeground(display, gc, red.pixel);
      XDrawPoint(display, win, gc, 5, 5);
      XDrawPoint(display, win, gc, 5, height-5);
      XDrawPoint(display, win, gc, width-5, 5);
      XDrawPoint(display, win, gc, width-5, height-5);
     
      /* draw two intersecting lines, one horizontal and one vertical, */
      /* which intersect at point "50,100".                            */
      /* draw the line in a brown color. */
      XSetForeground(display, gc, brown.pixel);
      XDrawLine(display, win, gc, 50, 0, 50, 200);
      XDrawLine(display, win, gc, 0, 100, 200, 100);
     
      /* now use the XDrawArc() function to draw a circle whose diameter */
      /* is 30 pixels, and whose center is at location '50,100'.         */
      /* draw the arc in a blue color. */
      XSetForeground(display, gc, blue.pixel);
      XDrawArc(display, win, gc, 50-(30/2), 100-(30/2), 30, 30, 0, 360*64);
     
      {
        XPoint points[] = {
          {0, 0},
          {15, 15},
          {0, 15},
          {0, 0}
        };
        int npoints = sizeof(points)/sizeof(XPoint);
     
        /* draw a small triangle at the top-left corner of the window. */
        /* the triangle is made of a set of consecutive lines, whose   */
        /* end-point pixels are specified in the 'points' array.       */
        /* draw the triangle in a yellow color. */
        XSetForeground(display, gc, yellow.pixel);
        XDrawLines(display, win, gc, points, npoints, CoordModeOrigin);
      }
     
      /* draw a rectangle whose top-left corner is at '120,150', its width is */
      /* 50 pixels, and height is 60 pixels.                                  */
      /* draw the rectangle in a black color. */
      XSetForeground(display, gc, BlackPixel(display, screen_num));
      XDrawRectangle(display, win, gc, 120, 150, 50, 60);
     
      /* draw a filled rectangle of the same size as above, to the left of the */
      /* previous rectangle.                                                   */
      /* draw the rectangle in a green color. */
      XSetForeground(display, gc, green.pixel);
      XFillRectangle(display, win, gc, 60, 150, 50, 60);
     
      /* flush all pending requests to the X server. */
      XFlush(display);
     
      /* make a delay for a short period. */
      sleep(4);
     
      /* close the connection to the X server. */
      XCloseDisplay(display);
      return(0);
    }
    gcc xlib-opengl.c -o xlib-opengl -l X11 -l GL
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    /*
     * simplest - simple single buffered RGBA xlib program.
     */
    /* compile: cc -o simplest simplest.c -lGL -lX11 */
     
    #include <GL/glx.h>
    #include <X11/keysym.h>
    #include <stdlib.h>
    #include <stdio.h>
     
    static int attributeList[] = { GLX_RGBA, None };
     
    static void
    draw_scene(void) {
        glClearColor(0.5, 0.5, 0.5, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0,0.0,0.0);
        glRectf(-.5,-.5,.5,.5);
        glColor3f(0.0,1.0,0.0);
        glRectf(-.4,-.4,.4,.4);
        glColor3f(0.0,0.0,1.0);
        glRectf(-.3,-.3,.3,.3);
        glFlush();
    }
     
    static void
    process_input(Display *dpy) {
        XEvent event;
        Bool redraw = 0;
     
        do {
            char buf[31];
            KeySym keysym;
     
            XNextEvent(dpy, &event);
            switch(event.type) {
            case Expose:
                redraw = 1;
                break;
            case ConfigureNotify:
                glViewport(0, 0, event.xconfigure.width, 
                        event.xconfigure.height);
                redraw = 1;
                break;
            case KeyPress:
                (void) XLookupString(&event.xkey, buf, sizeof(buf), 
                        &keysym, NULL);
                switch (keysym) {
     
                case XK_Escape:
                    exit(EXIT_SUCCESS);
                default:
                    break;
                }
            default:
                break;
            }
        } while (XPending(dpy));
        if (redraw) draw_scene();
    }
     
    static void
    error(const char *prog, const char *msg) {
        fprintf(stderr, "%s: %s\n", prog, msg);
        exit(EXIT_FAILURE);
    }
    int
    main(int argc, char **argv) {
        Display *dpy;
        XVisualInfo *vi;
        XSetWindowAttributes swa;
        Window win;
        GLXContext cx;
     
        /* get a connection */
        dpy = XOpenDisplay(0);
        if (!dpy) error(argv[0], "can't open display");
     
        /* get an appropriate visual */
        vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
        if (!vi) error(argv[0], "no suitable visual");
     
        /* create a GLX context */
        cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
        /* create a colormap */
        swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
                                       vi->visual, AllocNone);
        /* create a window */
        swa.border_pixel = 0;
        swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask;
        win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 300, 
                            300, 0, vi->depth, InputOutput, vi->visual,
                            CWBorderPixel|CWColormap|CWEventMask, &swa);
        XStoreName(dpy, win, "simplest");
        XMapWindow(dpy, win);
     
        /* connect the context to the window */
        glXMakeCurrent(dpy, win, cx);
     
        for(;;) process_input(dpy);
    }

  7. #7
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Il semble que cela prouve que les 40 Mo sont bien pour OpenGL. Quel pilote graphique est installé sur votre machine ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  8. #8
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut
    Nvidia v340

  9. #9
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    C'est peut être lié au chargement du pilote
    Enfin, je ne sais pas trop, mais la question est très intéressante. Je me demande ce qui se passe pour avoir une telle consommation de mémoire.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  10. #10
    Membre habitué
    Homme Profil pro
    root
    Inscrit en
    Janvier 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : root

    Informations forums :
    Inscription : Janvier 2013
    Messages : 174
    Points : 144
    Points
    144
    Par défaut
    Je sais pas.
    Avec le pilote libre "nouveau" c'est 20 mb, mais ce pilote supporte juste opengl 3.0 et pas supérieur (ce qui limite le développement 3d) et niveau performance c'est environs 5 fois moins puissant (mais pour utilisation normal c'est suffisant).

    Faut voir si chez les autres ça ce passe comment, dernièrement j'avais rien trouvé sur google, comme ci j'étais seul à remarquer.

Discussions similaires

  1. Réponses: 5
    Dernier message: 24/06/2014, 13h34
  2. [MFC] Utilisation mémoire
    Par CTux dans le forum MFC
    Réponses: 10
    Dernier message: 08/07/2005, 09h58
  3. Utilisation Mémoire d'une application
    Par scorplex dans le forum Composants VCL
    Réponses: 8
    Dernier message: 21/05/2005, 03h01
  4. Gestion de la mémoire entre plusieurs DLL
    Par Laurent Gomila dans le forum C++
    Réponses: 7
    Dernier message: 27/07/2004, 15h28
  5. Partage de blocs mémoire entre 2 processus
    Par rolkA dans le forum Windows
    Réponses: 6
    Dernier message: 18/11/2003, 19h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo