Declaring Vertices

Like with declaring variables, I would like to declare vertices.

int muffin;

That’s a variable declaration. I’m hoping there is something similar for vertex declaration. I want to make a “bank” of points, like in the following pseudo code.

vertex0=(-51, 412, 2);
vertex1=(-55, 8, -453);

And so on. Then, I don’t have a lot of repetition to deal with if I want to use certain coordinates in multiple different polygons. Copying and pasting vertex data over and over again seems too time consuming for my liking. Something that allows me to use glVertex3f(vertexname); is just what I need.

glBegin(GL_POLYGON);
glVertex3f(vertex0);
glEnd();

Simple question, and there may be a simple answer. Thanks!

Use the *v (for vector) calls :

GLfloat vertex0[] = (-51, 412, 2);
glVertex3fv(vertex0);

Thanks for your assistance. :wink: However, I get, “undefined reference to glvertex3fv.” Perhaps I’m misusing it.


#include <GL/gl.h>
#include <GL/glut.h>

void display(void)
{

// Vertex Data.
GLfloat vertex0[] = {-51, 412, 2}; // To bypass the "Invalid Initializer" error in GLfloat, these were required instead of parenthesis.
GLfloat vertex1[] = {-55, 8, -453};
GLfloat vertex2[] = {-59, -358, -161};


// Clear all pixels.
	glClear(GL_COLOR_BUFFER_BIT);
// Draw white polygon.

    //glOrtho(-16000,8000,-8000,4000,-8000,8000);
    glOrtho(-8000,4000,-4000,1500,-4000,4000);
	glColor3f (1.0, 1.0, 1.0);

// Load Vertex Data.
glBegin(GL_POLYGON);
	glvertex3fv (vertex0);
	glvertex3fv (vertex1);
	glvertex3fv (vertex2);
glEnd();

	glFlush ();
}


void init (void)
{
// Select clearing (background) color.
	glClearColor (0.0, 0.0, 0.0, 0.0);

// Initialize Viewing Values
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);



// Lighting Stuff.

   GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
   GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
//	light_position is NOT default value
   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

   glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
   glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
   glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
   glLightfv (GL_LIGHT0, GL_POSITION, light_position);

   glEnable (GL_LIGHTING);
   glEnable (GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);



}


int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize (500, 500);
	glutInitWindowPosition (100, 100);
	glutCreateWindow ("Waist");
	init ();
	glutDisplayFunc(display);
	glutMainLoop();
	return(0);
}

I’m using Version 10.04 Xubuntu, the Code::Blocks IDE, and MinGW’s compiler. (Other, more simple OpenGL utilities work.)

Problem solved! I was using glvertex3fv instead of glVertex3fv!

Yeah my bad.
I fixed my post, sorry about that :slight_smile: