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
|
// Request a 24-bits depth buffer when creating the window
sf::ContextSettings contextSettings;
contextSettings.depthBits = 24;
// Create the main window
sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings);
// Make it the active window for OpenGL calls
window.setActive();
//initialisation etats OPENGL
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 1.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// BOUCLE DES MESSAGES
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Escape:
{
window.close();
break;
}
default: {}
}
}
if (event.type == sf::Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
//----------------------------------------
// première viewport 500/480
//-----------------------------------------
glViewport(0, 0, 500, 480); //xinfG,yinfG,Larg,Hauteur)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)500 / (GLfloat)480, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, -3.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-1.0, -1.0, 0.0); //IG
glVertex3f(1.0, -1.0, 0.0); //ID
glVertex3f(1.0, 1.0, 0.0); //SD
glVertex3f(-1.0, 1.0, 0.0); //SG
glEnd();
window.display(); //swap
//------------------------------------
// second viewport
//------------------------------------
glViewport(500, 0, 140, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)500 / (GLfloat)480, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, -3.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(0.0, 1.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-1.0, -1.0, 0.0); //IG
glVertex3f(1.0, -1.0, 0.0); //ID
glVertex3f(1.0, 1.0, 0.0); //SD
glVertex3f(-1.0, 1.0, 0.0); //SG
glEnd();
window.display(); //swap
}
return 0; |
Partager