There are many mistakes here, as stated in an earlier post. It’s easiest to walk through your code from top to bottom.
First of all get rid of (most of) the header files. Your program only needs to include glut.h and stdlib.h
glut.h makes sure the appropriate headers (such as windows.h ) are included.
In your myinit function you set your drawing color to black. This is allright, but this is something you typically want to do in your display function (which you lack, but more on that later).
Your init function then sets the Projection Matrix. Three things on this:
- You don’t want to do this here. Instead, put this in a reshape function. The reshape function is called whenever the screen is resized.
- You might want to set up a viewport too (glViewport) (also in the reshape function, and prior to switching to the projection matrix).
- After setting the perspective, switch back to the modelview matrix again, to make sure you are working with the correct matrix. Restoring the modelview matrix to the identity matrix is an option, but you’ll have to decide whether or not this is what you want.
myMouse function:
Your intention, if I understand correctly, is to let the user click on the screen, remember the coordinates, and draw (stipled) lines on the screen.
Actually your mouse function also holds the display code. It is best (I do not know if it is arbitrary) to take these two apart. Your display function then handles the drawing, and your mouse function keeps a list of coordinates.
Keep in mind that the GL_LINES* function needs two calls to glVertex* in order to draw a line. Using a for loop you can make the ‘dots’ connect.
Separation of the mouse and display functions requires you to make your variables List and last global(!). In this case it is ok to do that. The definition of NUM (smart, although I would call it MAX_POINTS or something like that) should really go before your function definitions.
One more remark about drawing. Drawing always occurs between glBegin and glEnd function calls.
The glClear function allows you to clear multiple buffers by using |. Your two lines of code clearing all could also be
glClear(COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT) (in this case you have no depth buffer, but as an illustration). Reviewing your code I think the second call to glClear you did is a mistake and that you meant to call glBegin.
The main function looks allright, however call myinit() gefore you assign your glut functions. Remember that the main function should return an integer (0).
Ok this is quite a long post. Don’t be discouraged though and just keep trying.
Regards,
Ritchie