sorry for the bad phrasing of the question, i don't know what i'm talking about.. i'm making a project for my graphics class and i'm kinda stuck with an issue.
#include <GL/glut.h>
#include <iostream>
void display();
void init();
void reshape(int, int);
void mouseFunc(int, int, int, int);
const int XMAX = 600;
const int YMAX = 600;
const int GRID_SIZE = 20;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(XMAX, YMAX);
glutCreateWindow("test pgm");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouseFunc);
init();
glutMainLoop();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glPointSize(14); //POINT SIZE
#pragma region draw_here
glBegin(GL_POINTS);
float grid_x = GRID_SIZE - 1;
float grid_y = GRID_SIZE - 1;
for (float x = -grid_x; x < GRID_SIZE; x++)
{
for (float y = grid_y; y > -GRID_SIZE; y--)
{
glVertex2f(x, y);
}
}
glEnd();
#pragma endregion
glFlush();
}
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE);
glMatrixMode(GL_MODELVIEW);
}
void mouseFunc(int button, int state, int mouse_x, int mouse_y)
{
int x = -GRID_SIZE - (XMAX / (mouse_x + 1) * 20);
int y = GRID_SIZE - (YMAX / (mouse_y + 1) * 20);
if(state == 0)
std::cout << "button:" << button << "\nstate:" << state << "\n(x,y):(" << x << "," << y << ")\n------\n";
}
my desired output would be the coordinates i used to draw the pixels in the loops in the draw_here region for eg: clicking the yellow box on top left of output window should give the coordinates (-19, 19). i'm trying to demonstrate a path finding algorithm and i want to draw the obstacles and specify starting and ending locations using mouse clicks. i would eventually want to store the coordinates and relevant data in a array object and iterate through them as needed, i'm only in the prototyping phase right now.