[ create a new paste ] login | about

Link: http://codepad.org/4nyn5wkx    [ raw code | output | fork ]

C++, pasted on Sep 8:
#include <stdio.h>

#define GLEW_STATIC
#include <GL/glew.h>
#ifndef GLEW_STATIC
#pragma comment(lib,"glew32.lib")
#else
#pragma comment(lib,"glew32s.lib")
#endif

#include <GL/glut.h>


#define DRAW_LINE


GLuint m_vertexBufferID;
GLuint m_indexBufferID;

void init(void)
{
//#ifdef GLEW_STATIC
	glewInit();
//#endif
	const unsigned char* string_version = glGetString(GL_VERSION);
	printf("%s\n");
	glClearColor(0.0, 0.0, 1.0, 1.0);
	printf("%x\n",glGenBuffers);
	glGenBuffers(1,&m_vertexBufferID);
	glGenBuffers(1,&m_indexBufferID);

	glBindBuffer(GL_ARRAY_BUFFER,m_vertexBufferID);
	glBufferData(GL_ARRAY_BUFFER,576,0,GL_STATIC_DRAW);//576 = 4(byte/float) x 6(floats/vertex) x 24(vertex)
	glBindBuffer(GL_ARRAY_BUFFER,0);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER,24,0,GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);


	GLfloat geom[] = 
		{
			-.5f,-.5f,-.5f, -1.0f,0.0f,0.0f,//0
			-.5f,-.5f,-.5f, 0.0f,-1.0f,0.0f,//1
			-.5f,-.5f,-.5f, 0.0f,0.0f,-1.0f,//2

			.5f,-.5f,-.5f, 1.0f,0.0f,0.0f,//3
			.5f,-.5f,-.5f, 0.0f,-1.0f,0.0f,//4
			.5f,-.5f,-.5f, 0.0f,0.0f,-1.0f,//5

			-.5f,.5f,-.5f, -1.0f,0.0f,0.0f,//6
			-.5f,.5f,-.5f, 0.0f,1.0f,0.0f,//7
			-.5f,.5f,-.5f, 0.0f,0.0f,-1.0f,//8

			.5f,.5f,-.5f, 1.0f,0.0f,0.0f,//9
			.5f,.5f,-.5f, 0.0f,1.0f,0.0f,//10
			.5f,.5f,-.5f, 0.0f,0.0f,-1.0f,//11

			-.5f,-.5f,.5f, -1.0f,0.0f,0.0f,//12
			-.5f,-.5f,.5f, 0.0f,-1.0f,0.0f,//13
			-.5f,-.5f,.5f, 0.0f,0.0f,1.0f,//14

			.5f,-.5f,.5f, 1.0f,0.0f,0.0f,//15
			.5f,-.5f,.5f, 0.0f,-1.0f,0.0f,//16
			.5f,-.5f,.5f, 0.0f,0.0f,1.0f,//17

			-.5f,.5f,.5f, -1.0f,0.0f,0.0f,//18
			-.5f,.5f,.5f, 0.0f,1.0f,0.0f,//19
			-.5f,.5f,.5f, 0.0f,0.0f,1.0f,//20

			.5f,.5f,.5f, 1.0f,0.0f,0.0f,//21
			.5f,.5f,.5f, 0.0f,1.0f,0.0f,//22
			.5f,.5f,.5f, 0.0f,0.0f,1.0f,//23
		};
		glBindBuffer(GL_ARRAY_BUFFER,m_vertexBufferID);
		const unsigned int sizeof_GLfloat = sizeof(GLfloat);
		int sizeof_geom = sizeof(geom);
		{
			int num_elem = sizeof_geom/sizeof_GLfloat;
		}
		glBufferSubData(GL_ARRAY_BUFFER,0,sizeof_geom,geom);
		glBindBuffer(GL_ARRAY_BUFFER,0);

		GLubyte indicies[] = 
		{
			0,6,18,12,
			1,4,16,13,
			2,5,11,8,
			3,9,21,15,
			7,10,22,19,
			14,17,23,20,
		};
		const unsigned int sizeof_indicies = sizeof(indicies);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_indexBufferID);
		glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,sizeof_indicies,indicies);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
	
}

void resize(int w, int h)
{
  glViewport(0, 0, w, h);
  glLoadIdentity();
  glOrtho(-w, w, -h, h, -1.0, 1.0);
}

GLenum checkError()
{
	GLenum errCode;
	const GLubyte* errString;
	if((errCode = glGetError())!=GL_NO_ERROR){
		errString = gluErrorString(errCode);
		printf("Error: %s\n",errString);
	}
	else{
		printf("No Error.\n");
	}
	return errCode;
}


void display(void)
{

	checkError();
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	//line
	{
#ifdef DRAW_LINE
	glColor4d(1.0, 1.0, 1.0,1.0);
		glBegin(GL_LINES);
			glVertex3d(0,0,0);
			glVertex3d(1,1,0);
		glEnd();
#endif
	}
	checkError();

	//cube
	{
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_NORMAL_ARRAY);

		glBindBuffer(GL_ARRAY_BUFFER,m_vertexBufferID);
		const unsigned int sizeof_GLfloat = sizeof(GLfloat);
		glVertexPointer(3,GL_FLOAT,6*sizeof_GLfloat,0);
		glNormalPointer(GL_FLOAT,6*sizeof_GLfloat,(const GLvoid*)(3*sizeof_GLfloat));
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_indexBufferID);
		glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,0);

		glBindBuffer(GL_ARRAY_BUFFER,0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);

		glDisableClientState(GL_NORMAL_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);
	}
	glFlush();
	checkError();
}

int main(int argc, char *argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGBA);
	glutCreateWindow(argv[0]);
	glutDisplayFunc(display);
	glutReshapeFunc(resize);
	init();
	glutMainLoop();
	return 0;
}


Output:
1
2
3
4
5
6
Line 20: error: GL/glew.h: No such file or directory
cc1plus: warnings being treated as errors
Line 8: warning: ignoring #pragma comment 
Line 20: error: GL/glut.h: No such file or directory
Line 17: error: 'GLuint' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: