giovedì 13 dicembre 2012

Windows application with console

se stai usando una windows application come entry point per l'applicazione e vuoi anche una console

#include <iostream>
#include <string>
#include <cstdio>
#include <windows.h>
#include <io.h>
#include <fcntl.h>

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (AllocConsole()) {
int ifd = _open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
int ofd = _open_osfhandle((intptr_t)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);

*stdin = *_fdopen(ifd, "r");
*stdout = *_fdopen(ofd, "w");

std::cout<<"I made a console window";
std::cin.get();

fclose(stdout);
fclose(stdin);
}
}

Reference:
http://www.daniweb.com/software-development/cpp/threads/347901/is-it-possible-to-use-a-console-app-and-windows-one-at-the-same-time

venerdì 7 dicembre 2012

OpenGL su windows 7

alcuni appunti per installare OpenGL su windows 7
il mio pc è un po' datato quindi supporta fino alla 2.1

1. ricordarsi che con windows opengl sono supportate a livello driver e dovrebbero esser già nel sistema operativo, meglio comunque aggiornare i driver della propria scheda grafica.

2. per esser sicuro si può installare opengl extension viewer che testa quali opengl si possono utilizzare con i driver grafici installati.

3. preso da internet alcuni appunti sulle opengl


We need the following sets of libraries in programming OpenGL:
  1. Core OpenGL (GL): consists of hundreds of functions, which begin with a prefix "gl" (e.g., glColor, glVertex, glTranslate, glRotate). The Core OpenGL models an object via a set of geometric primitives, such as point, line, and polygon.
  2. OpenGL Utility Library (GLU): built on-top of the core OpenGL to provide important utilities and more building models (such as qradric surfaces). GLU functions start with a prefix "glu" (e.g., gluLookAt, gluPerspective)
  3. OpenGL Utilities Toolkit (GLUT): provides support to interact with the Operating System (such as creating a window, handling key and mouse inputs); and more building models (such as sphere and torus). GLUT functions start with a prefix of "glut" (e.g., glutCreatewindow, glutMouseFunc). 
  4. Quoting from the opengl.org: "GLUT is designed for constructing small to medium sized OpenGL programs. While GLUT is well-suited to learning OpenGL and developing simple OpenGL applications, GLUT is not a full-featured toolkit so large applications requiring sophisticated user interfaces are better off using native window system toolkits. GLUT is simple, easy, and small."
  5. Alternative of GLUT includes SDL, ....
  6. OpenGL Extension Wrangler Library (GLEW): "GLEW is a cross-platform open-source C/C++ extension loading library. GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform." Source and pre-build binary available at http://glew.sourceforge.net/.
  7.  installazione di glut per la parte grafica.


Reference

http://www.hackorama.com/opengl/
http://www.opengl.org/resources/libraries/glut/
http://www3.ntu.edu.sg/home/ehchua/programming/opengl/HowTo_OpenGL_C.html
http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/