[ create a new paste ] login | about

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

MikeSantanictics - C++, pasted on Jul 8:
#include"gl\glew.h"
#include"obj-catcher.h"
#include"gl\glut.h"

#define ushort unsigned int
#define BUFFER_OFFSET(i) ((char *)NULL + (i))

Catch  A("models\\COD-SAS.obj");
Catch  B("models\\boxALL.obj");
int xRot=0;
int Size=50;
GLfloat lightPos[]={0.0f,0.0f,500.0f,10};
GLfloat specular[]={1.0f,1.0f,1.0f,1.0f};
GLfloat specref[]={1.0f,1.0f,1.0f,1.0f};
GLfloat ambientLight[]={1.0f,1.0f,1.0f,1.0f};
GLfloat spotDir[]={0.0f,0.0f,-1.0f};
GLuint VertexVBOID,IndexVBOID;
GLuint VertexVBOID2,IndexVBOID2;

struct MyVertex
{
	float x, y, z;
	Normal vn;
	float s0, t0 , w0;
}*pvertex,*pvertex2;
unsigned int *index;
int something()
{
	glEnable(GL_LIGHTING);
	glClearColor(0.0f,0.0f,0.0f,1.0f);
	glShadeModel(GL_SMOOTH);
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,ambientLight);
	glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
	glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
	glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
	glEnable(GL_LIGHT0);
	return 0;
}
int SetupRC()
{
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glClearDepth(1);
	pvertex=new MyVertex [A.get_f()*3];
	index=new unsigned int [A.get_f()*3];
	for(int i=0;i<A.get_f()*3;i++)
	{
		index[i]=i;
		pvertex[i].x=A.get_vertex()[A.get_vi()[i]*3];pvertex[i].y=A.get_vertex()[A.get_vi()[i]*3+1];pvertex[i].z=A.get_vertex()[A.get_vi()[i]*3+2];
		pvertex[i].s0=A.get_texture()[A.get_ui()[i]*3+0];pvertex[i].t0=A.get_texture()[A.get_ui()[i]*3+1];pvertex[i].w0=A.get_texture()[A.get_ui()[i]*3+2];
		pvertex[i].vn=A.get_normal()[A.get_vni()[i]];
	} 
	for(int i=0;i<B.get_f()*3;i++)
	{
		pvertex2[i].x=B.get_vertex()[B.get_vi()[i]*3];pvertex2[i].y=B.get_vertex()[B.get_vi()[i]*3+1];pvertex2[i].z=B.get_vertex()[B.get_vi()[i]*3+2];
		pvertex2[i].s0=B.get_texture()[B.get_ui()[i]*3+0];pvertex2[i].t0=B.get_texture()[B.get_ui()[i]*3+1];pvertex2[i].w0=B.get_texture()[B.get_ui()[i]*3+2];
		pvertex2[i].vn=B.get_normal()[B.get_vni()[i]];
	} 
//the first object;
	glGenBuffers(1, &VertexVBOID);
	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(MyVertex)*3*A.get_f(), &pvertex[0].x, GL_STATIC_DRAW);
	glGenBuffers(1, &IndexVBOID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(ushort)*3*A.get_f(), index, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(MyVertex), BUFFER_OFFSET(0));
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(12));
	glEnableVertexAttribArray(2);
	glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(24));
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	A.ClearBuffer();
//end
//the 2nd object;
	glGenBuffers(1, &VertexVBOID2);
	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID2);
	glBufferData(GL_ARRAY_BUFFER, sizeof(MyVertex)*3*B.get_f(), &pvertex2[0].x, GL_STATIC_DRAW);
	glGenBuffers(1, &IndexVBOID2);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID2);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(ushort)*3*B.get_f(), index, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
	glEnableVertexAttribArray(3);//!!!!!
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(0));
	glEnableVertexAttribArray(4);//!!!!!
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(12));
	glEnableVertexAttribArray(5);//!!!!!
	glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(24));
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID2);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	A.ClearBuffer();
//end
	if(index) {delete [] index;index=NULL;}
	if(pvertex){delete [] pvertex;pvertex=NULL;}
	something();
	return 0;
}
void renderscene()
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glPushMatrix();
		glRotatef(xRot++,0.0f,1.0f,0.0f);
		glNormalPointer(GL_FLOAT,sizeof(MyVertex),BUFFER_OFFSET(12));	
		glTexCoordPointer(3,GL_FLOAT,sizeof(MyVertex),BUFFER_OFFSET(24));
			glDrawElements(GL_TRIANGLES,A.get_f()*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
		glNormalPointer(GL_FLOAT,sizeof(MyVertex),BUFFER_OFFSET(12));
		glTexCoordPointer(3,GL_FLOAT,sizeof(MyVertex),BUFFER_OFFSET(24));
		glTranslatef(30,0,0);
			glDrawElements(GL_TRIANGLES,B.get_f()*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
	glPopMatrix();
	glutSwapBuffers();
}
void TimerFunction(int value)
{
	glutPostRedisplay();
	glutTimerFunc(33,TimerFunction,1);
}
void windowchange(int w,int h)
{
	float fAspect;
	if(h==0)
		h=1;
	glViewport(0,0,w,h);
	fAspect=(GLfloat)w/(GLfloat)h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1*Size,Size,-1*Size,Size,-1*Size,Size);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
int main(int argc,char *argv[])
{
	glutInit( &argc , argv );
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutInitWindowSize(300,300);
	glutCreateWindow("obj-catcher,example(for OpenGL)");
	glutReshapeFunc(windowchange);
	glutDisplayFunc(renderscene);
	glutTimerFunc(0,TimerFunction,1);
	glewInit();
	SetupRC();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glutMainLoop();
	if(index) {delete [] index;index=NULL;}
	if(pvertex){delete [] pvertex;pvertex=NULL;}
	return 0;
}


Output:
1
2
3
4
5
Line 19: error: gl\glew.h: No such file or directory
Line 23: error: obj-catcher.h: No such file or directory
Line 19: error: gl\glut.h: No such file or directory
Line 8: error: 'Catch' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: