PDA

View Full Version : Drawing the letter A shape help



krazyb
02-23-2015, 09:50 PM
Hi i am new here and i am having trouble trying to draw the letter A shape. I have vertices but i can not figure where they go. Here is my code...



#include "glew.h"
#include "freeglut.h"
#include "glext.h"
#pragma comment(lib, "glew32.lib")

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

static int isWire = 0; // Is wireframe?

// Drawing routine.
void drawScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 0.0, 0.0);

// Draw a polygon with specified vertices.
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//if (isWire) glPolygonMode(GL_FRONT, GL_LINE); else glPolygonMode(GL_FRONT, GL_FILL);
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(10.0, 20.0, 0.0);
glVertex3f(18.0, 36.0, 0.0);
//glVertex3f(14.0, 20.0, 0.0);
//glVertex3f(12.0, 24.0, 0.0);
//glVertex3f(16.0, 24.0, 0.0);
//glVertex3f(14.0, 28.0, 0.0);
//glVertex3f(18.0, 28.0, 0.0);

//glVertex3f(20.0, 32.0, 0.0);

//glVertex3f(16.0, 32.0, 0.0);


//glVertex3f(24.0, 32.0, 0.0);
//glVertex3f(22.0, 36.0, 0.0);
//glVertex3f(20.0, 32.0, 0.0);
//glVertex3f(26.0, 28.0, 0.0);
//glVertex3f(22.0, 28.0, 0.0);
//glVertex3f(28.0, 24.0, 0.0);
//glVertex3f(24.0, 24.0, 0.0);
//glVertex3f(30.0, 20.0, 0.0);
//glVertex3f(26.0, 20.0, 0.0);

glEnd();

glFlush();
}

// Initialization routine.
void setup(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}

// OpenGL window reshape routine.
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

// Keyboard input processing routine.
/*void keyInput(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
default:
break;
}
}*/

// Keyboard input processing routine.
void keyInput(unsigned char key, int x, int y)
{
switch (key)
{
case ' ':
if (isWire == 0) isWire = 1;
else isWire = 0;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}

// Routine to output interaction instructions to the C++ window.
void printInteraction(void)
{
cout << "Interaction:" << endl;
cout << "Press the space bar to toggle between wirefrime and filled for the lower annulus." << endl;
}

// Main routine.
int main(int argc, char **argv)
{
glutInit(&argc, argv);

glutInitContextVersion(3, 3);
glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE) ;

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("square.cpp");
glutDisplayFunc(drawScene);
glutReshapeFunc(resize);
glutKeyboardFunc(keyInput);

glewExperimental = GL_TRUE;
glewInit();

setup();

glutMainLoop();
}

Carmine
02-24-2015, 10:24 AM
Where did the vertex coordinates come from? Have you checked to make sure they really are vertices of the letter 'A'? This can be done easily by using GL_POINTS in the glBegin statement instead of GL_TRIANGLE_FAN. The code you posted has all but two glVertex commands commented out. You need at least 3 vertices to make a triangle. It seems like you don't understand how GL_TRIANGLE_FAN is supposed to work. I suggest reading the docs on glBegin. I'd probably use gl_QUADS to do an 'A'. I suggest trying to do just ONE part of the 'A' (the horizontal line?) using one quadrilateral (i.e. 4 glVertex calls). If you can do that, the rest of the 'A' will be easy. Also, people are more likely to help you if you post code in [ code] [ /code] tags with proper indentation. Good luck.