Graphics in C++ [closed]

Closed. It is impossible to give an objective answer to this question . Answers to it are not accepted at the moment.

Want to improve this question? Reformulate the question so that it can be answered based on facts and quotations.

Closed 5 years ago.

Improve the question

There is a task: to write a program with a graphical interface. Use C++ in conjunction with OpenGL or DirectX.

Tell me where you can get information on this topic.

Author: Nicolas Chabanovsky, 2011-02-15

5 answers

According to the C++/DirectX bundle, a high - quality source of information is MSDN.

DirectX Tutorial is a good resource.

Besides:

 10
Author: stanislav, 2011-02-15 20:02:33

Qt to help you

 4
Author: savva, 2013-05-21 12:21:52

Http://www.opengl.org/ The official website, there just needs to be a LOT of information, of course in English). It seems that there were lessons at NeHe, but I did not succeed with them. Russian-language resources are game dev.

 3
Author: Сергей, 2011-02-18 15:09:51

There is also a certain unity. There are opengl for c#, and much more. Suddenly useful:)

 0
Author: MaxXx1313, 2013-05-21 13:19:39

To begin with, we recommend using opengl, as it is simpler and more compact.

Here is a full working example of the simplest application. The SDL library is used. For opengl, this is the same as STL for C++. Provides a convenient event handler, working with sound, devices.

Reference to SDL.

Draws a red square on a black background.

#define МАКСИМУМ_КНОПОК 423
bool нажатые_кнопки[МАКСИМУМ_КНОПОК];

#include <iostream>
#include <string>
#include <cstdlib>

#include <sdl/include/SDL.h>
#include <sdl/include/SDL_mixer.h>
#include <sdl/include/SDL_syswm.h>
#undef main

#include <GL/glew.h>
#include <GL/glut.h>

#pragma comment (lib , "sdl.lib")

int ширина_экрана = 1920;
int высота_экрана = 1080;

bool приложение_выполняется = true;

int OnEvent(SDL_Event* Event)
{
if(Event->type == SDL_KEYDOWN)
{
std::cout << "\nsym=" << (int)Event->key.keysym.sym;
нажатые_кнопки[Event->key.keysym.sym] = true; }
if(Event->type == SDL_KEYUP){нажатые_кнопки[Event->key.keysym.sym] = false; }
return true;
}

// события
SDL_Event Event;
inline void events(){while(SDL_PollEvent(&Event)){OnEvent(&Event);}}

void base_draw()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor4f(1,1,1,1);// важно
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, ширина_экрана, 0.0, высота_экрана, -1550000, 1500000);
  glEnable(GL_DEPTH_TEST);
}

int глубина_цвета = 32;

int _tmain(int argc, _TCHAR* argv[])
{
std::system("chcp 1251");

SDL_Surface * Surf_Display = NULL;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {return 0;}
  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);

  glMatrixMode(GL_PROJECTION);
  glEnable(GL_TEXTURE_2D);
  glLoadIdentity();

  unsigned int flags =  SDL_OPENGL | SDL_RESIZABLE;
  if((Surf_Display = SDL_SetVideoMode(ширина_экрана, высота_экрана, глубина_цвета, flags)) == NULL){return 0;}

  glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // цвет экрана при очищении

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor4f(1,1,1,1);// важно
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glEnable(GL_DEPTH_TEST);

while(приложение_выполняется==true)
{
events();
base_draw();

glColor4ub(255, 0, 0, 255);
glRectd(500 , 500 , 1000 , 1000);

SDL_GL_SwapBuffers();
};

std::system("pause");
return 0;
}
 0
Author: manking, 2013-05-21 13:53:56