Programowanie w systemie UNIX/Cpp: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
opengl
→‎OpenGl: nowy kod
Linia 40:
#include <iostream>
 
using namespace std;
unsigned int win_w = 0;
unsigned int win_h = 0;
unsigned int mouse_x = 0;
unsigned int mouse_y = 0;
 
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
glMatrixMode(GL_PROJECTION);
Linia 68 ⟶ 65:
glPopMatrix();
 
unsigned char pixel[3];
glReadPixels(mouse_x, mouse_y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
std::cout << "R: " << (int)pixel[0] << std::endl;
std::cout << "G: " << (int)pixel[1] << std::endl;
std::cout << "B: " << (int)pixel[2] << std::endl;
std::cout << std::endl;
 
glFlush();
glutSwapBuffers();
}
Linia 81 ⟶ 70:
void motion(int x, int y)
{
y = glutGet( GLUT_WINDOW_HEIGHT ) - y;
mouse_x = x;
mouse_y = win_h - y;
glutPostRedisplay();
}
 
unsigned char pixel[34];
void reshape(int w, int h)
glReadPixels(mouse_xx, mouse_yy, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
{
std::cout << "R: " << (int)pixel[0] << std::endl;
win_w = w;
std::cout << "G: " << (int)pixel[1] << std::endl;
win_h = h;
std::cout << "B: " << (int)pixel[2] << std::endl;
glViewport(0, 0, w, h);
std::cout << std::endl;
}
 
int main(int argc, char **argv)
{
glutInitWindowSize(640,480);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
 
glutInitWindowSize(640,480);
glutCreateWindow("glReadPixels()");
 
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutPassiveMotionFunc(motion);
glutMainLoop();