Trying to create this seemingly simply program and make it draw.
It is a pseudocode example from the text book.
It compiles and runs without errors, but all I get is a blank white screen.
It should be drawing GL_LINE_STRIPs.
Suggestions??
Thanks.
// Experiment 2
// Experimentation with scaling and translation
// 6 Oct 2015
#include <windows.h>
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
#include <gl/Gl.h>
#include <gl/Glu.h>
#include <gl/Glut.h>
using namespace std;
#define PI 3.14159265
// ******************************************************************
// Global Variables
const float screenWidth = 800.0; // max screen width in pixels
const float screenHeight = 600.0; // max screen height in pixels
float color[] = { 0.0, 0.0, 0.0 }; // color
GLdouble A = screenWidth / 4.0; // scaling and translation variables
GLdouble B = 0.0;
GLdouble C = screenHeight / 2.0;
GLdouble D = C;
// ******************************************************************
// Function Declarations
void myInit(void); // my initialization routine
void myDisplay(void); // the redraw function
void Random_Color(); // generate a random color
float f(float x); // any f(x) I want
void Print_Msg(int, char*); // Print messages to screen
// ******************************************************************
int main(int argc, char* argv[])
{
srand(time(NULL)); // seed RNG
Random_Color(); // gen a random color for drawing
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode
glutInitWindowSize(screenWidth, screenHeight); // set the window size
glutInitWindowPosition(0, 0); // set window starting position
glutCreateWindow("Experiment 2"); // open the screen window
glutDisplayFunc(myDisplay); // register the redraw function
myInit(); // call my initialization routine
glFlush();
glutMainLoop(); // go into a perpetual loop
}
// ******************************************************************
// START FUNCTION DEFINITIONS
// ******************************************************************
// ******************************************************************
// myInit()
void myInit(void) {
glClearColor(1.0, 1.0, 1.0, 0.0); // the background color is white
// glColor3f(0.0f, 0.0f, 0.0f); // the drawing color is black
glPointSize(2.0); // a 'dot' is 2 by 2 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, screenWidth, 0.0, screenHeight);
}
// ******************************************************************
// myDisplay()
void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glColor3f(color[0], color[1], color[2]); // set drawing color
glBegin(GL_LINE_STRIP); // Draw line strips
for (int x = 0; x <= 300; x += 3) { // scaled and
glVertex2d(A * x + B, C * f(x) + D); // translated
}
glEnd();
glFlush(); // send all output to display
}
// ******************************************************************
// Random_Color()
void Random_Color(void) {
// This routine will generate a random color and store it in color[0-2].
// color[] is a global array of floats.
for (int c = 0; c < 3; c++) { color[c] = ((float)(rand() % 100) / 100); }
}
// ******************************************************************
// f()
float f(float x) {
// any f(x) I want
return cos(2 * PI * x);
}
// ******************************************************************
// Add next function here
// ******************************************************************
// Print_Msg()
void Print_Msg(int Msg, char* Message) {
// Receives an Int value and a char string
// If the INT is zero, simply print the string argument.
// If the INT is non-zero, print the corresponding message from the
// list below, ignoring the string, if any, supplied as the 2nd arg.
switch (Msg) {
case 0: cout << endl << Message; // print msg as given
break;
case 1: cout << endl << "Error 1" << endl; // Placeholder
break;
case 2: cout << endl << "Error 2" << endl; // Placeholder
break;
default: break;
} // end SWITCH
cout << endl; // pad a line before returning
} // end function. Returns nothing.