Пятница, 26 Апреля 2024, 05:35

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Форум игроделов » Программирование » C/C++ » Графика в консольном приложении (VC6)
Графика в консольном приложении
АкунёкДата: Суббота, 05 Марта 2011, 10:33 | Сообщение # 1
был не раз
Сейчас нет на сайте
Уважаемые, хотелось бы узнать как можно рисовать линии, кружочки и.т.п в VC6, так же иметь цветной(всмысле с возможностью менять цвет символов, фона символов) текстовый режим. Интернет кишит кодами с graphics.h, но отказаться от VC6 я не могу в силу своих убеждений happy .

Stas96Дата: Суббота, 05 Марта 2011, 10:50 | Сообщение # 2
Programmer and Game Designer
Сейчас нет на сайте
Quote (Акунёк)
всмысле с возможностью менять цвет символов, фона символов

Вот скачай:Клац С помощью этих файлов можно менять цвет фона, цвет текста и т.д
Пример проги:
Code
#include <iostream>        

//#include "stdafx.h"
#include "console.h"
         
using namespace std; //используем пространство имен std        
int main()        
{        
setcolor( white, red ); //Первый параметр - цвет фона. Второй параметр - цвет букв. Устанавливаем цвет для текста:
cout << " Hi!!!.\n";       
setcolor( black, white);  //Возвращаем прежднии параметр консоли(Устанавливаем цвет фона - черный. Цвет текста - белый)
           
return 0;    
}

P.S. Только надо кинуть файлы в папку с проектом...


Сообщение отредактировал Stas96 - Суббота, 05 Марта 2011, 10:55
Kefir87Дата: Суббота, 05 Марта 2011, 10:52 | Сообщение # 3
участник
Сейчас нет на сайте
Quote
msoftcon.h

Сам не использовал, но вроде, как должно помочь
ezhickovichДата: Суббота, 05 Марта 2011, 10:52 | Сообщение # 4
[Великий и могучий хозяинъ]
Сейчас нет на сайте
WinAPI использовать религия запрещает?


Я: О великий повелитель этой ничтожной вселенной - сокращённо ЁЖ!
АкунёкДата: Суббота, 05 Марта 2011, 11:27 | Сообщение # 5
был не раз
Сейчас нет на сайте
Quote (ezhickovich)
WinAPI использовать религия запрещает?

Например...?

Поведайте что-нибудь о bgi happy


nilremДата: Суббота, 05 Марта 2011, 11:40 | Сообщение # 6
Просветленный разум
Сейчас нет на сайте
Code
#include <Windows.h>

int main()
{
  HWND handle = FindWindow(L"ConsoleWindowClass", NULL);
  HDC dc = GetDC(handle);
  Rectangle(dc,100,100,200,200);
  RoundRect(dc,200,100,300,200,100,100);
  SetPixel(dc,50,50,RGB(255,0,0));
//  MoveToEx(dc,51,51,NULL);
//  LineTo(dc,101,51);
  system("pause");
  return 0;
}

Линии чето не рисует, придется точками или через Polyline


Windmill 2

WindMill 2D Game Engine
АкунёкДата: Суббота, 05 Марта 2011, 11:49 | Сообщение # 7
был не раз
Сейчас нет на сайте
Вот как работает msoftcon biggrin :

Вооо, API - это круто happy


ezhickovichДата: Суббота, 05 Марта 2011, 13:45 | Сообщение # 8
[Великий и могучий хозяинъ]
Сейчас нет на сайте
Можно вообще с помощью ГЛ рисовать...
Code
#include <Windows.h> // Win32 API header
#include <cstdio> // Standart C IO
#include <GL\GL.h> // OpenGL header

HWND hWND = NULL; // Window handle
HDC hDC = NULL; // Device context
HGLRC hGLRC = NULL; // OpenGL rendering context

// Returns console handle
HWND GetConsoleHandle ()
{
  HWND conHwnd = NULL; // Console handle
  const short BUFSIZE = 1024; // Buffer size
  char oldWindowTitle[BUFSIZE]; // Old console window title
  char newWindowTitle[BUFSIZE]; // New console window title

  GetConsoleTitleA (oldWindowTitle, BUFSIZE); // Getting window title
  sprintf (newWindowTitle, "%d/%d", // Generating new title
     GetTickCount(),
     GetCurrentProcessId());

  SetConsoleTitleA (newWindowTitle); // Setting new window title
  Sleep(40); // Waiting for some time
  conHwnd = FindWindowA (NULL, newWindowTitle); // Searching for window
  SetConsoleTitleA (oldWindowTitle); // Setting old window title

  return conHwnd; // Returning handle
}

// Creates GL rendering context
bool CreateGLContext ()
{
  unsigned pixelFormat;

  // Getting device context
  if (!(hDC = GetDC (hWND)))
  {
   MessageBox (NULL, L"Failed to get device context!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   return false;
  }

  // Pixel format
  static    PIXELFORMATDESCRIPTOR pfd =
  {
   sizeof(PIXELFORMATDESCRIPTOR), 1,
   PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32,
   0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0,    0, 0, 0
  };

  // Searching for valid pixel format
  if (!(pixelFormat = ChoosePixelFormat (hDC, &pfd)))
  {
   MessageBox (NULL, L"Failed to choose valid pixel format!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   return false;
  }

  // Setting pixel format
  if (!SetPixelFormat (hDC, pixelFormat, &pfd))
  {
   MessageBox (NULL, L"Failed to set pixel format!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   return false;
  }

  // Creating render context
  if (!(hGLRC = wglCreateContext (hDC)))
  {
   MessageBox (NULL, L"Failed to create render context!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   return false;
  }

  // Setting render context
  if (!wglMakeCurrent (hDC, hGLRC))
  {
   MessageBox (NULL, L"Failed to set render context!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   return false;
  }

  return true;
}

// Creates GL rendering context
bool KillGLContext ()
{
  bool result = true; // By default it all will be ok

  // If GL render context was created
  if (hGLRC)
  {
   // Releasing render and device contexts
   if (!wglMakeCurrent (NULL, NULL))
   {
    MessageBox (NULL, L"Failed to release render and device contexts!",  
       L"Fuuuuck!", MB_OK | MB_ICONERROR);
    result = false;
   }
   // Deleting render context
   if (!wglDeleteContext (hGLRC))
   {
    MessageBox (NULL, L"Failed to delete render context!",  
       L"Fuuuuck!", MB_OK | MB_ICONERROR);
    result = false;
   }
   hGLRC = NULL; // Setting pointer to zero
  }

  // Releasing device context
  if (hDC && !ReleaseDC (hWND, hDC))
  {
   MessageBox (NULL, L"Failed to release device context!",  
      L"Fuuuuck!", MB_OK | MB_ICONERROR);
   result = false;
   hDC = NULL;
  }

  return result;
}

// Sets default GL params
bool SetDefaultGLParams ()
{
  glShadeModel(GL_SMOOTH);
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClearDepth(1.0f);
  glDisable(GL_DEPTH_TEST);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  return true;
}

// Draws scene
void DrawScene ()
{
  // Clearing screen
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity ();

  // Drawing triangle
  glBegin(GL_TRIANGLES);
   glColor3f(1.0f, 0.0f, 0.0f);
   glVertex3f( 0.0f, 1.0f, -1.0f);
   glColor3f(0.0f, 1.0f, 0.0f);
   glVertex3f(-1.0f, -1.0f, -1.0f);
   glColor3f(0.0f, 0.0f, 1.0f);
   glVertex3f( 1.0f, -1.0f, -1.0f);
  glEnd ();
}

// Win32 main
int main (int argc, char **argv)
{
  bool play = true; // Mainloop flag
  MSG msg; // Message

  // Hiding cursor
  HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
  CONSOLE_CURSOR_INFO cursorInfo = {1, false};
  SetConsoleCursorInfo (hOut, &cursorInfo);

  printf ("Yeahh! Its a console window!\n"); // Some printing

  hWND = GetConsoleHandle (); // Getting window handle
  // Creating render context and printing result
  printf ("Creating GL rendering context: %s\n", ((play = CreateGLContext ()) ? "OK" : "FAILED"));
  // Setting default GL params and printing result
  printf ("Setting default GL params: %s\n", ((play = SetDefaultGLParams ()) ? "OK" : "FAILED"));
  Sleep (300);
  while (play) // Mainloop
  {
   // Processing message
   if (PeekMessage (&msg, hWND, NULL, NULL, PM_REMOVE))
   {
    if (msg.message == WM_QUIT) play = false;
    else
    {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
    }
   } else
   {
    // Rendering scene
    DrawScene ();
    SwapBuffers (hDC);

    // Some printing
    system ("CLS");
    printf ("\n\n\nHello, sexy boy!");
    //Sleep (45);
   }
  }

  // Killling render context and printing result
  printf ("Killing GL rendering context: %s\n", KillGLContext () ? "OK" : "FAILED");
  Sleep (200);
  return 0;
}




Я: О великий повелитель этой ничтожной вселенной - сокращённо ЁЖ!


Сообщение отредактировал ezhickovich - Суббота, 05 Марта 2011, 13:57
АкунёкДата: Суббота, 05 Марта 2011, 14:50 | Сообщение # 9
был не раз
Сейчас нет на сайте
Quote (ezhickovich)
Можно вообще с помощью ГЛ рисовать...

Я преданный поклонник DirectX'a happy , но спасибо за науку, мб пригодится)


Форум игроделов » Программирование » C/C++ » Графика в консольном приложении (VC6)
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг