Ejemplo n.º 1
0
int main()
{
	int width = 800;
	int height = 600;

	int mesh_width = 256;
	int mesh_height = 256;

	// Creation du device
	cutilSafeCall( cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() ) );

	// Creation d'une fenetre
	C3::Window OpenGLWin;
	OpenGLWin.Create(C3::WindowMode(width,height),"CudaC3");
	
	// Glew init
	GLenum err = glewInit();
	if(err != GLEW_OK)
		std::cout << "Error on GLEW initialization.\n";


	// Configuration OpenGL
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glDisable(GL_DEPTH_TEST);
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.1, 10.0);

	// VBO
	// *** Create
	GLuint vbo;
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	// *** Initialize
	unsigned int size = mesh_width * mesh_height * 4 * sizeof(float);
	glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	// *** Register in CUDA
	cudaGraphicsResource *cuda_vbo_resource = NULL;
	cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_vbo_resource, vbo, cudaGraphicsMapFlagsWriteDiscard));


	float g_fAnim = 0.f;
	int nbFrame = 0;
	float timeFPS = 0.f;
	while(OpenGLWin.IsOpened())
	{
		// Events
		C3::Event event;
		while(OpenGLWin.PoolEvent(event))
		{
                        //std::cout << "Event !" << std::endl;
			if(event.Type == C3::Event::Closed)
			{
				std::cout << "Close ... " << std::endl;
				OpenGLWin.Close();
			}
			else if(event.Type == C3::Event::KeyPressed)
			{
				if(event.Key.Code == C3::Key::Escape)
				{
					std::cout << "Close ... " << std::endl;
					OpenGLWin.Close();
				}
			}
		}

		// Mise a jour du temps
		g_fAnim += OpenGLWin.GetFrameTime() / 1000.f;
		timeFPS += OpenGLWin.GetFrameTime() / 1000.f;
		nbFrame++;
		if(timeFPS > 1.0f)
		{
			std::stringstream ss;
			ss << "CudaC3 [" << (int)ceil( nbFrame / timeFPS ) << " FPS]";
			OpenGLWin.SetTitle(ss.str());
			timeFPS = 0.f;
			nbFrame = 0;
		}
		
		// Draw the scene
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

		// Lancer le calcul CUDA
		// *** map OpenGL buffer object for writing from CUDA
		float4 *dptr;
		cutilSafeCall(cudaGraphicsMapResources(1, &cuda_vbo_resource, 0));
		size_t num_bytes; 
		cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&dptr, &num_bytes, cuda_vbo_resource));
		// *** Run kernel
		runKernel(dptr, mesh_width, mesh_height,g_fAnim);
		cutilSafeCall( cutilDeviceSynchronize() );
		// *** Unmap
		cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_vbo_resource, 0));
		
		// OpenGL
		// *** Make some transformation
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslatef(0.0, 0.0, -3.0);
		glRotatef(0.0, 1.0, 0.0, 0.0);
		glRotatef(0.0, 0.0, 1.0, 0.0);
		// *** Render VBO
		// --- Bind
		glBindBuffer(GL_ARRAY_BUFFER, vbo);
		glVertexPointer(4, GL_FLOAT, 0, 0);
		// --- Draw
		glEnableClientState(GL_VERTEX_ARRAY);
		glColor3f(1.0, 0.0, 0.0);
		glDrawArrays(GL_POINTS, 0, mesh_width * mesh_height);
		glDisableClientState(GL_VERTEX_ARRAY);

		// Swap buffers
		OpenGLWin.Display();
	}

	// Liberation des ressources
	cudaGraphicsUnregisterResource(cuda_vbo_resource);
	
	glBindBuffer(1, vbo);
	glDeleteBuffers(1, &vbo);

	// Close device
	cutilDeviceReset();

	return 0;
}
Ejemplo n.º 2
0
void Example::render()
{
	// 4. Use the buffer to render the data.

	// Clear the color buffer and depth buffer with colors specified
	// above with glClearColor(): 0.5f, 0.5f, 0.5f, 0.5f
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Replace the current matrix with the identity matrix
    glLoadIdentity();

	// Position the camera with
	// gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)
	// first three args give position of camera
	// second three give point the camera's looking at
	// third three tell which way is up
    gluLookAt(0.0, 6.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	// Enable a vertex array

	// Vertex arrays are a series of arrays that we declare
	// to OpenGL, which stores different per-vertex attributes ,
	// including positions and colors.

	// The GL_VERTEX_ARRAY parameter tells OpenGL that the array to be 
	// enabled is a collection of positions. Another common parameter is 
	// GL_COLOR_ARRAY, which tells OpenGL that the array to be enabled
	// is a collection of colors.
    glEnableClientState(GL_VERTEX_ARRAY);

	// Activate the buffer we loaded earlier
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);

	// Tells OpenGL that the array or part of the array contains vertices, and 
	// provides some details about the array so OpenGL knows how to use it
	//		void glVertexPointer(GLint size, GLenum type, 
	//			GLsizei stride, const GLvoid *array);
	//
	// The call below tells OpenGL that each vertex in the array has three 
	// elements (x, y, and z), and each element is a floating-point number.
	// The stride of 0 means there's no padding between vertices, and the 
	// final 0 says that the array starts at the first position in the array.
    glVertexPointer(3, GL_FLOAT, 0, 0);

    float pointSize = 0.5f;
    for (unsigned int i = 0; i < m_vertices.size() / 3; ++i)
    {
		// Change the size of a point in pixels with
		//		void glPointSize(GLfloat size)
        glPointSize(pointSize);

		// glDrawArrays() is the most common method for rendering arrays.
		//		void glDrawArrays(GLenum mode, GLint first, GLsizei count);
		// where mode is a type of primitive to render. Different modes include
		// GL_POINTS, GL_LINES and GL_TRIANGLES
		// The call below asks OpenGL to draw one point at the location 
		// given by m_vertices[i*3]
        glDrawArrays(GL_POINTS, i, 1); 
        pointSize += 1.0f;
    }

	// Disable the client state when you're done with the array
    glDisableClientState(GL_VERTEX_ARRAY);
}
Ejemplo n.º 3
0
static void drawIP(const char* ip, int size, int xx, int yy)
{
	static const char* chardot =	" "
							" "
							" "
							" "
							".";

	static const char* char0 =	"..."
							". ."
							". ."
							". ."
							"...";

	static const char* char1 =	"."
							"."
							"."
							"."
							".";

	static const char* char2 =	"..."
							"  ."
							"..."
							".  "
							"...";

	static const char* char3 =	"..."
							"  ."
							"..."
							"  ."
							"...";

	static const char* char4 =	".  "
							". ."
							". ."
							"..."
							"  .";

	static const char* char5 =	"..."
							".  "
							"..."
							"  ."
							"...";

	static const char* char6 =	"..."
							".  "
							"..."
							". ."
							"...";

	static const char* char7 =	"..."
							"  ."
							"  ."
							"  ."
							"  .";

	static const char* char8 =	"..."
							". ."
							"..."
							". ."
							"...";

	static const char* char9 =	"..."
							". ."
							"..."
							"  ."
							"...";

	static const char* loading =
		".   ... ... ..  . ... ...      "
		".   . . . . . . . . . .        "
		".   . . ... . . . . . . .      "
		".   . . . . . . . . . . .      "
		"... ... . . ..  . . . ... . . .";


	static const char* localip =
		".   ... ... ... .     . ...   . ... ... ...  "
		".   . . .   . . .     . . .   . . . .   . . ."
		".   . . .   ... .     . ...   . . . ..  . .  "
		".   . . .   . . .     . .     . . . .   . . ."
		"... ... ... . . ...   . .     . . . .   ...  ";

	static const char* ipinfo =
		". ...   . ... ... ...  "
		". . .   . . . .   . .  "
		". ...   . . . ..  . . ."
		". .     . . . .   . .  "
		". .     . . . .   ... .";

	static const char* version =
        "... ... . .     ... .  "
        "  . . . . . .   . . . ."
        "... . . . . .   . . . ."
        ".   . . . ...   . . ..."
        "... ... .   . . ...   .";

	static const char* chars[] = {char0, char1, char2, char3, char4, char5, char6, char7, char8, char9};

    gglColor4f(0, 0, 0, 1);

	oglDisable(GL_TEXTURE_2D);

	oglEnableClientState(GL_VERTEX_ARRAY);

	float v[8];
	glVertexPointer(2, GL_FLOAT, 0, v);

	int len = strlen(ip);
	for (int i = 0; i < len; ++i)
	{
		const char* chr;
		if (ip[i] == '.')
			chr = chardot;
		else if (ip[i] == 'I')
			chr = localip;
		else if (ip[i] == 'L')
			chr = loading;
		else if (ip[i] == 'V')
			chr = version;
		else
			chr = chars[ip[i] - '0'];

		int height = 5;
		int width = strlen(chr) / height;

		for (int y = 0; y < height; ++y)
			for (int x = 0; x < width; ++x)
			{
				if (chr[x + y * width] == '.')
				{
					//glBegin(GL_QUADS);
					//glVertex2i((x + xx)     * size, (y + yy)     * size);
					//glVertex2i((x + xx + 1) * size, (y + yy)     * size);
					//glVertex2i((x + xx + 1) * size, (y + yy + 1) * size);
					//glVertex2i((x + xx)     * size, (y + yy + 1) * size);
					//glEnd();

					v[0] = (x + xx)     * size; v[1] = (y + yy)     * size;
					v[2] = (x + xx + 1) * size; v[3] = (y + yy)     * size;
					v[4] = (x + xx)     * size; v[5] = (y + yy + 1) * size;
					v[6] = (x + xx + 1) * size; v[7] = (y + yy + 1) * size;

					oglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
				}
			}

		xx = xx + width + 1;
	}

	oglDisableClientState(GL_VERTEX_ARRAY);
}
Ejemplo n.º 4
0
void
drawWater (Water *w, Bool full, Bool wire)
{
    static const float mat_shininess[]      = { 50.0 };
    static const float mat_specular[]       = { 0.5, 0.5, 0.5, 1.0 };
    static const float mat_diffuse[]        = { 0.2, 0.2, 0.2, 1.0 };
    static const float mat_ambient[]        = { 0.1, 0.1, 0.1, 1.0 };
    static const float lmodel_ambient[]     = { 0.4, 0.4, 0.4, 1.0 };
    static const float lmodel_localviewer[] = { 0.0 };

    float *v;
    if (!w)
	return;

    glDisable (GL_DEPTH_TEST);

    if (full)
    {
	glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
	glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
	glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
	glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
	glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
	glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);

	glEnable (GL_COLOR_MATERIAL);
	glEnable (GL_LIGHTING);
	glEnable (GL_LIGHT1);
	glDisable (GL_LIGHT0);

	glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	v = (float *) w->vertices;
	glDisableClientState (GL_TEXTURE_COORD_ARRAY);
	glEnableClientState (GL_NORMAL_ARRAY);

	glVertexPointer (3, GL_FLOAT, 6 * sizeof (float), v);
	glNormalPointer (GL_FLOAT, 6 * sizeof (float), v + 3);
	glDrawElements (GL_TRIANGLES, w->nSIdx, GL_UNSIGNED_INT, w->indices);

	glDisableClientState (GL_NORMAL_ARRAY);
	glDisable (GL_LIGHTING);

	glDrawElements (GL_TRIANGLES, w->nWIdx, GL_UNSIGNED_INT, w->indices + w->nSIdx);

	glEnableClientState (GL_TEXTURE_COORD_ARRAY);
    }

    if (wire)
    {
	int i, j;

	glColor4usv (defaultColor);

	glDisable (GL_LIGHTING);

	glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	for (i = 0; i < w->nIndices; i+=3)
	{
	    glBegin(GL_LINE_LOOP);

	    for (j = 0; j < 3; j++)
		glVertex3f(w->vertices[w->indices[i + j]].v[0],
			   w->vertices[w->indices[i + j]].v[1],
			   w->vertices[w->indices[i + j]].v[2]);
	    glEnd();
	}
    }

}
Ejemplo n.º 5
0
void SW::GLViewer::init()
{

    setGL();
    initGLSL();

#if BUFFER_
    //glClearColor(0.0, 0.0, 0.0, 0.0);

    //glDisable(GL_DITHER);

    glShadeModel(GL_FLAT);

    //glEnable(GL_DEPTH_TEST);

    enum{Vertices, Color, Elements, NumVBOs};
    GLuint buffers[NumVBOs];

    // glew init is very important or errors occur
    glewInit();
    // generate vertex arrays, and each array is corresponding to a object to be render
    glGenVertexArrays(1, &arrayId);

#ifdef QT_BUFFER
    QGLFunctions qtgl;
    qtgl.initializeGLFunctions(0);
#endif

    // 3D world coordinate of points
#ifdef QT_BUFFER
    QVector<QVector3D> Verts;
    Verts.append(QVector3D(-1.0, -1.0, -1.0));
    Verts.append(QVector3D(-1.0, -1.0, 1.0));
    Verts.append(QVector3D(-1.0, 1.0, -1.0));
    Verts.append(QVector3D(-1.0, 1.0, 1.0));
    Verts.append(QVector3D(1.0, -1.0, -1.0));
    Verts.append(QVector3D(1.0, -1.0, 1.0));
    Verts.append(QVector3D(1.0, 1.0, -1.0));
    Verts.append(QVector3D(1.0, 1.0, 1.0));
#else


    GLfloat Verts[][3] = {
        {-1.0, -1.0, -1.0},
        {-1.0, -1.0, 1.0},
        {-1.0, 1.0, -1.0},
        {-1.0, 1.0, 1.0},
        {1.0,  -1.0, -1.0},
        {1.0, -1.0, 1.0},
        {1.0, 1.0, -1.0},
        {1.0, 1.0, 1.0},
    };
#endif

    // colors of points
#ifdef QT_BUFFER
    QVector<QVector3D> Colors;
    Colors.append(QVector3D(0, 0.0, 0.0));
    Colors.append(QVector3D(0, 0.0, 1.0));
    Colors.append(QVector3D(0, 1.0, 0.0));
    Colors.append(QVector3D(0, 1.0, 1.0));
    Colors.append(QVector3D(1.0, 0.0, 0.0));
    Colors.append(QVector3D(1.0, 0.0, 1.0));
    Colors.append(QVector3D(1.0, 1.0, 0.0));
    Colors.append(QVector3D(1.0, 1.0, 1.0));
#else
    GLfloat Colors[][3] = {
        {0.0, 0.0, 0.0},
        {0.0, 0.0, 1.0},
        {0.0, 1.0, 0.0},
        {0.0, 1.0, 1.0},
        {1.0, 0.0, 0.0},
        {1.0, 0.0, 1.0},
        {1.0, 1.0, 0.0},
        {1.0, 1.0, 1.0},
    };
#endif

    // indices of points
#ifdef QT_BUFFER
    QVector<uint> Indices;
    Indices.append(0);Indices.append(1);Indices.append(3);Indices.append(2);
    Indices.append(4);Indices.append(6);Indices.append(7);Indices.append(5);
    Indices.append(2);Indices.append(3);Indices.append(7);Indices.append(6);
    Indices.append(0);Indices.append(4);Indices.append(5);Indices.append(1);
    Indices.append(0);Indices.append(2);Indices.append(6);Indices.append(4);
    Indices.append(1);Indices.append(5);Indices.append(7);Indices.append(3);
#else
    GLubyte Indices[]={
        0, 1, 3, 2,
        4, 6, 7, 5,
        2, 3, 7, 6,
        0, 4, 5, 1,
        0, 2, 6, 4,
        1, 5, 7, 3,
    };
#endif

    // active a vertex array
    glBindVertexArray(arrayId);

    // generate buffer objects, and each attribute(vertices, color, and normal..) is corresponding to one buffer

#ifdef QT_BUFFER
    qtgl.glGenBuffers(NumVBOs, buffers);
#else
    glGenBuffers(NumVBOs, buffers);
#endif

    //---------------------------------------buffer for vertices----------------------------------//
    // active a buffer object
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
#else
    glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
#endif
    // alloc a space for buffer
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ARRAY_BUFFER, Verts.size()*sizeof(GLfloat), Verts.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ARRAY_BUFFER, sizeof(Verts), Verts, GL_STATIC_DRAW);
#endif
    // put the data into the corresponding buffer
    glVertexPointer(3, GL_FLOAT, 0,BUFFER_OFFSET(0));
    glEnableClientState(GL_VERTEX_ARRAY);



    //---------------------------------------buffer for colors----------------------------------//
    // buffer for colors
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ARRAY_BUFFER, buffers[Color]);
#else
    glBindBuffer(GL_ARRAY_BUFFER, buffers[Color]);
#endif
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ARRAY_BUFFER, Colors.size()*sizeof(GLfloat), Colors.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ARRAY_BUFFER, sizeof(Colors), Colors, GL_STATIC_DRAW);
#endif
    glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
    glEnableClientState(GL_COLOR_ARRAY);


    //---------------------------------------buffer for elements----------------------------------//
    // buffer for elements
#ifdef QT_BUFFER
    numElement = Indices.size();
#else
    numElement = sizeof(Indices)/sizeof(Indices[0]);
#endif
#ifdef QT_BUFFER
    qtgl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
#else
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]);
#endif
#ifdef QT_BUFFER
    qtgl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, Indices.size()*sizeof(uint), Indices.data(), GL_STATIC_DRAW);
#else
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
#endif

#endif
}
Ejemplo n.º 6
0
void VoxelTerrain::UpdateTerrain(){

	glBindBuffer(GL_ARRAY_BUFFER,0);

	RecreateOctree();

	glDisable(GL_ALPHA_TEST);

	if (order!=0){
		glDisable(GL_DEPTH_TEST);
		glDepthMask(GL_FALSE);
	}else{
		glEnable(GL_DEPTH_TEST);
		glDepthMask(GL_TRUE);
	}

	switch(brush.blend){
		case 0:
			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
			break;
		case 1:
			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
			break;
		case 2:
			glBlendFunc(GL_DST_COLOR,GL_ZERO); // multiply
			break;
		case 3:
			glBlendFunc(GL_SRC_ALPHA,GL_ONE); // additive and alpha
			break;
		}

	float ambient_red,ambient_green,ambient_blue;

	// fx flag 1 - full bright ***todo*** disable all lights?
	if (brush.fx & 1){
		if(Global::fx1!=true){
			Global::fx1=true;
			glDisableClientState(GL_NORMAL_ARRAY);
		}
		ambient_red  =1.0;
		ambient_green=1.0;
		ambient_blue =1.0;
	}else{
		if(Global::fx1!=false){
			Global::fx1=false;
			glEnableClientState(GL_NORMAL_ARRAY);
		}
		ambient_red  =Global::ambient_red;
		ambient_green=Global::ambient_green;
		ambient_blue =Global::ambient_blue;
	}

	// fx flag 2 - vertex colours
	/*if(brush.fx&2){

			glEnable(GL_COLOR_MATERIAL);
	}else{
			glDisable(GL_COLOR_MATERIAL);
	}*/
	if(Global::fx2!=false){
		Global::fx2=false;
		glDisableClientState(GL_COLOR_ARRAY);
		glDisable(GL_COLOR_MATERIAL);
	}


	// fx flag 4 - flatshaded
	if(brush.fx&4){
		glShadeModel(GL_FLAT);
	}else{
		glShadeModel(GL_SMOOTH);
	}

	// fx flag 8 - disable fog
	if(brush.fx&8){
		if(Global::fog_enabled==true){ // only disable if fog enabled in camera update
			glDisable(GL_FOG);
		}
	}

	// fx flag 16 - disable backface culling
	if(brush.fx&16){
		glDisable(GL_CULL_FACE);
	}else{
		glEnable(GL_CULL_FACE);
	}

	// light + material color

	float ambient[]={ambient_red,ambient_green,ambient_blue};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);

	float mat_ambient[]={brush.red,brush.green,brush.blue,brush.alpha};
	float mat_diffuse[]={brush.red,brush.green,brush.blue,brush.alpha};
	float mat_specular[]={brush.shine,brush.shine,brush.shine,brush.shine};
	float mat_shininess[]={100.0}; // upto 128

	glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
	glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);

	// textures

	int tex_count=0;

	if(ShaderMat!=NULL){
		ShaderMat->TurnOn(mat, 0, &vertices);
	}

	tex_count=brush.no_texs;

	int DisableCubeSphereMapping=0;
	for(int ix=0;ix<tex_count;ix++){

		if(brush.tex[ix]){

			// Main brush texture takes precedent over surface brush texture
			unsigned int texture=0;
			int tex_flags=0,tex_blend=0;
			float tex_u_scale=1.0,tex_v_scale=1.0,tex_u_pos=0.0,tex_v_pos=0.0,tex_ang=0.0;
			int tex_cube_mode=0;


			texture=brush.cache_frame[ix];
			tex_flags=brush.tex[ix]->flags;
			tex_blend=brush.tex[ix]->blend;
			//tex_coords=brush.tex[ix]->coords;
			tex_u_scale=brush.tex[ix]->u_scale;
			tex_v_scale=brush.tex[ix]->v_scale;
			tex_u_pos=brush.tex[ix]->u_pos;
			tex_v_pos=brush.tex[ix]->v_pos;
			tex_ang=brush.tex[ix]->angle;
			tex_cube_mode=brush.tex[ix]->cube_mode;
			//frame=brush.tex_frame;

			glActiveTexture(GL_TEXTURE0+ix);
			glClientActiveTexture(GL_TEXTURE0+ix);

			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D,texture); // call before glTexParameteri

			// masked texture flag
			if(tex_flags&4){
				glEnable(GL_ALPHA_TEST);
			}else{
				glDisable(GL_ALPHA_TEST);
			}

			// mipmapping texture flag
			if(tex_flags&8){
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
			}else{
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			}

			// clamp u flag
			if(tex_flags&16){
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
			}else{
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
			}

			// clamp v flag
			if(tex_flags&32){
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
			}else{
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
			}

				// ***!ES***

			// spherical environment map texture flag
			if(tex_flags&64){
				glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
				glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
				glEnable(GL_TEXTURE_GEN_S);
				glEnable(GL_TEXTURE_GEN_T);
				DisableCubeSphereMapping=1;
			}/*else{
				glDisable(GL_TEXTURE_GEN_S);
				glDisable(GL_TEXTURE_GEN_T);
			}*/

				// cubic environment map texture flag
				if(tex_flags&128){

					glEnable(GL_TEXTURE_CUBE_MAP);
					glBindTexture(GL_TEXTURE_CUBE_MAP,texture); // call before glTexParameteri

					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

					glEnable(GL_TEXTURE_GEN_S);
					glEnable(GL_TEXTURE_GEN_T);
					glEnable(GL_TEXTURE_GEN_R);
					//glEnable(GL_TEXTURE_GEN_Q)

					if(tex_cube_mode==1){
						glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
						glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
						glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
					}

					if(tex_cube_mode==2){
						glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
						glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
						glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
					}
					DisableCubeSphereMapping=1;

				}else  if (DisableCubeSphereMapping!=0){

					glDisable(GL_TEXTURE_CUBE_MAP);

					// only disable tex gen s and t if sphere mapping isn't using them
					if((tex_flags & 64)==0){
						glDisable(GL_TEXTURE_GEN_S);
						glDisable(GL_TEXTURE_GEN_T);
					}

					glDisable(GL_TEXTURE_GEN_R);
					//glDisable(GL_TEXTURE_GEN_Q)

				}


			switch(tex_blend){
				case 0: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
				break;
				case 1: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
				break;
				case 2: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
				//case 2 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
				break;
				case 3: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);
				break;
				case 4:
					glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
					glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);
					break;
				case 5:
					glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
					glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE);
					glTexEnvi(GL_TEXTURE_ENV,GL_RGB_SCALE,2.0);
					break;
				default: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
			}

			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(2,GL_FLOAT,32,&vertices[6]);


			// reset texture matrix
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();

			if(tex_u_pos!=0.0 || tex_v_pos!=0.0){
				glTranslatef(tex_u_pos,tex_v_pos,0.0);
			}
			if(tex_ang!=0.0){
				glRotatef(tex_ang,0.0,0.0,1.0);
			}
			if(tex_u_scale!=1.0 || tex_v_scale!=1.0){
				glScalef(tex_u_scale,tex_v_scale,1.0);
			}

			// ***!ES***
			// if spheremap flag=true then flip tex
			if(tex_flags&64){
				glScalef(1.0,-1.0,-1.0);
			}

			// if cubemap flag=true then manipulate texture matrix so that cubemap is displayed properly
			if(tex_flags&128){

				glScalef(1.0,-1.0,-1.0);

				// get current modelview matrix (set in last camera update)
				float mod_mat[16];
				glGetFloatv(GL_MODELVIEW_MATRIX,&mod_mat[0]);

				// get rotational inverse of current modelview matrix
				Matrix new_mat;
				new_mat.LoadIdentity();

				new_mat.grid[0][0] = mod_mat[0];
				new_mat.grid[1][0] = mod_mat[1];
				new_mat.grid[2][0] = mod_mat[2];

				new_mat.grid[0][1] = mod_mat[4];
				new_mat.grid[1][1] = mod_mat[5];
				new_mat.grid[2][1] = mod_mat[6];

				new_mat.grid[0][2] = mod_mat[8];
				new_mat.grid[1][2] = mod_mat[9];
				new_mat.grid[2][2] = mod_mat[10];

				glMultMatrixf(&new_mat.grid[0][0]);

			}


		}

	}

	// draw tris
	glMatrixMode(GL_MODELVIEW);

	glPushMatrix();
	glMultMatrixf(&mat.grid[0][0]);
	glVertexPointer(3,GL_FLOAT,32,&vertices[0]);
	glNormalPointer(GL_FLOAT,32,&vertices[3]);

	glDrawArrays(GL_TRIANGLES, 0, triangleindex*3);
	glPopMatrix();

	// disable all texture layers
	for(int ix=0;ix<tex_count;ix++){

		glActiveTexture(GL_TEXTURE0+ix);
		glClientActiveTexture(GL_TEXTURE0+ix);

		// reset texture matrix
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();

		glDisable(GL_TEXTURE_2D);

		// ***!ES***
		if (DisableCubeSphereMapping!=0){
			glDisable(GL_TEXTURE_CUBE_MAP);
			glDisable(GL_TEXTURE_GEN_S);
			glDisable(GL_TEXTURE_GEN_T);
			glDisable(GL_TEXTURE_GEN_R);
			DisableCubeSphereMapping=0;
		}

	}
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);


	if (brush.fx&8 && Global::fog_enabled==true){
		glEnable(GL_FOG);
	}

	if(ShaderMat!=NULL){
		ShaderMat->TurnOff();
	}

}
Ejemplo n.º 7
0
void level::_renderRayTexture(void)
{
	int maxX = _size.getX()*_tileSize, maxY = _size.getY()*_tileSize;

	glEnable(GL_TEXTURE_2D);

	switch(_colorModel)
	{
		case 3:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_rayTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _interpolatedTexture);
			break;
		case 4:
		default:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_pointTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _outlineTexture);
			break;
	}
	

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glClear(GL_DEPTH_BUFFER_BIT);
	float2D textureArray[6];
	int2D corners[6];
	float3D colors[6];
	corners[0] = int2D(0, 0);
	textureArray[0] = float2D(0, 0);
	corners[1] = int2D(0, maxY);
	textureArray[1] = float2D(0, 1.f);
	corners[2] = int2D(maxX, maxY);
	textureArray[2] = float2D(1.f, 1.f);
	corners[3] = int2D(maxX, maxY);
	textureArray[3] = float2D(1.f, 1.f);
	corners[4] = int2D(maxX, 0);
	textureArray[4] = float2D(1.f, 0);
	corners[5] = int2D(0, 0);
	textureArray[5] = float2D(0, 0);
	for(int i = 0; i < 6; i++) colors[i] = float3D(1.f, 1.f, 1.f);

	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glColorPointer(3, GL_FLOAT, 0, &colors[0]);
	glVertexPointer(2, GL_INT, 0, &corners[0]);
	glTexCoordPointer(2, GL_FLOAT, 0, &textureArray[0]);
	glDrawArrays(GL_TRIANGLES, 0, 6);

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glClear(GL_DEPTH_BUFFER_BIT);
	glDisable(GL_TEXTURE_2D);
	

}
Ejemplo n.º 8
0
void mesh3DS::draw(){

	assert(getNumFaces()!=0);

    int face, numFaces, vertexIndex, texcoordIndex;
	GLuint materialFaces; //GL_FRONT or GL_FRONT_AND_BACK

	std::map<std::string, std::vector<ushort> >::iterator materialsIter;
	for(materialsIter=m_materialFaces.begin(); materialsIter!=m_materialFaces.end(); ++materialsIter){
		const material3DS& currentMaterial = m_parentModel->getMaterial(materialsIter->first);

		// Bind texture map (if any)
		bool hasTextureMap = currentMaterial.hasTextureMap();
		if(hasTextureMap) glBindTexture(GL_TEXTURE_2D, currentMaterial.getTextureMapId());
		//else glBindTexture(GL_TEXTURE_2D, 0);

		const GLfloat *specular = currentMaterial.getSpecularColor();
		float shininess = currentMaterial.getShininess();
		float adjustedSpecular[4] = {specular[0]*shininess, specular[1]*shininess, specular[2]*shininess, 1};

		glPushAttrib(GL_LIGHTING_BIT);
		if(currentMaterial.isTwoSided()){
			glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
			materialFaces = GL_FRONT_AND_BACK;
		}
		else{
			glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
			materialFaces = GL_FRONT;
		}

		// Apply material colors
		if(glIsEnabled(GL_LIGHTING)){
			//const GLfloat matZero[4]={0,0,0,0};
			const GLfloat matOne[4]={1,1,1,1};
			if(hasTextureMap){ //replace color with texture, but keep lighting contribution
				glMaterialfv(materialFaces, GL_DIFFUSE, matOne);
			}
			else glMaterialfv(materialFaces, GL_DIFFUSE, currentMaterial.getDiffuseColor());
			glMaterialfv(materialFaces, GL_AMBIENT, currentMaterial.getAmbientColor());
			glMaterialfv(materialFaces, GL_SPECULAR, adjustedSpecular);
			glMaterialf(materialFaces, GL_SHININESS, 128.f * currentMaterial.getSpecularExponent());
		}
		else glColor3fv(currentMaterial.getDiffuseColor());

		const std::vector<ushort> *currentMatFaces = &(materialsIter->second);
		numFaces = (int)currentMatFaces->size(); //number of faces in this material

		switch(m_drawMode){
			case DRAW_IMMEDIATE_MODE:

				glBegin(GL_TRIANGLES);
				for(face=0; face<numFaces; face+=3){
					if(hasTextureMap){
						texcoordIndex = (*currentMatFaces)[face]*2;
						glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
					}
					vertexIndex = (*currentMatFaces)[face]*3;
					glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
					glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);

					if(hasTextureMap){
						texcoordIndex = (*currentMatFaces)[face+1]*2;
						glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
					}
					vertexIndex = (*currentMatFaces)[face+1]*3;
					glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
					glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);

					if(hasTextureMap){
						texcoordIndex = (*currentMatFaces)[face+2]*2;
						glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
					}
					vertexIndex = (*currentMatFaces)[face+2]*3;
					glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
					glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);
				}
				glEnd();

				break;

			case DRAW_VERTEX_ARRAY:

				glEnableClientState( GL_VERTEX_ARRAY );
				glEnableClientState( GL_NORMAL_ARRAY );

				if(hasTextureMap){
					glTexCoordPointer( 2, GL_FLOAT, 0, &m_texcoords[0] );
					glEnableClientState( GL_TEXTURE_COORD_ARRAY );
				}

				glVertexPointer( 3, GL_FLOAT, 0, &m_vertices[0] );
				glNormalPointer(GL_FLOAT, 0, &m_normals[0] );
				glDrawElements(GL_TRIANGLES, numFaces, GL_UNSIGNED_SHORT, &(materialsIter->second[0]));

				glDisableClientState( GL_VERTEX_ARRAY );
				glDisableClientState( GL_NORMAL_ARRAY );
				if(hasTextureMap){
					glDisableClientState( GL_TEXTURE_COORD_ARRAY );
				}

				break;

			case DRAW_VBO:

				break;

			default:
				std::cout<<"[3DS] ERROR: Invalid mesh draw mode specified"<<std::endl;
				break;
		}

		glPopAttrib(); // GL_LIGHTING_BIT
	}
}
Ejemplo n.º 9
0
//====================
// モデルデータの描画
//====================
void cPMDModel::render( void )
{
    if( !m_pvec3OrgPositionArray )	return;

#if (1)
    unsigned short	*pIndices = m_pIndices;

    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_NORMAL_ARRAY );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );

    // 頂点座標、法線、テクスチャ座標の各配列をセット
    glVertexPointer( 3, GL_FLOAT, 0, m_pvec3PositionArray );
    glNormalPointer( GL_FLOAT, 0, m_pvec3NormalArray );
    glTexCoordPointer( 2, GL_FLOAT, 0, m_puvOrgTexureUVArray );

    for( unsigned long i = 0 ; i < m_ulNumMaterials ; i++ )
    {
        // マテリアル設定
        glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE,  (float *)&(m_pMaterials[i].col4Diffuse)  );
        glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT,  (float *)&(m_pMaterials[i].col4Ambient)  );
        glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&(m_pMaterials[i].col4Specular) );
        glMaterialf(  GL_FRONT_AND_BACK, GL_SHININESS, m_pMaterials[i].fShininess );

        if( m_pMaterials[i].col4Diffuse.a < 1.0f )	glDisable( GL_CULL_FACE );
        else										glEnable( GL_CULL_FACE );

        if( m_pMaterials[i].uiTexID != 0xFFFFFFFF )
        {
            // テクスチャありならBindする
            glEnable( GL_TEXTURE_2D );
            glBindTexture( GL_TEXTURE_2D, m_pMaterials[i].uiTexID );
        }
        else
        {
            // テクスチャなし
            glDisable( GL_TEXTURE_2D );
        }

        // 頂点インデックスを指定してポリゴン描画
        glDrawElements( GL_TRIANGLES, m_pMaterials[i].ulNumIndices, GL_UNSIGNED_SHORT, pIndices );

        pIndices += m_pMaterials[i].ulNumIndices;
    }

    glDisableClientState( GL_VERTEX_ARRAY );
    glDisableClientState( GL_NORMAL_ARRAY );
    glDisableClientState( GL_TEXTURE_COORD_ARRAY );
#endif

#if	_DBG_BONE_DRAW
    glDisable( GL_DEPTH_TEST );
    glDisable( GL_LIGHTING );

    for( unsigned short i = 0 ; i < m_unNumBones ; i++ )
    {
        m_pBoneArray[i].debugDraw();
    }

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
#endif

#if	_DBG_IK_DRAW
    glDisable( GL_DEPTH_TEST );
    glDisable( GL_LIGHTING );

    for( unsigned short i = 0 ; i < m_unNumIK ; i++ )
    {
        m_pIKArray[i].debugDraw();
    }

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
#endif

#if	_DBG_TEXTURE_DRAW
    g_clsTextureList.debugDraw();
#endif
}
Ejemplo n.º 10
0
void GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum)
{
	float	s, t, l;
	int		i, j;
	int		index;
	trivertx_t	*v, *verts;
	int		list;
	int		*order;
	vec3_t	point;
	float	*normal;
	float	height, lheight;
	int		count;

	lheight = currententity->origin[2] - lightspot[2];

	height = 0;
	verts = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
	verts += posenum * paliashdr->poseverts;
	order = (int *)((byte *)paliashdr + paliashdr->commands);

	height = -lheight + 1.0;

	while (1)
	{
		// get the vertex count and primitive type
		count = *order++;
		if (!count)
			break;		// done

#ifdef USE_OPENGLES

		{
			int primType;
			int c;
			float* pVertex;

			if (count < 0)
			{
				count = -count;
				primType = GL_TRIANGLE_FAN;
			}
			else
				primType = GL_TRIANGLE_STRIP;

			pVertex = gVertexBuffer;
			for(c = 0; c < count; c++)
			{
				// texture coordinates come from the draw list
				// (skipped for shadows) glTexCoord2fv ((float *)order);
				order += 2;

				// normals and vertexes come from the frame list
				pVertex[0] = verts->v[0] * paliashdr->scale[0] + paliashdr->scale_origin[0];
				pVertex[1] = verts->v[1] * paliashdr->scale[1] + paliashdr->scale_origin[1];
				pVertex[2] = verts->v[2] * paliashdr->scale[2] + paliashdr->scale_origin[2];

				pVertex[0] -= shadevector[0]*(pVertex[2]+lheight);
				pVertex[1] -= shadevector[1]*(pVertex[2]+lheight);
				pVertex[2] = height;
	//			height -= 0.001;

				pVertex += 3;
				verts++;
			}

			glVertexPointer(3, GL_FLOAT, 0, gVertexBuffer);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
			glDrawArrays(primType, 0, count);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		}

#else

		if (count < 0)
		{
			count = -count;
			glBegin (GL_TRIANGLE_FAN);
		}
		else
			glBegin (GL_TRIANGLE_STRIP);

		do
		{
			// texture coordinates come from the draw list
			// (skipped for shadows) glTexCoord2fv ((float *)order);
			order += 2;

			// normals and vertexes come from the frame list
			point[0] = verts->v[0] * paliashdr->scale[0] + paliashdr->scale_origin[0];
			point[1] = verts->v[1] * paliashdr->scale[1] + paliashdr->scale_origin[1];
			point[2] = verts->v[2] * paliashdr->scale[2] + paliashdr->scale_origin[2];

			point[0] -= shadevector[0]*(point[2]+lheight);
			point[1] -= shadevector[1]*(point[2]+lheight);
			point[2] = height;
//			height -= 0.001;
			glVertex3fv (point);

			verts++;
		} while (--count);

		glEnd ();

#endif

	}
}
Ejemplo n.º 11
0
void COctree::CreateDisplayList(COctree *pNode, t3DModel *pRootWorld, int displayListOffset)
{
	// This function handles our rendering code in the beginning and assigns it all
	// to a display list.  This increases our rendering speed, as long as we don't flood
	// the pipeline with a TON of data.  Display lists can actually be to bloated or too small.
	// Like our DrawOctree() function, we need to find the end nodes by recursing down to them.
	// We only create a display list for the end nodes and ignore the rest.  The 
	// displayListOffset is used to add to the end nodes current display list ID, in case
	// we created some display lists before creating the octree.  Usually it is just 1 otherwise.

	// Make sure a valid node was passed in, otherwise go back to the last node
	if(!pNode) return;

	// Check if this node is subdivided. If so, then we need to recurse down to it's nodes
	if(pNode->IsSubDivided())
	{
		// Recurse down to each one of the children until we reach the end nodes
		CreateDisplayList(pNode->m_pOctreeNodes[TOP_LEFT_FRONT],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[TOP_LEFT_BACK],		pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[TOP_RIGHT_BACK],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[TOP_RIGHT_FRONT],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[BOTTOM_LEFT_FRONT],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[BOTTOM_LEFT_BACK],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[BOTTOM_RIGHT_BACK],	pRootWorld, displayListOffset);
		CreateDisplayList(pNode->m_pOctreeNodes[BOTTOM_RIGHT_FRONT],pRootWorld, displayListOffset);
	}
	else 
	{
		// Make sure we have valid data assigned to this node
		if(!pNode->m_pWorld) return;

		// Add our display list offset to our current display list ID
		pNode->m_DisplayListID += displayListOffset;

		// Start the display list and assign it to the end nodes ID
		glNewList(pNode->m_DisplayListID,GL_COMPILE);

		// Create a temp counter for our while loop below to store the objects drawn
		int counter = 0;
		
		// Store the object count and material count in some local variables for optimization
		int objectCount = pNode->m_pObjectList.size();
		int materialCount = pRootWorld->pMaterials.size();

		// Go through all of the objects that are in our end node
		while(counter < objectCount)
		{
			// Get the first object index into our root world
			int i = pNode->m_pObjectList[counter];

			// Store pointers to the current face list and the root object 
			// that holds all the data (verts, texture coordinates, normals, etc..)
			t3DObject *pObject     = &pNode->m_pWorld->pObject[i];
			t3DObject *pRootObject = &pRootWorld->pObject[i];

			// Check to see if this object has a texture map, if so, bind the texture to it.
			if(pRootObject->bHasTexture) 
			{
				// Turn on texture mapping and turn off color
				glEnable(GL_TEXTURE_2D);

				// Reset the color to normal again
				glColor3ub(255, 255, 255);

				// Bind the texture map to the object by it's materialID
				glBindTexture(GL_TEXTURE_2D, g_Texture[pRootObject->materialID]);
			} 
			else 
			{
				// Turn off texture mapping and turn on color
				glDisable(GL_TEXTURE_2D);

				// Reset the color to normal again
				glColor3ub(255, 255, 255);
			}

			// Check to see if there is a valid material assigned to this object
			if(materialCount && pRootObject->materialID >= 0) 
			{
				// Get and set the color that the object is, since it must not have a texture
				BYTE *pColor = pRootWorld->pMaterials[pRootObject->materialID].color;

				// Assign the current color to this model
				glColor3ub(pColor[0], pColor[1], pColor[2]);
			}

			// Now we get to the more unknown stuff, vertex arrays.  If you haven't
			// dealt with vertex arrays yet, let me give you a brief run down on them.
			// Instead of doing loops to go through and pass in each of the vertices
			// of a model, we can just pass in the array vertices, then an array of
			// indices that MUST be an unsigned int, which gives the indices into
			// the vertex array.  That means that we can send the vertices to the video
			// card with one call to glDrawElements().  There are a bunch of other
			// functions for vertex arrays that do different things, but I am just going
			// to mention this one.  Since texture coordinates, normals and colors are also
			// associated with vertices, we are able to point OpenGL to these arrays before
			// we draw the geometry.  It uses the same indices that we pass to glDrawElements()
			// for each of these arrays.  Below, we point OpenGL to our texture coordinates,
			// vertex and normal arrays.  This is done with calls to glTexCoordPointer(), 
			// glVertexPointer() and glNormalPointer().
			//
			// Before using any of these functions, we need to enable their states.  This is
			// done with glEnableClientState().  You just pass in the ID of the type of array 
			// you are wanting OpenGL to look for.  If you don't have data in those arrays,
			// the program will most likely crash.
			//
			// If you don't want to use vertex arrays, you can just render the world like normal.
			// That is why I saved the pFace information, as well as the pIndices info.  This
			// way you can use what ever method you are comfortable with.  I tried both, and
			// by FAR the vertex arrays are incredibly faster.  You decide :)

			// Make sure we have texture coordinates to render
			if(pRootObject->pTexVerts) 
			{
				// Turn on the texture coordinate state
				glEnableClientState(GL_TEXTURE_COORD_ARRAY);

				// Point OpenGL to our texture coordinate array.
				// We have them in a pair of 2, of type float and 0 bytes of stride between them.
				glTexCoordPointer(2, GL_FLOAT, 0, pRootObject->pTexVerts);
			}

			// Make sure we have vertices to render
			if(pRootObject->pVerts)
			{
				// Turn on the vertex array state
				glEnableClientState(GL_VERTEX_ARRAY);

				// Point OpenGL to our vertex array.  We have our vertices stored in
				// 3 floats, with 0 stride between them in bytes.
				glVertexPointer(3, GL_FLOAT, 0, pRootObject->pVerts);
			}

			// Make sure we have normals to render
			if(pRootObject->pNormals)
			{
				// Turn on the normals state
				glEnableClientState(GL_NORMAL_ARRAY);

				// Point OpenGL to our normals array.  We have our normals
				// stored as floats, with a stride of 0 between.
				glNormalPointer(GL_FLOAT, 0, pRootObject->pNormals);
			}

			// Here we pass in the indices that need to be rendered.  We want to
			// render them in triangles, with numOfFaces * 3 for indice count,
			// and the indices are of type UINT (important).
			glDrawElements(GL_TRIANGLES,    pObject->numOfFaces * 3, 
						   GL_UNSIGNED_INT, pObject->pIndices);

			// Increase the current object count rendered
			counter++;
		}

		// End the display list for this ID
		glEndList();
	}
}
Ejemplo n.º 12
0
/*
=============
GL_DrawAliasFrame
=============
*/
void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum)
{
	float	s, t;
	float 	l;
	int		i, j;
	int		index;
	trivertx_t	*v, *verts;
	int		list;
	int		*order;
	vec3_t	point;
	float	*normal;
	int		count;

#ifdef USE_OPENGLES
	glEnableClientState(GL_COLOR_ARRAY);
#endif

lastposenum = posenum;

	verts = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
	verts += posenum * paliashdr->poseverts;
	order = (int *)((byte *)paliashdr + paliashdr->commands);

	while (1)
	{
		// get the vertex count and primitive type
		count = *order++;
		if (!count)
			break;		// done

#ifdef USE_OPENGLES
		{
			int primType;
			int c;
			float* pColor;
			float* pTexCoord;
			float* pPos;

			if (count < 0)
			{
				count = -count;
				primType = GL_TRIANGLE_FAN;
			}
			else
				primType = GL_TRIANGLE_STRIP;

			// texture coordinates come from the draw list
			glTexCoordPointer(2, GL_FLOAT, 0, gTexCoordBuffer);
			glVertexPointer(3, GL_FLOAT, 0, gVertexBuffer);
			glColorPointer(4, GL_FLOAT, 0, gColorBuffer);

			pColor = gColorBuffer;
			pPos = gVertexBuffer;
			pTexCoord = gTexCoordBuffer;
			c = count;
			do
			{
				// texture coordinates come from the draw list
				*pTexCoord++ = ((float *)order)[0];
				*pTexCoord++ = ((float *)order)[1];
				order += 2;

				// normals and vertexes come from the frame list
				l = shadedots[verts->lightnormalindex] * shadelight;
				*pColor++ = l;
				*pColor++ = l;
				*pColor++ = l;
				*pColor++ = 1.0f;
				*pPos++ = verts->v[0];
				*pPos++ = verts->v[1];
				*pPos++ = verts->v[2];
				verts++;
		    } while (--c);

			glDrawArrays(primType, 0, count);
		}

#else
		if (count < 0)
		{
			count = -count;
			glBegin (GL_TRIANGLE_FAN);
		}
		else
			glBegin (GL_TRIANGLE_STRIP);

		do
		{
			// texture coordinates come from the draw list
			glTexCoord2f (((float *)order)[0], ((float *)order)[1]);
			order += 2;

			// normals and vertexes come from the frame list
			l = shadedots[verts->lightnormalindex] * shadelight;
			glColor3f (l, l, l);
			glVertex3f (verts->v[0], verts->v[1], verts->v[2]);
			verts++;
		} while (--count);

		glEnd ();
#endif
	}

#ifdef USE_OPENGLES
	glDisableClientState(GL_COLOR_ARRAY);
#endif

}
Ejemplo n.º 13
0
/*
=================
R_DrawSpriteModel

=================
*/
void R_DrawSpriteModel (entity_t *e)
{
	vec3_t	point;
	mspriteframe_t	*frame;
	float		*up, *right;
	vec3_t		v_forward, v_right, v_up;
	msprite_t		*psprite;

	// don't even bother culling, because it's just a single
	// polygon without a surface cache
	frame = R_GetSpriteFrame (e);
	psprite = (msprite_t*) currententity->model->cache.data;

	if (psprite->type == SPR_ORIENTED)
	{	// bullet marks on walls
		AngleVectors (currententity->angles, v_forward, v_right, v_up);
		up = v_up;
		right = v_right;
	}
	else
	{	// normal sprite
		up = vup;
		right = vright;
	}

	glColor3f (1,1,1);

	GL_DisableMultitexture();

    GL_Bind(frame->gl_texturenum);

	glEnable (GL_ALPHA_TEST);

#ifdef USE_OPENGLES

	{
	    float* pPoint = gVertexBuffer;
	    float texCoords[] = {
			0, 1,
			0, 0,
			1, 0,
			1, 1
		};

		VectorMA (e->origin, frame->down, up, point);
		VectorMA (point, frame->left, right, pPoint);
		pPoint += 3;

		VectorMA (e->origin, frame->up, up, point);
		VectorMA (point, frame->left, right, pPoint);
		pPoint += 3;

		VectorMA (e->origin, frame->up, up, point);
		VectorMA (point, frame->right, right, pPoint);
		pPoint += 3;

		VectorMA (e->origin, frame->down, up, point);
		VectorMA (point, frame->right, right, pPoint);

		glVertexPointer(3, GL_FLOAT, 0, gVertexBuffer);
		glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
	}

#else
	glBegin (GL_QUADS);

	glTexCoord2f (0, 1);
	VectorMA (e->origin, frame->down, up, point);
	VectorMA (point, frame->left, right, point);
	glVertex3fv (point);

	glTexCoord2f (0, 0);
	VectorMA (e->origin, frame->up, up, point);
	VectorMA (point, frame->left, right, point);
	glVertex3fv (point);

	glTexCoord2f (1, 0);
	VectorMA (e->origin, frame->up, up, point);
	VectorMA (point, frame->right, right, point);
	glVertex3fv (point);

	glTexCoord2f (1, 1);
	VectorMA (e->origin, frame->down, up, point);
	VectorMA (point, frame->right, right, point);
	glVertex3fv (point);

	glEnd ();
#endif

	glDisable (GL_ALPHA_TEST);
}
Ejemplo n.º 14
0
Archivo: rain.c Proyecto: prophile/dim3
void rain_draw(int tick)
{
	int				n,xadd,yadd,zadd,density,
					slant_add,slant_mult,slant_div;
	float			slant_ang_y;
	float			*vertex_ptr,*col_ptr;
	rain_draw_type	*rain_draw;

		// is rain on and not under liquid?

	if (!map.rain.on) return;
	if (view.render->camera.under_liquid_idx!=-1) return;
	
		// reset on?
		
	if (map.rain.reset) {
		map.rain.reset=FALSE;
		rain_setup(tick,view.render->camera.pnt.x,view.render->camera.pnt.y,view.render->camera.pnt.z);
	}
	
		// rain slant
		
	slant_add=rain_slant_add;
	slant_ang_y=rain_slant_ang_y;
		
	if (map.rain.slant_time_msec!=0) {
		
			// time to change slant?
			
		if (tick>rain_slant_next_end_tick) {
			rain_slant_add=slant_add=rain_slant_next_add;
			rain_slant_ang_y=slant_ang_y=rain_slant_next_ang_y;
			rain_setup_next_slant(tick);
		}
		else {
		
				// slant in the middle of changing
				
			if (tick>rain_slant_next_start_tick) {
				slant_mult=tick-rain_slant_next_start_tick;
				slant_div=(rain_slant_next_end_tick-rain_slant_next_start_tick);
				
				slant_add=rain_slant_add+(((rain_slant_next_add-rain_slant_add)*slant_mult)/slant_div);
				slant_ang_y=rain_slant_ang_y+((rain_slant_next_ang_y-rain_slant_ang_y)*((float)slant_mult/(float)slant_div));
			}
			
		}
	}

	angle_get_movement(slant_ang_y,slant_add,&xadd,&zadd);

		// rain change

	xadd=(tick-rain_last_tick)*xadd;
	yadd=(tick-rain_last_tick)*map.rain.speed;
	zadd=(tick-rain_last_tick)*zadd;
	
	rain_last_tick=tick;

		// rain density

	density=map.rain.density;
	if (density>max_rain_density) density=max_rain_density;

		// construct VBO

	vertex_ptr=view_bind_map_next_vertex_object(((density*2)*(3+4)));
	if (vertex_ptr==NULL) return;

	col_ptr=vertex_ptr+((density*2)*3);

		// create vertexes

	rain_draw=view.rain_draws;

	for (n=0;n!=density;n++) {

			// move rain

		rain_draw->x+=xadd;
		rain_draw->y+=yadd;
		rain_draw->z+=zadd;
		
		if (rain_draw->y>rain_draw->by) rain_setup_single_reset(rain_draw,view.render->camera.pnt.x,view.render->camera.pnt.y,view.render->camera.pnt.z);

			// draw rain

		*vertex_ptr++=(float)rain_draw->x;
		*vertex_ptr++=(float)rain_draw->y;
		*vertex_ptr++=(float)rain_draw->z;

		*col_ptr++=map.rain.start_color.r;
		*col_ptr++=map.rain.start_color.g;
		*col_ptr++=map.rain.start_color.b;
		*col_ptr++=map.rain.alpha;

		*vertex_ptr++=(float)(rain_draw->x+xadd);
		*vertex_ptr++=(float)(rain_draw->y+map.rain.line_length);
		*vertex_ptr++=(float)(rain_draw->z+zadd);

		*col_ptr++=map.rain.end_color.r;
		*col_ptr++=map.rain.end_color.g;
		*col_ptr++=map.rain.end_color.b;
		*col_ptr++=map.rain.alpha;

		rain_draw++;
	}

  	view_unmap_current_vertex_object();

		// setup view

	gl_3D_view();
	gl_3D_rotate(&view.render->camera.pnt,&view.render->camera.ang);
	gl_setup_project();
	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glDisable(GL_ALPHA_TEST);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glDepthMask(GL_FALSE);

		// draw the rain

	glLineWidth((float)map.rain.line_width);

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3,GL_FLOAT,0,(void*)0);
		
	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4,GL_FLOAT,0,(void*)(((density*2)*3)*sizeof(float)));

	glDrawArrays(GL_LINES,0,(density*2));

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

	glLineWidth(1);

		// unbind the vbo

	view_unbind_current_vertex_object();
}
Ejemplo n.º 15
0
void LayerBase::drawWithOpenGL(const Region& clip) const
{
    const DisplayHardware& hw(graphicPlane(0).displayHardware());
    const uint32_t fbHeight = hw.getHeight();
    const State& s(drawingState());

    GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
    if (CC_UNLIKELY(s.alpha < 0xFF)) {
        const GLfloat alpha = s.alpha * (1.0f/255.0f);
        if (mPremultipliedAlpha) {
            glColor4f(alpha, alpha, alpha, alpha);
        } else {
            glColor4f(1, 1, 1, alpha);
        }
        glEnable(GL_BLEND);
        glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    } else {
        glColor4f(1, 1, 1, 1);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        if (!isOpaque()) {
            glEnable(GL_BLEND);
            glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
        } else {
            glDisable(GL_BLEND);
        }
    }

    struct TexCoords {
        GLfloat u;
        GLfloat v;
    };

    Rect crop(s.active.w, s.active.h);
    if (!s.active.crop.isEmpty()) {
        crop = s.active.crop;
    }
    GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
    GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
    GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
    GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);

    TexCoords texCoords[4];
    texCoords[0].u = left;
    texCoords[0].v = top;
    texCoords[1].u = left;
    texCoords[1].v = bottom;
    texCoords[2].u = right;
    texCoords[2].v = bottom;
    texCoords[3].u = right;
    texCoords[3].v = top;
    for (int i = 0; i < 4; i++) {
        texCoords[i].v = 1.0f - texCoords[i].v;
    }

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, mVertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_BLEND);
}
Ejemplo n.º 16
0
void Model::renderMesh(bool bWireframe, bool bLight)
{
  // get the renderer of the model
  CalRenderer *pCalRenderer;
  pCalRenderer = m_calModel->getRenderer();

  // begin the rendering loop
  if(!pCalRenderer->beginRendering()) return;

  // set wireframe mode if necessary

  // set the global OpenGL states
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);

  // set the lighting mode if necessary
  if(bLight)
  {
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
  }

  // we will use vertex arrays, so enable them
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);

  // get the number of meshes
  int meshCount;
  meshCount = pCalRenderer->getMeshCount();

  // render all meshes of the model
  int meshId;
  for(meshId = 0; meshId < meshCount; meshId++)
  {
    // get the number of submeshes
    int submeshCount;
    submeshCount = pCalRenderer->getSubmeshCount(meshId);

    // render all submeshes of the mesh
    int submeshId;
    for(submeshId = 0; submeshId < submeshCount; submeshId++)
    {
      // select mesh and submesh for further data access
      if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
      {
        unsigned char meshColor[4];
        GLfloat materialColor[4];

        // set the material ambient color
        pCalRenderer->getAmbientColor(&meshColor[0]);
        materialColor[0] = CLAMP(meshColor[0] / 255.0f,0,1);  materialColor[1] = CLAMP(meshColor[1] / 255.0f,0,1);
	    materialColor[2] = CLAMP(meshColor[2] / 255.0f,0,1);  materialColor[3] = CLAMP(meshColor[3] / 255.0f,0,1);
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materialColor);

        // set the material diffuse color
        pCalRenderer->getDiffuseColor(&meshColor[0]);

        materialColor[0] = CLAMP(meshColor[0] / 255.0f,0,1);  materialColor[1] = CLAMP(meshColor[1] / 255.0f,0,1);
        materialColor[2] = CLAMP(meshColor[2] / 255.0f,0,1);  materialColor[3] = 1;//CLAMP(meshColor[3] / 255.0f,0,1);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialColor);

        // set the vertex color if we have no lights
        if(!bLight)
        {
          glColor4f(materialColor[0],materialColor[1],materialColor[2],materialColor[3]);
        }

        // set the material specular color
        pCalRenderer->getSpecularColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialColor);

        // set the material shininess factor
        float shininess;
        shininess = 50.0f; //TODO: pCalRenderer->getShininess();
        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &shininess);

        // get the transformed vertices of the submesh
        static float meshVertices[30000][3];
        int vertexCount;
        vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);

        // get the transformed normals of the submesh
        static float meshNormals[30000][3];
        pCalRenderer->getNormals(&meshNormals[0][0]);

        // get the texture coordinates of the submesh
        static float meshTextureCoordinates[30000][2];
        int textureCoordinateCount;
        textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);

        // get the faces of the submesh
        static CalIndex meshFaces[50000][3];
        int faceCount;
        faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);

        // set the vertex and normal buffers
        glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
        glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);

        // set the texture coordinate buffer and state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glEnable(GL_TEXTURE_2D);
          glEnableClientState(GL_TEXTURE_COORD_ARRAY);
          glEnable(GL_COLOR_MATERIAL);

          // set the texture id we stored in the map user data
          glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));

          // set the texture coordinate buffer
          glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
          glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        }

        // draw the submesh
        if(bWireframe)
            glDrawElements(GL_LINES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
        else
        //if(sizeof(CalIndex)==2)
            glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
        //else
		//	  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);

        // disable the texture coordinate state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glDisable(GL_COLOR_MATERIAL);
          glDisableClientState(GL_TEXTURE_COORD_ARRAY);
          glDisable(GL_TEXTURE_2D);
        }

// DEBUG-CODE //////////////////////////////////////////////////////////////////
/*
glBegin(GL_LINES);
glColor3f(1.0f, 1.0f, 1.0f);
int vertexId;
for(vertexId = 0; vertexId < vertexCount; vertexId++)
{
const float scale = 0.3f;
  glVertex3f(meshVertices[vertexId][0], meshVertices[vertexId][1], meshVertices[vertexId][2]);
  glVertex3f(meshVertices[vertexId][0] + meshNormals[vertexId][0] * scale, meshVertices[vertexId][1] + meshNormals[vertexId][1] * scale, meshVertices[vertexId][2] + meshNormals[vertexId][2] * scale);
}
glEnd();
*/
////////////////////////////////////////////////////////////////////////////////
      }
    }
  }

  // clear vertex array state
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

  // reset the lighting mode
  if(bLight)
  {
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
  }

  // reset the global OpenGL states
  glDisable(GL_DEPTH_TEST);

  // end the rendering
  pCalRenderer->endRendering();
}
// this doesn't yet work, it is an attempt to port over the point sprite logic
// from opengles. It draws the point sprites but it doesn't replace the point
// size or color values. I left it here in case anyone wants to fix it :)
void ofxParticleEmitter::drawPoints()
{
	// Disable the texture coord array so that texture information is not copied over when rendering
	// the point sprites.
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
	// Bind to the verticesID VBO and popuate it with the necessary vertex & color informaiton
	glBindBuffer(GL_ARRAY_BUFFER, verticesID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(PointSprite) * maxParticles, vertices, GL_DYNAMIC_DRAW);
	
	// Configure the vertex pointer which will use the currently bound VBO for its data
	glVertexPointer(2, GL_FLOAT, sizeof(PointSprite), 0);
	glColorPointer(4,GL_FLOAT,sizeof(PointSprite),(GLvoid*) (sizeof(GLfloat)*3));
	
	// Bind to the particles texture
	glBindTexture(GL_TEXTURE_2D, (GLuint)textureData.textureID);
	
	// Enable the point size array
	
	
	//glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
	
	
	// Configure the point size pointer which will use the currently bound VBO.  PointSprite contains
	// both the location of the point as well as its size, so the config below tells the point size
	// pointer where in the currently bound VBO it can find the size for each point
	
	
	//glPointSizePointerOES(GL_FLOAT,sizeof(PointSprite),(GLvoid*) (sizeof(GL_FLOAT)*2));
	
	
	// Change the blend function used if blendAdditive has been set
	
    // Set the blend function based on the configuration
    glBlendFunc(blendFuncSource, blendFuncDestination);
	
	// Enable and configure point sprites which we are going to use for our particles
	glEnable(GL_POINT_SPRITE);
	glTexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
	
	// Now that all of the VBOs have been used to configure the vertices, pointer size and color
	// use glDrawArrays to draw the points
	glDrawArrays(GL_POINTS, 0, particleIndex);
	
	// Unbind the current VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// Disable the client states which have been used incase the next draw function does 
	// not need or use them
	
	
	//glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
	
	
	glDisable(GL_POINT_SPRITE);
	
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	// Re-enable the texture coordinates as we use them elsewhere in the game and it is expected that
	// its on
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
Ejemplo n.º 18
0
int EspaceGL::afficher_briques_dock ()
{
    if ( m_ptr_dock->possede_element_flotant() )
        afficher_brique_flotante_dock();

    _3d tmp = {0, 0, 0};
    Uint32 timer_a;
    Uint32 timer_b;

    //std::cout<< BusApp::ref_instance().position_souris().x <<std::endl;

    //std::cout << m_ptr_dock->n_elem()<< " briques dock"<<std::endl;
   // std::cout << m_ptr_briques_dock->size() << " briques dock"<<std::endl;
    int h = 0;
    timer_a = SDL_GetTicks();
    while ( h < (int) m_ptr_dock->n_elem())
    {
        int l = 0;
        int limite = 500000;

        do
        {
            Brique* brique = m_ptr_dock->montrer_ptr_brique(h);

        /* arriere plan maillon : */
            if ( m_ptr_dock->element(h).est_verrouille() ) m_rc = m_gc = m_bc = 255; else m_rc = m_gc = m_bc = 235;
            tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();
            (*m_triangles_array).e[l] = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] = (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;
            tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            (*m_triangles_array).e[l] = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] = (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;
            tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            (*m_triangles_array).e[l]   = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] =   (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;

            tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            (*m_triangles_array).e[l] = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] = (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;
            tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            (*m_triangles_array).e[l] = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] = (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;
            tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
            tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
            (*m_triangles_array).e[l] = tmp.x;
            (*m_triangles_array).e[l+1] = tmp.y;
            (*m_triangles_array).e[l+2] = tmp.z;
            (*m_triangles_array).c[l] = (unsigned char) m_rc;
            (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
            (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
            l+=3;

        /** indicateur verrou maillon*/

            /* on choisit la bonne couleur */
            if ( ! m_ptr_dock->element(h).est_verrouille() ) m_rc = m_gc = m_bc = 255;
            else
            {
                m_rc = m_gc = m_bc = 0;

                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+5+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+5+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom() +5;
                (*m_triangles_array).e[l] = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] = (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;
                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+5+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                (*m_triangles_array).e[l] = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] = (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;
                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                (*m_triangles_array).e[l]   = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] =   (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;

                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+5+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+5+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                (*m_triangles_array).e[l] = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] = (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;
                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                (*m_triangles_array).e[l] = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] = (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;
                tmp.x = (double) m_ptr_dock->element(h).montrer_x()+5+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
                tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
                (*m_triangles_array).e[l] = tmp.x;
                (*m_triangles_array).e[l+1] = tmp.y;
                (*m_triangles_array).e[l+2] = tmp.z;
                (*m_triangles_array).c[l] = (unsigned char) m_rc;
                (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
                (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
                l+=3;
            }
            _col c = brique->montrer_couleur();
            std::vector <_3d> tmpliste = brique->get_vtxtri();

             //positionement

            double mf[16];
            double mr[16];
            brique->copier_matrice_finale_dans(mf);
            brique->copier_matrice_rotation_dans(mr);

            for ( int i = 0 ; i < (int) tmpliste.size() ; i+=4 )
            {
                tmp = tmpliste[i+3];
                mathematicien.appliquer_matrice(mr, &tmp);
                if (tmp.z<0) tmp.z = -tmp.z;
                tmp.z = m_lumiere_ambiante+(1-m_lumiere_ambiante)*tmp.z;
                unsigned char rc = tmp.z*c.r, bc = tmp.z*c.b, gc = tmp.z*c.g;
                for ( int j = i ; j < i+3 ; j++ )
                {
                    tmp = tmpliste[j];
                    mathematicien.appliquer_matrice(mf, &tmp);

                int mx =  m_ptr_dock->element(h).obt_x();
                int my =  m_ptr_dock->element(h).obt_y();

                    mathematicien.perspective_inconsciente_2( &tmp.x, mx, my);
                    (*m_triangles_array).e[l] = tmp.x;
                    (*m_triangles_array).e[l+1] = tmp.y;
                    (*m_triangles_array).e[l+2] = tmp.z;
                    (*m_triangles_array).c[l] = rc;
                    (*m_triangles_array).c[l+1] = gc;
                    (*m_triangles_array).c[l+2] = bc;
                     l+=3;
                }
            }

            h++;
        } while ( l < limite &&  h < (int) m_ptr_dock->n_elem());
        (*m_triangles_array).n = l;

        glEnable (GL_BLEND);

    // Activation des vertex array
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
    // Faces
        glVertexPointer(P_SIZE, GL_FLOAT, (P_SIZE)*sizeof((*m_triangles_array).e[0]), (*m_triangles_array).e );
        glColorPointer(C_SIZE, GL_UNSIGNED_BYTE, (C_SIZE)*sizeof((*m_triangles_array).c[0]), &(*m_triangles_array).c);
        glDrawArrays(GL_TRIANGLES, 0,(*m_triangles_array).n/P_SIZE );

    // Desctivation des vertex array
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
    }
    timer_b = SDL_GetTicks();
    //std::cout << "        (affichage dock : " << timer_b - timer_a << " milisec )"<< std::endl;

    return 0;

}
Ejemplo n.º 19
0
static void setup_state(const char* vtxs, const ALLEGRO_VERTEX_DECL* decl, ALLEGRO_BITMAP* texture)
{
   if(decl) {
      ALLEGRO_VERTEX_ELEMENT* e;
      e = &decl->elements[ALLEGRO_PRIM_POSITION];
      if(e->attribute) {
         int ncoord = 0;
         GLenum type = 0;
         bool normalized;

         glEnableClientState(GL_VERTEX_ARRAY);

         convert_storage(e->storage, &type, &ncoord, &normalized);

         glVertexPointer(ncoord, type, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_VERTEX_ARRAY);
      }

      e = &decl->elements[ALLEGRO_PRIM_TEX_COORD];
      if(!e->attribute)
         e = &decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL];
      if(texture && e->attribute) {
         int ncoord = 0;
         GLenum type = 0;
         bool normalized;

         glEnableClientState(GL_TEXTURE_COORD_ARRAY);

         convert_storage(e->storage, &type, &ncoord, &normalized);

         glTexCoordPointer(ncoord, type, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
      }

      e = &decl->elements[ALLEGRO_PRIM_COLOR_ATTR];
      if(e->attribute) {
         glEnableClientState(GL_COLOR_ARRAY);

         glColorPointer(4, GL_FLOAT, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_COLOR_ARRAY);
         glColor4f(1, 1, 1, 1);
      }
   } else {
      const ALLEGRO_VERTEX* vtx = (const ALLEGRO_VERTEX*)vtxs;
   
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      glVertexPointer(3, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].x);
      glColorPointer(4, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].color.r);
      glTexCoordPointer(2, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].u);
   }

   if (texture) {
      GLuint gl_texture = al_get_opengl_texture(texture);
      int true_w, true_h;
      int tex_x, tex_y;
      GLuint current_texture;
      float mat[4][4] = {
         {1,  0,  0, 0},
         {0, -1,  0, 0},
         {0,  0,  1, 0},
         {0,  0,  0, 1}
      };
      int height;

      if (texture->parent)
         height = texture->parent->h;
      else
         height = texture->h;
      
      al_get_opengl_texture_size(texture, &true_w, &true_h);
      al_get_opengl_texture_position(texture, &tex_x, &tex_y);
      
      mat[3][0] = (float)tex_x / true_w;
      mat[3][1] = (float)(height - tex_y) / true_h;
         
      if(decl) {
         if(decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL].attribute) {
            mat[0][0] = 1.0f / true_w;
            mat[1][1] = -1.0f / true_h;
         } else {
            mat[0][0] = (float)al_get_bitmap_width(texture) / true_w;
            mat[1][1] = -(float)al_get_bitmap_height(texture) / true_h;
         }
      } else {
         mat[0][0] = 1.0f / true_w;
         mat[1][1] = -1.0f / true_h;
      }

      glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&current_texture);
      if (current_texture != gl_texture) {
         glBindTexture(GL_TEXTURE_2D, gl_texture);
      }

      glMatrixMode(GL_TEXTURE);
      glLoadMatrixf(mat[0]);
      glMatrixMode(GL_MODELVIEW);
   } else {
      glBindTexture(GL_TEXTURE_2D, 0);
   }
}
Ejemplo n.º 20
0
int EspaceGL::afficher_briques_2 (void)
{
    std::vector <Brique*> &b = (*m_ptr_briques);

    _3d tmp = {0, 0, 0};
    int mx = BusApp::ref_instance().renvoyer_resolution_fenetre().x/2;
    int my = BusApp::ref_instance().renvoyer_resolution_fenetre().y/2;

    int h = 0;
    while ( h < (int) b.size())
    {

        int l = 0;
        int limite = 500000;

        do
        {


            Brique* brique = m_ptr_briques->at(h);

                _col c = brique->montrer_couleur();
                std::vector <_3d> tmpliste = brique->get_vtxtri();
                //arr = brique->get_ptr_arrays();
                //(*m_triangles_array).n = 0;


                 //positionement
                double mf[16];
                double mr[16];
                brique->copier_matrice_finale_dans(mf);


                mathematicien.produit(mf, m_Cam_matF);
             //   mathematicien.produit(mf, mb);

                brique->copier_matrice_rotation_dans(mr);
                mathematicien.produit(mr, m_Cam_matR);

                // affichage des faces
           _3d pos = brique->get_centre();

            Mathematicien().appliquer_matrice(mf, &pos);
            if ( (pos.z < LIMITE_PROCHE) && (pos.z > LIMITE_LOIN) )
            {

                for ( int i = 0 ; i < (int) tmpliste.size() ; i+=4 )
                {
                    tmp = tmpliste[i+3];
                    mathematicien.appliquer_matrice(mr, &tmp);
                    if (tmp.z<0) tmp.z = -tmp.z;
                   // tmp.z = m_lumiere_ambiante+(1-m_lumiere_ambiante)*tmp.z;
                    unsigned char rc = tmp.z*c.r, bc = tmp.z*c.b, gc = tmp.z*c.g;
                    for ( int j = i ; j < i+3 ; j++ )
                    {
                        tmp = tmpliste[j];

                        mathematicien.perspective_folle(&(*m_triangles_array).e[l], &tmp.x, mf, mx, my);
                        (*m_triangles_array).c[l] = rc; l++;
                        (*m_triangles_array).c[l] = gc; l++;
                        (*m_triangles_array).c[l] = bc; l++;
                    }
                }
            }
            h++;
            //
            //
        } while ( l < limite && h < (int) b.size());
        (*m_triangles_array).n = l;
        glEnable (GL_BLEND);

    // Activation des vertex array
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
    // Faces
        glVertexPointer(P_SIZE, GL_FLOAT, (P_SIZE)*sizeof((*m_triangles_array).e[0]), (*m_triangles_array).e );
        glColorPointer(C_SIZE, GL_UNSIGNED_BYTE, (C_SIZE)*sizeof((*m_triangles_array).c[0]), &(*m_triangles_array).c);
//        glNormalPointer();
        glDrawArrays(GL_TRIANGLES, 0,(*m_triangles_array).n/P_SIZE );

    // Desctivation des vertex array
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
    }
    return 0;

}
int main( void )
{
    GLFWwindow *window;
    
    // Initialize the library
    if ( !glfwInit( ) )
    {
        return -1;
    }
    
    // Create a windowed mode window and its OpenGL context
    window = glfwCreateWindow( SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL );
    
    if ( !window )
    {
        glfwTerminate( );
        return -1;
    }
    
    // Make the window's context current
    glfwMakeContextCurrent( window );
    
    glViewport( 0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT ); // specifies the part of the window to which OpenGL will draw (in pixels), convert from normalised to pixels
    glMatrixMode( GL_PROJECTION ); // projection matrix defines the properties of the camera that views the objects in the world coordinate frame. Here you typically set the zoom factor, aspect ratio and the near and far clipping planes
    glLoadIdentity( ); // replace the current matrix with the identity matrix and starts us a fresh because matrix transforms such as glOrpho and glRotate cumulate, basically puts us at (0, 0, 0)
    glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1 ); // essentially set coordinate system
    glMatrixMode( GL_MODELVIEW ); // (default matrix mode) modelview matrix defines how your objects are transformed (meaning translation, rotation and scaling) in your world
    glLoadIdentity( ); // same as above comment
    
    GLfloat polygonVertices[] =
    {
        320, 240, 0,
        370, 290, 0,
        420, 240, 0,
        370, 190, 0
    };
    
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    
    // Loop until the user closes the window
    while ( !glfwWindowShouldClose( window ) )
    {
        glClear( GL_COLOR_BUFFER_BIT );

        // render OpenGL here
        glEnableClientState( GL_VERTEX_ARRAY );
        glVertexPointer( 3, GL_FLOAT, 0, polygonVertices );
        glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
        glDisableClientState( GL_VERTEX_ARRAY );
        
        // Swap front and back buffers
        glfwSwapBuffers( window );
        
        // Poll for and process events
        glfwPollEvents( );
    }
    
    glfwTerminate( );
    
    return 0;
}
Ejemplo n.º 22
0
int EspaceGL::afficher_brique_flotante_dock ()
{

    _3d tmp = {0, 0, 0};
    Uint32 timer_a;
    Uint32 timer_b;

    int h = 0;
    timer_a = SDL_GetTicks();
    while ( h < (int) m_ptr_dock->n_elem())
    {
        int l = 0;
        int limite = 500000;

        do
        {
            Brique* brique = m_ptr_dock->montrer_ptr_brique_flotante();
            _col c = brique->montrer_couleur();
            std::vector <_3d> tmpliste = brique->get_vtxtri();

             //positionement

            double mf[16];
            double mr[16];
            brique->copier_matrice_finale_dans(mf);
            brique->copier_matrice_rotation_dans(mr);

            for ( int i = 0 ; i < (int) tmpliste.size() ; i+=4 )
            {
                tmp = tmpliste[i+3];
                mathematicien.appliquer_matrice(mr, &tmp);
                if (tmp.z<0) tmp.z = -tmp.z;
                tmp.z = m_lumiere_ambiante+(1-m_lumiere_ambiante)*tmp.z;
                unsigned char rc = tmp.z*c.r, bc = tmp.z*c.b, gc = tmp.z*c.g;
                for ( int j = i ; j < i+3 ; j++ )
                {
                    tmp = tmpliste[j];
                    mathematicien.appliquer_matrice(mf, &tmp);

                    int mx =  BusApp::ref_instance().position_souris().x;
                    int my =  BusApp::ref_instance().position_souris().y;

                    mathematicien.perspective_inconsciente_2( &tmp.x, mx, my);
                    (*m_triangles_array).e[l] = tmp.x;
                    (*m_triangles_array).e[l+1] = tmp.y;
                    (*m_triangles_array).e[l+2] = tmp.z;
                    (*m_triangles_array).c[l] = rc;
                    (*m_triangles_array).c[l+1] = gc;
                    (*m_triangles_array).c[l+2] = bc;
                     l+=3;
                }
            }

            h++;
        } while ( l < limite &&  h < (int) m_ptr_dock->n_elem());
        (*m_triangles_array).n = l;

        glEnable (GL_BLEND);

    // Activation des vertex array
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
    // Faces
        glVertexPointer(P_SIZE, GL_FLOAT, (P_SIZE)*sizeof((*m_triangles_array).e[0]), (*m_triangles_array).e );
        glColorPointer(C_SIZE, GL_UNSIGNED_BYTE, (C_SIZE)*sizeof((*m_triangles_array).c[0]), &(*m_triangles_array).c);
        glDrawArrays(GL_TRIANGLES, 0,(*m_triangles_array).n/P_SIZE );

    // Desctivation des vertex array
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
    }
    timer_b = SDL_GetTicks();
    //std::cout << "        (affichage dock : " << timer_b - timer_a << " milisec )"<< std::endl;

    return 0;

}
Ejemplo n.º 23
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
void Render()
{
    glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
	glClearDepth(1.0F);

	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT);

	//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glShadeModel(GL_SMOOTH);

	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
	//gluLookAt(0, 0, 1, 0, 0, -5, 0, 1, 0);
    //glTranslatef(0.0f, 0.0f, -0.1f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //gluPerspective(90.0f, 1.0, 0.1f, 100.0f);
	glFrustum(-1, 1, -1, 1, 0.95, 10);

	/*//glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	//glTranslatef(0.0f, 0.0f,-4.0f);
	gluLookAt(0, 0, 0, 0, 0, -5, 0, 1, 0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, 1.0f, 0.1f, 100.0f);*/

	



    /*glBindBuffer(GL_ARRAY_BUFFER, BufferName[COLOR_OBJECT]);
    glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, BufferName[POSITION_OBJECT]);
    glVertexPointer(2, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_TRIANGLES, 0, VertexCount);

    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

	glBindBuffer(GL_ARRAY_BUFFER, 0);*/




	//AE::uint strideInBytes = 11;
	AE::uint strideInBytes = 15;
	AE::uint sizeofFloat = sizeof(float);
	AE::uint sizeOfFloatTimesTwo = sizeofFloat * 2;
	AE::uint sizeOfFloatTimesThree = sizeofFloat * 3;

	glBindBuffer(GL_ARRAY_BUFFER, bufferId);
	//glVertexPointer(2, GL_FLOAT, strideInBytes, AE_GL_BUFFER_OFFSET(0));
	glVertexPointer(3, GL_FLOAT, strideInBytes, AE_GL_BUFFER_OFFSET(0));
	//glColorPointer(3, GL_UNSIGNED_BYTE, strideInBytes, AE_GL_BUFFER_OFFSET(sizeOfFloatTimesTwo));
	glColorPointer(3, GL_UNSIGNED_BYTE, strideInBytes, AE_GL_BUFFER_OFFSET(sizeOfFloatTimesThree));

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferId);
	size_t error = glGetError();

	//glDrawArrays(GL_TRIANGLES, 0, 3);
	glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, AE_GL_BUFFER_OFFSET(0));
	error = glGetError();

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

	glBindBuffer(GL_ARRAY_BUFFER, 0);




	/*glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_POLYGON);
		glVertex3f(0.25, 0.25, 0.0);
		glVertex3f(0.75, 0.25, 0.0);
		glVertex3f(0.75, 0.75, 0.0);
		glVertex3f(0.25, 0.75, 0.0);
	glEnd();*/



	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glViewport(0, 0, 300, 300);

	// Reset the coordinate system before modifying

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Pseudo window coordinates
    gluOrtho2D(0.0, (GLfloat) 300, 0.0f, (GLfloat) 300);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


	GLuint *pImage = (GLuint *)(malloc(sizeof(GLuint)));
	pImage[0] = 0xFFFF00FF;
	glRasterPos2i(50, 50);
	glDrawPixels(1, 1, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pImage);
	free(pImage);




	::SwapBuffers(deviceContext);
}
Ejemplo n.º 24
0
int EspaceGL::afficher_briques_dock_offscreen ( void )
{

    _3d tmp = {0, 0, 0};
    Uint32 timer_a;
    Uint32 timer_b;

   // std::cout<< BusApp::ref_instance().position_souris().x <<std::endl;

    //std::cout << m_ptr_dock->n_elem()<< " briques dock off"<<std::endl;
   // std::cout << m_ptr_briques_dock->size() << " briques dock"<<std::endl;
    int h = 0;
    timer_a = SDL_GetTicks();
    while ( h < (int) m_ptr_dock->n_elem())
    {
        int l = 0;
        int limite = 500000;

        do
        {
            Brique* brique = m_ptr_dock->montrer_ptr_brique(h);

        tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;
        tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();;
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;
        tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();;
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;

        tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()-m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();;
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;
        tmp.x = (double) m_ptr_dock->element(h).montrer_x()+m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();;
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;
        tmp.x = (double) m_ptr_dock->element(h).montrer_x()-m_ptr_dock->element(h).montrer_w()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.y = (double) m_ptr_dock->element(h).montrer_y()+m_ptr_dock->element(h).montrer_h()*-m_ptr_dock->element(h).montrer_zoom()/2;
        tmp.z = -1000.000000+10*m_ptr_dock->element(h).montrer_zoom();;
        (*m_triangles_array).e[l] = tmp.x;
        (*m_triangles_array).e[l+1] = tmp.y;
        (*m_triangles_array).e[l+2] = tmp.z;
        (*m_triangles_array).c[l] = (unsigned char) m_rc;
        (*m_triangles_array).c[l+1] = (unsigned char) m_gc;
        (*m_triangles_array).c[l+2] = (unsigned char) m_bc;
        l+=3;
        m_map_ptr_brique[m_ptr] = brique;
        m_map_id_surface_brique[m_ptr] = -1;

        m_ptr++; m_rc++; if (m_rc==256) { m_rc = 0; m_gc++; if (m_gc==256) { m_gc = 0; m_bc++;	} }

            std::vector <_3d> tmpliste = brique->get_vtxsom();
            (*m_triangles_array).n = 0;


             //positionement
            double mf[16];
            double mr[16];

            brique->copier_matrice_finale_dans(mf);

            brique->copier_matrice_rotation_dans(mr);



                // affichage des faces
                for ( int j = 0 ; j < brique->n_surface() ; j++)
                {

                    for ( int i = 0 ; i < brique->surface(j).n_tri()*3 ; i++ )
                    {
                        tmp = tmpliste[brique->surface(j).som(i)];
                    //    mathematicien.appliquer_matrice(mf, &tmp);
                         mathematicien.appliquer_matrice(mf, &tmp);

                        int mx =  m_ptr_dock->element(h).obt_x();
                        int my =  m_ptr_dock->element(h).obt_y();

                        mathematicien.perspective_inconsciente_2( &tmp.x, mx, my);
                        (*m_triangles_array).e[l] = tmp.x;
                        (*m_triangles_array).c[l] = (unsigned char) (m_rc); l++;
                        (*m_triangles_array).e[l] = tmp.y;
                        (*m_triangles_array).c[l] = (unsigned char) (m_gc); l++;
                        (*m_triangles_array).e[l] = tmp.z;
                        (*m_triangles_array).c[l] = (unsigned char) (m_bc); l++;
                    }
                    m_map_id_surface_brique[m_ptr] = j;
                    m_map_ptr_brique[m_ptr] = brique;
                    m_ptr++; m_rc++; if (m_rc==256) { m_rc = 0; m_gc++; if (m_gc==256) { m_gc = 0; m_bc++;	} }
                }

            h++;
        } while ( l < limite &&  h < (int) m_ptr_dock->n_elem());
        (*m_triangles_array).n = l;

        glEnable (GL_BLEND);

    // Activation des vertex array
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
    // Faces
        glVertexPointer(P_SIZE, GL_FLOAT, (P_SIZE)*sizeof((*m_triangles_array).e[0]), (*m_triangles_array).e );
        glColorPointer(C_SIZE, GL_UNSIGNED_BYTE, (C_SIZE)*sizeof((*m_triangles_array).c[0]), &(*m_triangles_array).c);
        glDrawArrays(GL_TRIANGLES, 0,(*m_triangles_array).n/P_SIZE );

    // Desctivation des vertex array
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
    }
    timer_b = SDL_GetTicks();
    //std::cout << "        (affichage dock : " << timer_b - timer_a << " milisec )"<< std::endl;
    m_taille_map_brique = m_ptr;

    return 0;

}
//! Render piclist texture
void Storm3D_Scene_PicList_Picture::Render()
{
	IStorm3D_Material::ATYPE alphaType = IStorm3D_Material::ATYPE_NONE;
	if(material)
	{
		alphaType = material->GetAlphaType();
		if(alpha < 0.99f && alphaType == IStorm3D_Material::ATYPE_NONE)
			material->SetAlphaType(IStorm3D_Material::ATYPE_USE_TEXTRANSPARENCY);

		// Apply the texture
		material->ApplyBaseTextureExtOnly();

		if(wrap)
		{
 			glActiveTexture(GL_TEXTURE0);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		} else {
 			glActiveTexture(GL_TEXTURE0);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		}

		// Animate
		{
			IStorm3D_Texture *ti = material->GetBaseTexture();
			// FIXED: crashed to null pointer here. -jpk
			if (ti != NULL)
			{
				Storm3D_Texture *t = static_cast<Storm3D_Texture *> (ti);
				t->AnimateVideo();
			}
		}
	}

	// FIXME: ugly hack to work around disappearing grenade throw meter
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	// Create 3d-vector
	VC3 pos(position.x,position.y,0);

	// Create color (color+alpha)
	DWORD col = 0xFFFFFFFF;
	if(material)
	{
		COL c(1.f, 1.f, 1.f);
		float newAlpha = 1.f;
		c = material->GetColor();
		newAlpha = alpha * (1-material->GetTransparency());
		col=COLOR_RGBA((int)(c.r*255.0f),(int)(c.g*255.0f),(int)(c.b*255.0f),(int)(newAlpha*255.0f));
		//col = COLOR_RGBA(c.r, c.g, c.b, newAlpha);
	}

	// Render it
	frozenbyte::storm::VertexShader::disable();

	// render with custom shape
	if(customShape && customShape->vertices)
	{
		// use combined alpha
		float alpha_mul = 1.0f;
		if(material)
		{
			alpha_mul = alpha * (1.0f - material->GetTransparency());
		}
		for(int i = 0; i < customShape->numVertices; i++)
		{
			DWORD c = customShape->vertices[i].color;
			int newAlpha = (int)((c >> 24) * alpha_mul);
			c &= 0x00FFFFFF;
			c |= (newAlpha & 0xFF) << 24;
			customShape->vertices[i].color = c;
			customShape->vertices[i].position.x -= .5f;
			customShape->vertices[i].position.y -= .5f;
		}
		glEnableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_NORMAL_ARRAY);
		glEnableClientState(GL_VERTEX_ARRAY);

		glClientActiveTexture(GL_TEXTURE0);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glVertexPointer(3, GL_FLOAT, sizeof(VXFORMAT_2D), &customShape->vertices[0].position);
		glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VXFORMAT_2D), &customShape->vertices[0].color);
		glTexCoordPointer(2, GL_FLOAT, sizeof(VXFORMAT_2D), &customShape->vertices[0].texcoords);

		glDrawArrays(GL_TRIANGLES, 0, customShape->numVertices);
		scene->AddPolyCounter(customShape->numVertices/3);
	}
Ejemplo n.º 26
0
int EspaceGL::afficher_briques_offscreen()
{
    m_ptr = 0;
    Uint32 timer_a, timer_b;

    std::vector <Brique*> &b = (*m_ptr_briques);

    _3d tmp = {0, 0, 0};

    m_map_id_surface_brique[m_ptr] = -1;
    m_map_ptr_brique[m_ptr] = m_ptr_briques->at(0);
    m_ptr++; m_rc++;
    int mx = BusApp::ref_instance().renvoyer_resolution_fenetre().x/2;
    int my = BusApp::ref_instance().renvoyer_resolution_fenetre().y/2;

    int h = 1;
    while ( h < (int) b.size())
    {
        int l = 0;
        int limite = 700000;
        timer_a = SDL_GetTicks();

        do
        {

            Brique* brique = m_ptr_briques->at(h);
            std::vector <_3d> tmpliste = brique->get_vtxsom();
            (*m_triangles_array).n = 0;


             //positionement
            double mf[16];
            double mr[16];

            brique->copier_matrice_finale_dans(mf);
            mathematicien.produit(mf, m_Cam_matF);

            brique->copier_matrice_rotation_dans(mr);
            mathematicien.produit(mr, m_Cam_matR);

           _3d pos = brique->get_centre();

            Mathematicien().appliquer_matrice(mf, &pos);

            if ( pos.z < LIMITE_PROCHE && pos.z > LIMITE_LOIN )
            {


                // affichage des faces
                for ( int j = 0 ; j < brique->n_surface() ; j++)
                {

                    for ( int i = 0 ; i < brique->surface(j).n_tri()*3 ; i++ )
                    {
                        tmp = tmpliste[brique->surface(j).som(i)];
                    //    mathematicien.appliquer_matrice(mf, &tmp);
                        mathematicien.perspective_folle(&(*m_triangles_array).e[l], &tmp.x, mf , mx,my);

                       // (*m_triangles_array).e[l] = tmp.x;
                        (*m_triangles_array).c[l] = (unsigned char) (m_rc); l++;
                        //(*m_triangles_array).e[l] = tmp.y;
                        (*m_triangles_array).c[l] = (unsigned char) (m_gc); l++;
                        //(*m_triangles_array).e[l] = tmp.z;
                        (*m_triangles_array).c[l] = (unsigned char) (m_bc); l++;
                    }
                    m_map_id_surface_brique[m_ptr] = j;
                    m_map_ptr_brique[m_ptr] = brique;
                    m_ptr++; m_rc++; if (m_rc==256) { m_rc = 0; m_gc++; if (m_gc==256) { m_gc = 0; m_bc++;	} }
                }
            }
            h++;
            //
            //
        } while ( l < limite && h < (int) b.size());
        (*m_triangles_array).n = l;
        timer_b = SDL_GetTicks();
        //std::cout << "        array_offsrceen.n (remplissage : " << timer_b - timer_a << " milisec ) : " << l << " vertex"<<std::endl;
        glEnable (GL_BLEND);

    // Activation des vertex array
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
    // Faces
        glVertexPointer(P_SIZE, GL_FLOAT, (P_SIZE)*sizeof((*m_triangles_array).e[0]), (*m_triangles_array).e );
        glColorPointer(C_SIZE, GL_UNSIGNED_BYTE, (C_SIZE)*sizeof((*m_triangles_array).c[0]), &(*m_triangles_array).c);
        glDrawArrays(GL_TRIANGLES, 0,(*m_triangles_array).n/P_SIZE );

   //
//
//     Desctivation des vertex array
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
        timer_a = SDL_GetTicks();
#ifdef COUT_TEMPS8RENDU
        std::cout << "        (affichage : " << timer_a - timer_b << " milisec ) : " <<std::endl;
#endif // COUT_TEMPS8RENDU

    }
    m_taille_map_brique = m_ptr;
    return 0;

}
Ejemplo n.º 27
0
void
Canvas::DrawCircle(int x, int y, unsigned radius)
{
  if (IsPenOverBrush() && pen.GetWidth() > 2) {
    GLDonutVertices vertices(x, y,
                             radius - pen.GetWidth() / 2,
                             radius + pen.GetWidth() / 2);
    if (!brush.IsHollow()) {
      vertices.bind_inner_circle();
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.CIRCLE_SIZE);
    }
    vertices.bind();
    pen.Set();
    glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.SIZE);
  } else if (OpenGL::vertex_buffer_object && radius < 16) {
    /* draw a "small" circle with VBO */

    OpenGL::small_circle_buffer->Bind();
    glVertexPointer(2, GL_SHORT, 0, NULL);

    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)x << 16, (GLfixed)y << 16, 0);
    glScalex((GLfixed)radius << 8, (GLfixed)radius << 8, (GLfixed)1 << 16);
#else
    glTranslatef(x, y, 0.);
    glScalef(radius / 256., radius / 256., 1.);
#endif

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, OpenGL::SMALL_CIRCLE_SIZE);
    }

    if (IsPenOverBrush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, OpenGL::SMALL_CIRCLE_SIZE);
      pen.Unbind();
    }

    glPopMatrix();

    OpenGL::small_circle_buffer->Unbind();
  } else if (OpenGL::vertex_buffer_object) {
    /* draw a "big" circle with VBO */

    OpenGL::circle_buffer->Bind();
    glVertexPointer(2, GL_SHORT, 0, NULL);

    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)x << 16, (GLfixed)y << 16, 0);
    glScalex((GLfixed)radius << 6, (GLfixed)radius << 6, (GLfixed)1 << 16);
#else
    glTranslatef(x, y, 0.);
    glScalef(radius / 1024., radius / 1024., 1.);
#endif

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, OpenGL::CIRCLE_SIZE);
    }

    if (IsPenOverBrush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, OpenGL::CIRCLE_SIZE);
      pen.Unbind();
    }

    glPopMatrix();

    OpenGL::circle_buffer->Unbind();
  } else {
    GLCircleVertices vertices(x, y, radius);
    vertices.bind();

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.SIZE);
    }

    if (IsPenOverBrush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, vertices.SIZE);
      pen.Unbind();
    }
  }
}
void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
{
    const DisplayHardware& hw(graphicPlane(0).displayHardware());
    const uint32_t fbHeight = hw.getHeight();
    const State& s(drawingState());
    
    // bind our texture
    TextureManager::activateTexture(texture, needsFiltering());
    uint32_t width  = texture.width; 
    uint32_t height = texture.height;

    GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;

    int renderEffect = mFlinger->getRenderEffect();
    int renderColorR = mFlinger->getRenderColorR();
    int renderColorG = mFlinger->getRenderColorG();
    int renderColorB = mFlinger->getRenderColorB();

    bool noEffect = renderEffect == 0;

    if (UNLIKELY(s.alpha < 0xFF) && noEffect) {
        const GLfloat alpha = s.alpha * (1.0f/255.0f);
        if (mPremultipliedAlpha) {
            glColor4f(alpha, alpha, alpha, alpha);
        } else {
            glColor4f(1, 1, 1, alpha);
        }
        glEnable(GL_BLEND);
        glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    } else if (noEffect) {
        glColor4f(1, 1, 1, 1);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        if (needsBlending()) {
            glEnable(GL_BLEND);
            glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
        } else {
            glDisable(GL_BLEND);
        }
    } else {
        // Apply a render effect, which is simple color masks for now.
        GLenum env, src;
        env = GL_MODULATE;
        src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
        const GGLfixed alpha = (s.alpha << 16)/255;
        switch (renderEffect) {
            case RENDER_EFFECT_NIGHT:
                glColor4x(alpha, alpha*0.6204, alpha*0.3018, alpha);
                break;
            case RENDER_EFFECT_TERMINAL:
                glColor4x(0, alpha, 0, alpha);
                break;
            case RENDER_EFFECT_BLUE:
                glColor4x(0, 0, alpha, alpha);
                break;
            case RENDER_EFFECT_AMBER:
                glColor4x(alpha, alpha*0.75, 0, alpha);
                break;
            case RENDER_EFFECT_SALMON:
                glColor4x(alpha, alpha*0.5, alpha*0.5, alpha);
                break;
            case RENDER_EFFECT_FUSCIA:
                glColor4x(alpha, 0, alpha*0.5, alpha);
                break;
            case RENDER_EFFECT_N1_CALIBRATED_N:
                glColor4x(alpha*renderColorR/1000, alpha*renderColorG/1000, alpha*renderColorB/1000, alpha);
                break;
            case RENDER_EFFECT_N1_CALIBRATED_R:
                glColor4x(alpha*(renderColorR-50)/1000, alpha*renderColorG/1000, alpha*(renderColorB-30)/1000, alpha);
                break;
            case RENDER_EFFECT_N1_CALIBRATED_C:
                glColor4x(alpha*renderColorR/1000, alpha*renderColorG/1000, alpha*(renderColorB+30)/1000, alpha);
                break;
            case RENDER_EFFECT_RED:
                glColor4x(alpha, 0, 0, alpha);
                break;
        }
        glEnable(GL_BLEND);
        glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env);
    }

    /*
     *  compute texture coordinates
     *  here, we handle NPOT, cropping and buffer transformations
     */

    GLfloat cl, ct, cr, cb;
    if (!mBufferCrop.isEmpty()) {
        // source is cropped
        const GLfloat us = (texture.NPOTAdjust ? texture.wScale : 1.0f) / width;
        const GLfloat vs = (texture.NPOTAdjust ? texture.hScale : 1.0f) / height;
        cl = mBufferCrop.left   * us;
        ct = mBufferCrop.top    * vs;
        cr = mBufferCrop.right  * us;
        cb = mBufferCrop.bottom * vs;
    } else {
        cl = 0;
        ct = 0;
        cr = (texture.NPOTAdjust ? texture.wScale : 1.0f);
        cb = (texture.NPOTAdjust ? texture.hScale : 1.0f);
    }

    /*
     * For the buffer transformation, we apply the rotation last.
     * Since we're transforming the texture-coordinates, we need
     * to apply the inverse of the buffer transformation:
     *   inverse( FLIP_V -> FLIP_H -> ROT_90 )
     *   <=> inverse( ROT_90 * FLIP_H * FLIP_V )
     *    =  inverse(FLIP_V) * inverse(FLIP_H) * inverse(ROT_90)
     *    =  FLIP_V * FLIP_H * ROT_270
     *   <=> ROT_270 -> FLIP_H -> FLIP_V
     *
     * The rotation is performed first, in the texture coordinate space.
     *
     */

    struct TexCoords {
        GLfloat u;
        GLfloat v;
    };

    enum {
        // name of the corners in the texture map
        LB = 0, // left-bottom
        LT = 1, // left-top
        RT = 2, // right-top
        RB = 3  // right-bottom
    };

    // vertices in screen space
    int vLT = LB;
    int vLB = LT;
    int vRB = RT;
    int vRT = RB;

    // the texture's source is rotated
    uint32_t transform = mBufferTransform;
    if (transform & HAL_TRANSFORM_ROT_90) {
        vLT = RB;
        vLB = LB;
        vRB = LT;
        vRT = RT;
    }
    if (transform & HAL_TRANSFORM_FLIP_V) {
        swap(vLT, vLB);
        swap(vRT, vRB);
    }
    if (transform & HAL_TRANSFORM_FLIP_H) {
        swap(vLT, vRT);
        swap(vLB, vRB);
    }

    TexCoords texCoords[4];
    texCoords[vLT].u = cl;
    texCoords[vLT].v = ct;
    texCoords[vLB].u = cl;
    texCoords[vLB].v = cb;
    texCoords[vRB].u = cr;
    texCoords[vRB].v = cb;
    texCoords[vRT].u = cr;
    texCoords[vRT].v = ct;

    if (needsDithering()) {
        glEnable(GL_DITHER);
    } else {
        glDisable(GL_DITHER);
    }

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, mVertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    Region::const_iterator it = clip.begin();
    Region::const_iterator const end = clip.end();
    while (it != end) {
        const Rect& r = *it++;
        const GLint sy = fbHeight - (r.top + r.height());
        glScissor(r.left, sy, r.width(), r.height());
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    }
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Ejemplo n.º 29
0
void MDTexture::render_billboards3(MDOpenGL &opengl, vector<int> &visible_atom_indices, vector<int> &atom_types, vector<vector<float> > &positions, bool draw_water, double color_cutoff, double dr2_max, vector<float> system_size, bool periodic_boundary_conditions) {
    Camera *camera = opengl.camera;
    CVector left, up, right, direction, v0, v1, v2, v3;
    int S = 1.0;
    double cam_x = camera->position.x; double cam_y = camera->position.y; double cam_z = camera->position.z;
    double one_over_color_cutoff = 1.0/color_cutoff;
    CVector up_on_screen = opengl.coord_to_ray(0,opengl.window_height/2.0);
    double dx = camera->target.x - cam_x;
    double dy = camera->target.y - cam_y;
    double dz = camera->target.z - cam_z;
    direction = camera->target;

    left = direction.Cross(up_on_screen);
    up = (direction.Cross(left)).Normalize();
    right = (direction.Cross(up)).Normalize();

    v0 = (right + up);
    v1 = (right*-1 + up);
    v2 = (right*-1 + up*-1);
    v3 = (right + up*-1);
    
    glNormal3f(direction.x, direction.y, direction.z);
    int num_vertices = 0;
    int num_atoms = 0;

    for(int n=0; n<positions.size(); n++) {
        int atom_type = atom_types[n];
        if( (atom_type == H_TYPE || atom_type == O_TYPE) && !draw_water) continue;
        double scale = visual_atom_radii[atom_type];

        double real_x = positions[n][0];
        double real_y = positions[n][1];
        double real_z = positions[n][2];

        for(int dx = -1; dx <= 1; dx++) {
            for(int dy = -1; dy <= 1; dy++) {
                for(int dz = -1; dz <= 1; dz++) {
                    if(!periodic_boundary_conditions && (dx != 0 || dy != 0 || dz != 0)) continue;

                    double x = real_x + system_size[0]*dx;
                    double y = real_y + system_size[1]*dy;
                    double z = real_z + system_size[2]*dz;

                    double delta_x = x - cam_x;
                    double delta_y = y - cam_y;
                    double delta_z = z - cam_z;

                    double dr2 = delta_x*delta_x + delta_y*delta_y + delta_z*delta_z;
                    if(dr2 < 50) continue;
                    if(dr2 > dr2_max) continue;
                    
                    double cam_target_times_dr = delta_x*direction.x + delta_y*direction.y + delta_z*direction.z;
                    if(cam_target_times_dr < 0) continue;

                    vertices[3*num_vertices + 0] = v0.x*scale + x;
                    vertices[3*num_vertices + 1] = v0.y*scale + y;
                    vertices[3*num_vertices + 2] = v0.z*scale + z;
                    indices[num_vertices] = num_vertices;
                    num_vertices++;

                    vertices[3*num_vertices + 0] = v1.x*scale + x;
                    vertices[3*num_vertices + 1] = v1.y*scale + y;
                    vertices[3*num_vertices + 2] = v1.z*scale + z;
                    indices[num_vertices] = num_vertices;
                    num_vertices++;

                    vertices[3*num_vertices + 0] = v2.x*scale + x;
                    vertices[3*num_vertices + 1] = v2.y*scale + y;
                    vertices[3*num_vertices + 2] = v2.z*scale + z;
                    indices[num_vertices] = num_vertices;
                    num_vertices++;

                    vertices[3*num_vertices + 0] = v3.x*scale + x;
                    vertices[3*num_vertices + 1] = v3.y*scale + y;
                    vertices[3*num_vertices + 2] = v3.z*scale + z;
                    indices[num_vertices] = num_vertices;
                    num_vertices++;

                    colors[4*num_atoms + 0] = color_list[atom_type][0];
                    colors[4*num_atoms + 1] = color_list[atom_type][1];
                    colors[4*num_atoms + 2] = color_list[atom_type][2];
                    colors[4*num_atoms + 3] = 1.0;
                    
                    num_atoms++;
                }
            }
        }
    }
    glNormal3f(direction.x, direction.y, direction.z);
    // glNormalPointer(GL_FLOAT, 6*sizeof(GLfloat), (float*)(3*sizeof(GLfloat)));

    glBindBuffer(GL_ARRAY_BUFFER, vertices_id);
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*3*num_vertices, NULL, GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat)*3*num_vertices, vertices);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_id);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*num_vertices, NULL, GL_STATIC_DRAW);
    glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(GLuint)*num_vertices, indices);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), NULL);
    glColorPointer (4, GL_FLOAT, 4, NULL);
    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_id);
    glBindBuffer(GL_ARRAY_BUFFER, vertices_id);
    glDrawElements(GL_QUADS, num_vertices, GL_UNSIGNED_INT, 0);

    glDisableClientState(GL_VERTEX_ARRAY);
}
Ejemplo n.º 30
0
void GLMeshBuffer::draw()
{
	if(m_effectType == setCustom && m_uShaderEffectProgram != INVALID_GLBUFFER)
		glUseProgram(m_uShaderEffectProgram);

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	if(m_bWireFrame)
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	else
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	//Color
	if(m_isValidColor)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vboColor);
		glColorPointer(m_stepColor, GL_FLOAT, 0, 0);
		glEnableClientState(GL_COLOR_ARRAY);
	}

	//TexCoord
	if(m_isValidTexCoord)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vboTexCoord);
		glTexCoordPointer(m_stepTexCoord, GL_FLOAT, 0, 0);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	}

	//Normal
	if(m_isValidNormal)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vboNormal);
		glNormalPointer(GL_FLOAT, 0, 0);
		glEnableClientState(GL_NORMAL_ARRAY);
	}

	//Vertex
	if(m_isValidVertex)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vboVertex);
		glVertexPointer(m_stepVertex, GL_FLOAT, 0, 0);
		glEnableClientState(GL_VERTEX_ARRAY);
	}


	//Draw Faces
	if(m_isValidIndex)
	{
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_iboFaces);
		glEnableClientState(GL_ELEMENT_ARRAY_BUFFER);
		glDrawElements(m_faceMode, (GLsizei)m_ctFaceElements, GL_UNSIGNED_INT, (GLvoid*)0);

		glDisableClientState(GL_ELEMENT_ARRAY_BUFFER);
	}
	else
		glDrawArrays(m_faceMode, 0, m_ctFaceElements);

	if(m_isValidColor)
		glDisableClientState(GL_COLOR_ARRAY);
	if(m_isValidTexCoord)
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	if(m_isValidNormal)
		glDisableClientState(GL_NORMAL_ARRAY);
	if(m_isValidVertex)
		glDisableClientState(GL_VERTEX_ARRAY);

	glPopAttrib();

	if(m_effectType == setCustom && m_uShaderEffectProgram != INVALID_GLBUFFER)
		glUseProgram(0);
}