[C++][SDL][OpenGL]Culori

Ai făcut un program și vrei să ne arați și nouă? Vrei să te lauzi cu priceperea ta în programare? Vrei să îți dăm un feedback sau unele sugestii în legătură cu aplicația ta? Haide, arată-ne şi noi te vom ajuta să-ți finisezi creațiile.

[C++][SDL][OpenGL]Culori

Postby jolgau » 04 Jan 2012, 17:02

Tocmai m-am apucat sa invat SDL si am creat un program care sa schimbe culorile apasand pe tastele q,w,e,a,s,d,z,x.

  1. #include "SDL.h"
  2. #include "SDL_opengl.h"
  3.  
  4. int main(int argc, char* args[])
  5. {
  6.     SDL_Init(SDL_INIT_EVERYTHING);
  7.  
  8.     SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
  9.     SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
  10.     SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
  11.     SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
  12.     SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32);
  13.     SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
  14.     SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
  15.  
  16.     SDL_WM_SetCaption("Color", NULL);
  17.  
  18.     SDL_SetVideoMode(600, 400, 32, SDL_OPENGL );
  19.  
  20.     glClearColor(1,1,1,1);
  21.     glViewport(0,0,600,400);
  22.  
  23.     glShadeModel(GL_SMOOTH);
  24.  
  25.     glMatrixMode(GL_PROJECTION);
  26.     glLoadIdentity();
  27.  
  28.     glDisable(GL_DEPTH_TEST);
  29.  
  30.     bool isRunning = true;
  31.  
  32.     SDL_Event event;
  33.  
  34.     while( isRunning )
  35.        {
  36.         // Event
  37.         while( SDL_PollEvent(&event) )
  38.             {
  39.              if ( event.type == SDL_QUIT )
  40.                 {
  41.                   isRunning = false;
  42.                 }
  43.              if (event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)
  44.                 {
  45.                   isRunning = false;
  46.                 }
  47.              if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_q)
  48.                 {
  49.                   glClearColor(1,0,0,1);
  50.                 }
  51.              if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_w)
  52.                 {
  53.                   glClearColor(0,1,0,1);
  54.                 }
  55.              if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_e)
  56.                 {
  57.                   glClearColor(0,0,1,1);
  58.                 }
  59.              if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_a)
  60.                 {
  61.                   glClearColor(0,0,0,1);
  62.                 }
  63.              if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_s)
  64.                 {
  65.                   glClearColor(1,1,1,1);
  66.                 }
  67.             if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_d)
  68.                {
  69.                    glClearColor(1,0,1,1);
  70.                }
  71.             if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_z)
  72.                {
  73.                    glClearColor(1,1,0,1);
  74.                }
  75.             if(event.type = SDL_KEYUP && event.key.keysym.sym == SDLK_x)
  76.                {
  77.                    glClearColor(0,1,1,1);
  78.                }
  79.             }
  80.        // Render
  81.        glClear(GL_COLOR_BUFFER_BIT);
  82.  
  83.        SDL_GL_SwapBuffers();
  84.        }
  85.  
  86.     SDL_Quit();
  87.  
  88.     return 0;
  89. }


Sursa/executabil (TOT) :http://www.2shared.com/file/FVyR39ID/Color_C.html
0,0p / 0 votes
User avatar
jolgau
Bit
 
Joined: 11 Dec 2010
Status: 0

Re: [C++][SDL][OpenGL]Culori

Postby Cosmin_NTG » 04 Jan 2012, 20:39

Ok! Destul de interesant insa poti si sa explici ce face fiecare functie in parte? I mean, arata-ne ca asta nu e doar un exemplu care ilustreaza functionarea corecta a SDL-ului. No offense :D.


L.E. (-- 04 Jan 2012, 19:39 --)

Eu utilizez SFML (acronimul de la Simple and Fast Multimedia Library). In vreo 2 saptamani (in care nu am abordat o maniera destul de consecventa pentru a invata utilitatea acestei biblioteci) am reusit sa creez un fel de music player: se deschide o fereastra cu 4 butoane pe care scrie Play, Pause, Stop si in dreapta jos un buton pe care scrie Quit. Daca dai click pe Play incepe sa se auda o piesa de-a lui ATB (:D). Pause -> piesa se opreste dar se reia din locul de unde a fost oprita in urma "tastarii" butonului Play iar Stop -> are functia uzuala. Partea proasta e ca doar o singura piesa poate fi redata (dar pentru inceput, eu zic ca e promitator). Imi pusesem in minte odata sa pun codul sursa pe forum (chiar la aceasta categorie) dar codul nu avea un aspect...agreabil, ca sa zic asa.

Aici este executabilul si fisierele care contribuie la functionalitatea acestuia: http://www.2shared.com/file/8eqFH_p4/msplyr.html. Incearca sa creezi ceva asemanator cu SDL. Eu unul invat altfel cand am un scop concret.
0,0p / 0 votes
Thinking about solutions is better than thinking about problems
User avatar
Cosmin_NTG
Byte
 
Joined: 11 Jan 2011
Location: 192.2L1.44G
Status: 10

Re: [C++][SDL][OpenGL]Culori

Postby eric56 » 05 Jan 2012, 23:54

Ce frumos! Cosmin_Ntg l-am INCERCAT si eu :)
0,0p / 0 votes
Respecta si vei fi respectat
User avatar
eric56
Bit
 
Joined: 19 Dec 2011
Status: 0

Re: [C++][SDL][OpenGL]Culori

Postby andreiandreiq » 06 Jan 2012, 01:22

Interesante amândouă realizările, "m-am jucat un pic cu ele".

Cosmin, am o întrebare: De la ce vine "DNG Programmer's" ? Am văzut că scrie în coltul din stânga jos.. și sunt curios. :-?
0,0p / 0 votes
Image
User avatar
andreiandreiq
Word
 
Joined: 30 Dec 2009
Status: 33.33

Re: [C++][SDL][OpenGL]Culori

Postby Cosmin_NTG » 06 Jan 2012, 13:55

:)). Dap. That's a good question. Este un nume al unei companii (pe care sper sa o conduc in viitorul indepartat-oarecum). Stiu ca o sa radeti de mine dar mie imi place cum suna. Mai concret, este numele companiei pe care vreau sa o construiesc. Am realizat si unele demersuri in acest sens (de ordin minor, evident). Odata transformasem DNG-ul intr-un acronim (Dynamic Nearby Generation) dar am renuntat ulterior la asta pentru ca nu mi s-a parut potrivit. In orice caz nu am luat programul de la vreo firma cu numele asta (daca la asta te gandeai) sau ceva de genul; pot posta codul daca vrei dar, cum am mai zis, nu prea e inteligibil.
0,0p / 0 votes
Thinking about solutions is better than thinking about problems
User avatar
Cosmin_NTG
Byte
 
Joined: 11 Jan 2011
Location: 192.2L1.44G
Status: 10


Return to Programe facute de noi

Who is online

Users browsing this forum: No registered users and 0 guests

cron