Example #1
0
void tveVertexArray::render(float y, int dir)
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    //first pass
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glTexCoordPointer(2, GL_FLOAT, 0, tex_coord[0]);
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, height_map->tex[SHADOW]);

    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glTexCoordPointer(2, GL_FLOAT, 0, tex_coord[1]);
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, height_map->tex[GRASS]);

    glVertexPointer(3, GL_FLOAT, 0, vertices);
    //TODO
    if (top->lock) glLockArraysEXT(0, (LEAF_GRANULARITY+1)*(LEAF_GRANULARITY+1));
    drawArray(dir);

    // prepare second and third pass
    glEnableClientState(GL_COLOR_ARRAY);
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glTexCoordPointer(2, GL_FLOAT, 0, tex_coord[1]);
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_2D);
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glDepthMask(0);

    //second pass
    //TODO
    if (y > 128.0f)
    {
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, color[0]);
        glBindTexture(GL_TEXTURE_2D, height_map->tex[SNOW]);
        drawArray(dir);
    }
    //third pass
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, color[1]);
    glBindTexture(GL_TEXTURE_2D, height_map->tex[ROCK]);
    drawArray(dir);

    glDisableClientState(GL_COLOR_ARRAY);
    //fourth pass
    if (tveVoyager::cv_posy->value.floating < tveVoyager::cv_water->value.floating)
    {
        glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
        glBindTexture(GL_TEXTURE_2D, top->cur_water_tex);
        drawArray(dir);
    }

    glDepthMask(1);
    //FIXME: I don't know why I need to put that line before disabling TEXTURE_COORD in
    //       order to run perfectly on GeForce 2 Ultra under Linux with driver 0.9.767
    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    if (top->lock) glUnlockArraysEXT();
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}
Example #2
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
        glutInitWindowSize(480, 272);
	glutCreateWindow( __FILE__ );

#if !SYS
	glutJoystickFunc(joystick, 0);
#else
	glutPassiveMotionFunc(motion);
#endif

	glutKeyboardFunc(keydown);
	glutKeyboardUpFunc(keyup);
	glutSpecialFunc(special_down);
	glutSpecialUpFunc(special_up);
	glutReshapeFunc(reshape);
	glutDisplayFunc(display);

	GLCHK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE));

	GLCHK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, 
			   GL_RGBA, GL_UNSIGNED_BYTE, firefox_start));
	GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
	GLCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));

	genmesh();

	GLCHK(glEnableClientState(GL_VERTEX_ARRAY));
	GLCHK(glVertexPointer(3, GL_FLOAT, sizeof(struct vertex), &mesh[0].x));

	GLCHK(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
	GLCHK(glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), &mesh[0].s));

	GLCHK(glEnableClientState(GL_NORMAL_ARRAY));
	GLCHK(glNormalPointer(GL_FLOAT, sizeof(struct vertex), &mesh[0].nx));

	{
		GLfloat ambient[] = { .3,.3,.3,1 };
		GLCHK(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient));
		
		GLCHK(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
	}

	{
		GLfloat diff[] = { 1,1,1,1 };
		GLfloat spec[] = { 1,1,1,1 };
		GLfloat ambient[] = { .4,.4,.4,1 };

		GLCHK(glMaterialfv(GL_FRONT, GL_DIFFUSE, diff));
		GLCHK(glMaterialfv(GL_FRONT, GL_AMBIENT, ambient));
		GLCHK(glMaterialfv(GL_FRONT, GL_SPECULAR, spec));
		GLCHK(glMateriali(GL_FRONT, GL_SHININESS, 40));
	}

	GLCHK(glLockArraysEXT(0, MESHX*MESHY));

	GLCHK(glEnable(GL_DEPTH_TEST));
	GLCHK(glClearColor(0,0,.5,1));

	GLCHK(glEnable(GL_NORMALIZE));

#if GL_PSP_bezier_patch
	GLCHK(glPatchSubdivisionPSP(8,8));
	//GLCHK(glPatchSubdivisionPSP(16,16));
	//GLCHK(glPatchSubdivisionPSP(64,64));
#endif

//	GLCHK(glPolygonOffset(1,0));
//	GLCHK(glEnable(GL_POLYGON_OFFSET_FILL));

	glutMainLoop();

	return 0;
}
Example #3
0
static void ModeMenu(int m)
{
   m &= allowed;

   if (!m) return;

   if (m==QUIT)
      exit(0);

   if (m==GLINFO) {
      printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_EXTENSIONS: %s\n", (char *) glGetString(GL_EXTENSIONS));
      printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
      return;
   }

   if (CHANGED(state, m, FILTER_MASK)) {
      UPDATE(state, m, FILTER_MASK);
      if (m & LINEAR_FILTER) {
	 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      } else {
	 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      }
   }

   if (CHANGED(state, m, LIGHT_MASK)) {
      UPDATE(state, m, LIGHT_MASK);
      if (m & LIT) {
	 glEnable(GL_LIGHTING);
	 glDisable(GL_TEXTURE_GEN_S);
	 glDisable(GL_TEXTURE_GEN_T);
	 glDisable(GL_TEXTURE_2D);
      }
      else if (m & UNLIT) {
	 glDisable(GL_LIGHTING);
	 glDisable(GL_TEXTURE_GEN_S);
	 glDisable(GL_TEXTURE_GEN_T);
	 glDisable(GL_TEXTURE_2D);
      }
      else if (m & REFLECT) {
	 glDisable(GL_LIGHTING);
	 glEnable(GL_TEXTURE_GEN_S);
	 glEnable(GL_TEXTURE_GEN_T);
	 glEnable(GL_TEXTURE_2D);
      }
   }

   if (CHANGED(state, m, SHADE_MASK)) {
      UPDATE(state, m, SHADE_MASK);
      if (m & SHADE_SMOOTH)
	 glShadeModel(GL_SMOOTH);
      else
	 glShadeModel(GL_FLAT);
   }


   if (CHANGED(state, m, CLIP_MASK)) {
      UPDATE(state, m, CLIP_MASK);
      if (m & USER_CLIP) {
	 glEnable(GL_CLIP_PLANE0);
      } else {
	 glDisable(GL_CLIP_PLANE0);
      }
   }

   if (CHANGED(state, m, FOG_MASK)) {
      UPDATE(state, m, FOG_MASK);
      if (m & FOG) {
	 glEnable(GL_FOG);
      }
      else {
	 glDisable(GL_FOG);
      }
   }

   if (CHANGED(state, m, STIPPLE_MASK)) {
      UPDATE(state, m, STIPPLE_MASK);
      if (m & STIPPLE) {
	 glEnable(GL_POLYGON_STIPPLE);
      }
      else {
	 glDisable(GL_POLYGON_STIPPLE);
      }
   }

   if (CHANGED(state, m, POLYGON_MASK)) {
      UPDATE(state, m, POLYGON_MASK);
      if (m & POLYGON_FILL) {
	 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      }
      else {
	 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      }
   }

#ifdef GL_EXT_vertex_array
   if (CHANGED(state, m, (LOCK_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)))
   {
      if (m & (PRIMITIVE_MASK)) {
	 UPDATE(state, m, (PRIMITIVE_MASK));
      }

      if (m & (RENDER_STYLE_MASK)) {
	 UPDATE(state, m, (RENDER_STYLE_MASK));
      }

      if (m & LOCK_MASK) {
	 UPDATE(state, m, (LOCK_MASK));
      }


      print_flags("primitive", state & PRIMITIVE_MASK);
      print_flags("render style", state & RENDER_STYLE_MASK);

      if ((state & PRIMITIVE_MASK) != STRIPS &&
	  ((state & RENDER_STYLE_MASK) == DRAW_ELTS ||
	   (state & RENDER_STYLE_MASK) == ARRAY_ELT || 
	   (state & PRIMITIVE_MASK) == POINTS))
      {
	 fprintf(stderr, "enabling small arrays\n");
	 /* Rendering any primitive with draw-element/array-element
	  *  --> Can't do strips here as ordering has been lost in
	  *  compaction process...
	  */
	 glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq,
			     compressed_data );
	 glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq,
			     &compressed_data[0][3]);
#ifdef GL_EXT_compiled_vertex_array
	 if (allowed & LOCKED) {
	    if (state & LOCKED) {
	       glLockArraysEXT( 0, numuniq );
	    } else {
	       glUnlockArraysEXT();
	    }
	 }
#endif
      }
      else if ((state & PRIMITIVE_MASK) == TRIANGLES &&
	       (state & RENDER_STYLE_MASK) == DRAW_ARRAYS) {
	 fprintf(stderr, "enabling big arrays\n");
	 /* Only get here for TRIANGLES and drawarrays
	  */
	 glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), (numverts-2) * 3,
			     expanded_data );
	 glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), (numverts-2) * 3,
			     &expanded_data[0][3]);

#ifdef GL_EXT_compiled_vertex_array
	 if (allowed & LOCKED) {
	    if (state & LOCKED) {
	       glLockArraysEXT( 0, (numverts-2)*3 );
	    } else {
	       glUnlockArraysEXT();
	    }
	 }
#endif
      }
      else {
	 fprintf(stderr, "enabling normal arrays\n");
	 glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numverts, data );
	 glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numverts, &data[0][3]);
#ifdef GL_EXT_compiled_vertex_array
	 if (allowed & LOCKED) {
	    if (state & LOCKED) {
	       glLockArraysEXT( 0, numverts );
	    } else {
	       glUnlockArraysEXT();
	    }
	 }
#endif
      }

   }
#endif


   if (m & DLIST_MASK) {
      UPDATE(state, m, DLIST_MASK);
   }

   if (m & MATERIAL_MASK) {
      UPDATE(state, m, MATERIAL_MASK);
   }

   print_flags("new flags", state);

   glutPostRedisplay();
}
Example #4
0
void wxGL_PMFCanvas::draw_omnipoints(){
	static geo_sphere sphere(3);

	if(omni.flags & OMNIPOINT_DONT_DRAW)
		return;

	glEnable(GL_BLEND);
	
	glBlendFunc(GL_ONE,GL_ONE);
	glDisable(GL_CULL_FACE);

	GLfloat  ambientLight[4]={0.25f,0.25f,0.25f,1.0f};
	glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);

	glDepthMask(GL_FALSE);

	unsigned int i;
	unsigned int j;

	if (GLEE_ARB_vertex_buffer_object)
	{
		glBindBuffer(GL_ARRAY_BUFFER, omni_point_buffer.buffer);
		glLockArraysEXT( 0, omni_point_buffer.n_verts);
		ERROR_CHECK;
		glEnableClientState(GL_NORMAL_ARRAY);
		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3,GL_FLOAT, omni_point_buffer.vertex_size, (void*)NULL);
		glNormalPointer(GL_FLOAT, omni_point_buffer.vertex_size, (void*)((vector3d*)NULL + 1));
	}

	for(i = 0; i<omni.point.size(); i++){
		for(j = 0; j<omni.point[i].size(); j++){
			color col = omni.unselected;
			if(i == (unsigned)omni_selected_list){
				col = omni.selected_list;
				if(j == (unsigned)omni_selected_item)
					col = omni.selected_item;
			}

			//invalid radius so it's ok if we set it to anyhting
			//and the rest of the code assumes a sane rad
			
			if(!(omni.flags & OMNIPOINT_RAD))
				omni.point[i][j].rad = model.get_avg_dimintion()/61.80f;

			if (GLEE_ARB_vertex_buffer_object)
			{
				glPushMatrix();

				vector3d pnt = omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model);
				glTranslatef(pnt.x, pnt.y, pnt.z);

				if(omni.flags & OMNIPOINT_ANY_PATH){
					//sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), model.get_avg_dimintion()/30.0f, 2, col*10);
					float r = model.get_avg_dimintion()/30.0f;
					glScalef(r,r,r);
					color col2 = col*10;
					glColor4ubv( (GLubyte*)col2.col);
					glDrawArrays(GL_TRIANGLES, 0, omni_point_buffer.n_verts);
					glScalef(1.0f/r,1.0f/r,1.0f/r);
				}

				glColor4ubv( (GLubyte*)col.col);

				glScalef(omni.point[i][j].rad, omni.point[i][j].rad, omni.point[i][j].rad);
				//sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), omni.point[i][j].rad, 2, col);
				glDrawArrays(GL_TRIANGLES, 0, omni_point_buffer.n_verts);

				glPopMatrix();
			}
			else
			{
				sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), omni.point[i][j].rad, 2, col);
				if(omni.flags & OMNIPOINT_ANY_PATH) 	                      
					sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), model.get_avg_dimintion()/30.0f, 2, col*10);
	 		}



		}
	}

	if (GLEE_ARB_vertex_buffer_object)
	{
		glColor4ubv( (GLubyte*)color(255,255,255,255).col);


		glUnlockArraysEXT();
		glBindBuffer(GL_ARRAY_BUFFER, 0);

		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_NORMAL_ARRAY);
		ERROR_CHECK;
	}
	
	GLfloat  AmbientLight[4]={1.0f,1.0f,1.0f,1.0f};
	glLightfv(GL_LIGHT0,GL_AMBIENT,AmbientLight);

	glLineWidth(2.5f);


	if(omni.flags & OMNIPOINT_ANY_PATH)
	for(i = 0; i<omni.point.size(); i++){
		glBegin(GL_LINE_STRIP);
		for(j = 0; j<omni.point[i].size(); j++){
			color col = omni.unselected;
			if(i == (unsigned)omni_selected_list){
				col = omni.selected_item;
			}
			col = col * 4.0f;
			glColor4ubv( (GLubyte*)col.col);
			vector3d v(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model));
			glVertex3fv((GLfloat *)&(v));
		}
		if (omni.flags & OMNIPOINT_CLOSED_PATH) {
			color col = omni.unselected;
			if(i == (unsigned)omni_selected_list){
				col = omni.selected_item;
			}
			col = col * 4.0f;
			glColor4ubv( (GLubyte*)col.col);
			vector3d v(omni.point[i][0].pos+model.get_model_offset(omni.point[i][0].model));
			glVertex3fv((GLfloat *)&(v));
		}
		glEnd();
	}

	glDisable(GL_BLEND);
	glBegin(GL_LINES);

	if(omni.flags & OMNIPOINT_NORM)
	for(i = 0; i<omni.point.size(); i++){
		for(j = 0; j<omni.point[i].size(); j++){
			color col = omni.unselected;
			if(i == (unsigned)omni_selected_list){
				col = omni.selected_list;
				if(j == (unsigned)omni_selected_item)
					col = omni.selected_item;
			}
			glColor4ubv( (GLubyte*)col.col);

			vector3d v(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model));
			glVertex3fv((GLfloat *)&(v));
			if(omni.flags & OMNIPOINT_COMMON_NORMAL) {
				vector3d vec(omni.point[i][0].norm * omni.point[i][0].rad);
				vec = omni.point[i][j].pos + model.get_model_offset(omni.point[i][j].model) + vec * 2.5f;
				glVertex3fv((GLfloat *)&(vec));
			} else {
				vector3d vec(omni.point[i][j].norm * omni.point[i][0].rad);
				vec = omni.point[i][j].pos + model.get_model_offset(omni.point[i][j].model) + vec * 2.5f;
				glVertex3fv((GLfloat *)&(vec));
			}
		}
	}

	glEnd();

	glColor4ubv( (GLubyte*)color(255,255,255,255).col);

	glDepthMask(GL_TRUE);

	glLineWidth(1.05f);

}
Example #5
0
// Finally, the actual calls to do something with all this data.  You can either choose to render
// it given the configuration, or generate a display list of rendering it with the given
// configuration (uses GL_COMPILE mode to build the list).  Fails if insufficient data has
// been given (i.e. if you don't give it an array for an enabled parameter, if you don't
// give it an array of indices when it needs them).
// Note that rendering with GLVERTEX_MODE currently involves a lot of CPU overhead to
// unpack the data and pass it to the GL; while the results will be correct, it would be
// unwise to use this method for rendering that is to be benchmarked, because it will
// underestimate performance significantly on some machines.
bool GeomRenderer::renderPrimitives(GLenum mode)
{
    if (!isReadyToRender())
    {
        return false;
    }

    // Okay, different sections here depending on what we're doing.
    if (drawMethod == GLVERTEX_MODE)
    {
        glBegin(mode);
        for (unsigned int x=0; x<indicesCount; x++)
        {
            int directIndex = getIndex(x);
            if (parameterBits & COLOR_BIT) sendColor(directIndex);
            if (parameterBits & TEXTURE_COORD_BIT) sendTexCoord(directIndex);
            if (parameterBits & NORMAL_BIT) sendNormal(directIndex);
            sendVertex(directIndex);
        }
        glEnd();
    }
    // Otherwise it has something to do with arrays; set up the arrays.
    else
    {
        if (parameterBits & COLOR_BIT)
        { 
            glEnableClientState(GL_COLOR_ARRAY);
            glColorPointer(colorData.size, colorData.type, colorData.stride, colorData.pointer);
//            std::cout << "Enabled color arrays, size [" << colorData.size << "], type [" << colorData.type 
//                      << "], stride [" << colorData.stride << "], pointer [" << colorData.pointer << "]" << std::endl;
        }
        if (parameterBits & TEXTURE_COORD_BIT)
        { 
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(texCoordData.size, texCoordData.type, texCoordData.stride, texCoordData.pointer);
//            std::cout << "Enabled texCoord arrays, size [" << texCoordData.size << "], type [" << texCoordData.type 
//                      << "], stride [" << texCoordData.stride << "], pointer [" << texCoordData.pointer << "]" << std::endl;
        }
        if (parameterBits & NORMAL_BIT)
        { 
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(normalData.type, normalData.stride, normalData.pointer);
//            std::cout << "Enabled normal arrays, size [" << normalData.size << "], type [" << normalData.type 
//                      << "], stride [" << normalData.stride << "], pointer [" << normalData.pointer << "]" << std::endl;
        }
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(vertexData.size, vertexData.type, vertexData.stride, vertexData.pointer);
//        std::cout << "Enabled vertex arrays, size [" << vertexData.size << "], type [" << vertexData.type 
//                  << "], stride [" << vertexData.stride << "], pointer [" << vertexData.pointer << "]" << std::endl;

        // Should we lock?
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glLockArraysEXT(0, arrayLength);
        }

        // Okay, arrays configured; what exactly are we doing?
        if (drawMethod == GLARRAYELEMENT_MODE)
        {
            glBegin(mode);
            for (unsigned int x=0; x<indicesCount; x++)
            {
                glArrayElement(getIndex(x));
            }
            glEnd();
        }
        else if (drawMethod == GLDRAWARRAYS_MODE)
        {
            glDrawArrays(mode, 0, arrayLength);
            std::cout << "Called glDrawArrays, mode [" << mode << "], from 0 to " << arrayLength << std::endl;
        }
        else if (drawMethod == GLDRAWELEMENTS_MODE)
        {
            glDrawElements(mode, indicesCount, indicesType, indices);
        }

        // Done.  If we locked, unlock.
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glUnlockArraysEXT();
        }
    }

    return true;
}
Example #6
0
//===========================================================================
// DG_Arrays
//  Enable, set and optionally lock all enabled arrays.
//===========================================================================
void DG_Arrays(void *vertices, void *colors, int numCoords, void **coords,
			   int lock)
{
	int     i;

	if(vertices)
	{
		if(noArrays)
		{
			arrays[AR_VERTEX].enabled = true;
			arrays[AR_VERTEX].data = vertices;
		}
		else
		{
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(3, GL_FLOAT, 16, vertices);
		}
	}

	if(colors)
	{
		if(noArrays)
		{
			arrays[AR_COLOR].enabled = true;
			arrays[AR_COLOR].data = colors;
		}
		else
		{
			glEnableClientState(GL_COLOR_ARRAY);
			glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
		}
	}

	for(i = 0; i < numCoords && i < MAX_TEX_UNITS; i++)
	{
		if(coords[i])
		{
			if(noArrays)
			{
				arrays[AR_TEXCOORD0 + i].enabled = true;
				arrays[AR_TEXCOORD0 + i].data = coords[i];
			}
			else
			{
				if(glClientActiveTextureARB)
					glClientActiveTextureARB(GL_TEXTURE0 + i);

				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
				glTexCoordPointer(2, GL_FLOAT, 0, coords[i]);
			}
		}
	}

	if(!noArrays && lock > 0 && glLockArraysEXT)
	{
		// 'lock' is the number of vertices to lock.
		glLockArraysEXT(0, lock);
	}

#ifdef _DEBUG
	CheckError();
#endif
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTCompiledVertexArray_nglLockArraysEXT(JNIEnv *env, jclass clazz, jint first, jint count, jlong function_pointer) {
	glLockArraysEXTPROC glLockArraysEXT = (glLockArraysEXTPROC)((intptr_t)function_pointer);
	glLockArraysEXT(first, count);
}
Example #8
0
/*
================
DrawTris

Draws triangle outlines for debugging
================
*/
static void DrawTris(shaderCommands_t * input)
{
	char           *s = r_trisColor->string;
	vec4_t          trisColor = { 1, 1, 1, 1 };
	unsigned int    stateBits = 0;

	GL_Bind(tr.whiteImage);

	if(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))
	{
		s += 2;
		if(Q_IsHexColorString(s))
		{
			trisColor[0] = ((float)(gethex(*(s)) * 16 + gethex(*(s + 1)))) / 255.00;
			trisColor[1] = ((float)(gethex(*(s + 2)) * 16 + gethex(*(s + 3)))) / 255.00;
			trisColor[2] = ((float)(gethex(*(s + 4)) * 16 + gethex(*(s + 5)))) / 255.00;

			if(Q_HexColorStringHasAlpha(s))
			{
				trisColor[3] = ((float)(gethex(*(s + 6)) * 16 + gethex(*(s + 7)))) / 255.00;
			}
		}
	}
	else
	{
		int             i;
		char           *token;

		for(i = 0; i < 4; i++)
		{
			token = COM_Parse(&s);
			if(token)
			{
				trisColor[i] = atof(token);
			}
			else
			{
				trisColor[i] = 1.f;
			}
		}

		if(!trisColor[3])
		{
			trisColor[3] = 1.f;
		}
	}

	if(trisColor[3] < 1.f)
	{
		stateBits |= (GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA);
	}

	glColor4fv(trisColor);

	// ydnar r_showtris 2
	if(r_showtris->integer == 2)
	{
		stateBits |= (GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE);
		GL_State(stateBits);
		glDepthRange(0, 0);
	}
#ifdef CELSHADING_HACK
	else if(r_showtris->integer == 3)
	{
		stateBits |= (GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE);
		GL_State(stateBits);
		glEnable(GL_POLYGON_OFFSET_LINE);
		glPolygonOffset(4.0, 0.5);
		glLineWidth(5.0);
	}
#endif
	else
	{
		stateBits |= (GLS_POLYMODE_LINE);
		GL_State(stateBits);
		glEnable(GL_POLYGON_OFFSET_LINE);
		glPolygonOffset(r_offsetFactor->value, r_offsetUnits->value);
	}

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glVertexPointer(3, GL_FLOAT, 16, input->xyz);	// padded for SIMD

	if(glLockArraysEXT)
	{
		glLockArraysEXT(0, input->numVertexes);
		GLimp_LogComment("glLockArraysEXT\n");
	}

	R_DrawElements(input->numIndexes, input->indexes);

	if (GLEW_EXT_compiled_vertex_array)
	{
		glUnlockArraysEXT();
		GLimp_LogComment("glUnlockArraysEXT\n");
	}
	glDepthRange(0, 1);
	glDisable(GL_POLYGON_OFFSET_LINE);
}
Example #9
0
void RB_StageIteratorLightmappedMultitexture(void)
{
	shaderCommands_t *input;

	input = &tess;

	//
	// log this call
	//
	if(r_logFile->integer)
	{
		// don't just call LogComment, or we will get
		// a call to va() every frame!
		GLimp_LogComment(va("--- RB_StageIteratorLightmappedMultitexture( %s ) ---\n", tess.shader->name));
	}

	// set GL fog
	SetIteratorFog();

	//
	// set face culling appropriately
	//
	GL_Cull(input->shader->cullType);

	//
	// set color, pointers, and lock
	//
	GL_State(GLS_DEFAULT);
	glVertexPointer(3, GL_FLOAT, 16, input->xyz);

#ifdef REPLACE_MODE
	glDisableClientState(GL_COLOR_ARRAY);
	glColor3f(1, 1, 1);
	glShadeModel(GL_FLAT);
#else
	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.constantColor255);
#endif

	//
	// select base stage
	//
	GL_SelectTexture(0);

	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	R_BindAnimatedImage(&tess.xstages[0]->bundle[0]);
	glTexCoordPointer(2, GL_FLOAT, 8, tess.texCoords0);

	//
	// configure second stage
	//
	GL_SelectTexture(1);
	glEnable(GL_TEXTURE_2D);
	if(r_lightmap->integer)
	{
		GL_TexEnv(GL_REPLACE);
	}
	else
	{
		GL_TexEnv(GL_MODULATE);
	}

//----(SA)  modified for snooper
	if(tess.xstages[0]->bundle[1].isLightmap && (backEnd.refdef.rdflags & RDF_SNOOPERVIEW))
	{
		GL_Bind(tr.whiteImage);
	}
	else
	{
		R_BindAnimatedImage(&tess.xstages[0]->bundle[1]);
	}

	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, 8, tess.texCoords1);

	//
	// lock arrays
	//
	if (GLEW_EXT_compiled_vertex_array)
	{
		glLockArraysEXT(0, input->numVertexes);
		GLimp_LogComment("glLockArraysEXT\n");
	}

	R_DrawElements(input->numIndexes, input->indexes);

	//
	// disable texturing on TEXTURE1, then select TEXTURE0
	//
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	GL_SelectTexture(0);
#ifdef REPLACE_MODE
	GL_TexEnv(GL_MODULATE);
	glShadeModel(GL_SMOOTH);
#endif

	//
	// now do any dynamic lighting needed
	//
	//% if ( tess.dlightBits && tess.shader->sort <= SS_OPAQUE )
	if(tess.dlightBits && tess.shader->fogPass && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY)))
	{
		if(r_dynamiclight->integer == 2)
		{
			DynamicLightPass();
		}
		else
		{
			DynamicLightSinglePass();
		}
	}

	//
	// now do fog
	//
	if(tess.fogNum && tess.shader->fogPass)
	{
		RB_FogPass();
	}

	//
	// unlock arrays
	//
	if (GLEW_EXT_compiled_vertex_array)
	{
		glUnlockArraysEXT();
		GLimp_LogComment("glUnlockArraysEXT\n");
	}
}
Example #10
0
/*
** RB_StageIteratorVertexLitTexture
*/
void RB_StageIteratorVertexLitTexture(void)
{
	shaderCommands_t *input;
	shader_t       *shader;

	input = &tess;

	shader = input->shader;

	//
	// compute colors
	//
	RB_CalcDiffuseColor((unsigned char *)tess.svars.colors);

	//
	// log this call
	//
	if(r_logFile->integer)
	{
		// don't just call LogComment, or we will get
		// a call to va() every frame!
		GLimp_LogComment(va("--- RB_StageIteratorVertexLitTexturedUnfogged( %s ) ---\n", tess.shader->name));
	}


	// set GL fog
	SetIteratorFog();

	//
	// set face culling appropriately
	//
	GL_Cull(input->shader->cullType);

	//
	// set arrays and lock
	//
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.svars.colors);
	glTexCoordPointer(2, GL_FLOAT, 8, tess.texCoords0);
	glVertexPointer(3, GL_FLOAT, 16, input->xyz);

	if (GLEW_EXT_compiled_vertex_array)
	{
		glLockArraysEXT(0, input->numVertexes);
		GLimp_LogComment("glLockArraysEXT\n");
	}

	//
	// call special shade routine
	//
	R_BindAnimatedImage(&tess.xstages[0]->bundle[0]);
	GL_State(tess.xstages[0]->stateBits);
	R_DrawElements(input->numIndexes, input->indexes);

	//
	// now do any dynamic lighting needed
	//
	//% if ( tess.dlightBits && tess.shader->sort <= SS_OPAQUE )
	if(tess.dlightBits && tess.shader->fogPass && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY)))
	{
		if(r_dynamiclight->integer == 2)
		{
			DynamicLightPass();
		}
		else
		{
			DynamicLightSinglePass();
		}
	}


	//
	// now do fog
	//
	if(tess.fogNum && tess.shader->fogPass)
	{
		RB_FogPass();
	}

	//
	// unlock arrays
	//
	if (GLEW_EXT_compiled_vertex_array)
	{
		glUnlockArraysEXT();
		GLimp_LogComment("glUnlockArraysEXT\n");
	}
}
Example #11
0
/*
** RB_StageIteratorGeneric
*/
void RB_StageIteratorGeneric(void)
{
	shaderCommands_t *input;

	input = &tess;

	RB_DeformTessGeometry();

	//
	// log this call
	//
	if(r_logFile->integer)
	{
		// don't just call LogComment, or we will get
		// a call to va() every frame!
		GLimp_LogComment(va("--- RB_StageIteratorGeneric( %s ) ---\n", tess.shader->name));
	}

	// set GL fog
	SetIteratorFog();


	//
	// set face culling appropriately
	//
	GL_Cull(input->shader->cullType);

	// set polygon offset if necessary
	if(input->shader->polygonOffset)
	{
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(r_offsetFactor->value, r_offsetUnits->value);
	}

	//
	// if there is only a single pass then we can enable color
	// and texture arrays before we compile, otherwise we need
	// to avoid compiling those arrays since they will change
	// during multipass rendering
	//
	if(tess.numPasses > 1 || input->shader->multitextureEnv)
	{
		setArraysOnce = false;
		glDisableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}
	else
	{
		setArraysOnce = true;

		glEnableClientState(GL_COLOR_ARRAY);
		glColorPointer(4, GL_UNSIGNED_BYTE, 0, tess.svars.colors);

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT, 0, tess.svars.texcoords[0]);
	}

	//
	// lock XYZ
	//
	glVertexPointer(3, GL_FLOAT, 16, input->xyz);	// padded for SIMD
	if (GLEW_EXT_compiled_vertex_array)
	{
		glLockArraysEXT(0, input->numVertexes);
		GLimp_LogComment("glLockArraysEXT\n");
	}

	//
	// enable color and texcoord arrays after the lock if necessary
	//
	if(!setArraysOnce)
	{
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
	}

	//
	// call shader function
	//
	RB_IterateStagesGeneric(input);

	//
	// now do any dynamic lighting needed
	//
	//% tess.dlightBits = 255;  // HACK!
	//% if( tess.dlightBits && tess.shader->sort <= SS_OPAQUE &&
	if(tess.dlightBits && tess.shader->fogPass && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY)))
	{
		if(r_dynamiclight->integer == 2)
		{
			DynamicLightPass();
		}
		else
		{
			DynamicLightSinglePass();
		}
	}

	//
	// now do fog
	//
	if(tess.fogNum && tess.shader->fogPass)
	{
		RB_FogPass();
	}

	//
	// unlock arrays
	//
	if (GLEW_EXT_compiled_vertex_array)
	{
		glUnlockArraysEXT();
		GLimp_LogComment("glUnlockArraysEXT\n");
	}

	//
	// reset polygon offset
	//
	if(input->shader->polygonOffset)
	{
		glDisable(GL_POLYGON_OFFSET_FILL);
	}
}
Example #12
0
//Set up openGL
bool GLInit()
{
	//set viewport
	int height = 480;
	int width = 640;

	
	glViewport(0, 0, width, height);					//reset viewport

	//set up projection matrix
	glMatrixMode(GL_PROJECTION);							//select projection matrix
	glLoadIdentity();										//reset
	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f);
	
	//load identity modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//other states
	//shading
	glShadeModel(GL_SMOOTH);
	glClearColor(	backgroundColor.r,
					backgroundColor.g,
					backgroundColor.b,
					backgroundColor.a);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	//depth
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	//hints
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Set up vertex arrays for torus
	//Fixed 17th November 2002
	//Instead of passing tangents as texture coords 1 and 2, use aliased attributes 9 and 10.
	//This way, these texture coordinates will reach the vertex program on a geforce 2
	//which only has 2 texture units.
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].position);

	glEnableClientState(GL_NORMAL_ARRAY);
	glNormalPointer(GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].normal);

	//Pass texture coords to unit 0
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].s);

	//Pass tangent,binormal to attributes 9, 10
	glEnableClientState(GL_VERTEX_ATTRIB_ARRAY9_NV);
	glVertexAttribPointerNV(9, 3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].sTangent);
	
	glEnableClientState(GL_VERTEX_ATTRIB_ARRAY10_NV);
	glVertexAttribPointerNV(10, 3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].tTangent);
	
	//Use compiled vertex arrays
	glLockArraysEXT(0, torus.numVertices);


	//Load vertex programs
	glGenProgramsNV(1, &singlePassVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, singlePassVertexProgram);
	LoadNV_vertex_program("single pass vertex program.txt", singlePassVertexProgram);

	glGenProgramsNV(1, &diffuseDecalVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, diffuseDecalVertexProgram);
	LoadNV_vertex_program("diffuse decal vertex program.txt", diffuseDecalVertexProgram);

	glGenProgramsNV(1, &lookUpSpecularVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, lookUpSpecularVertexProgram);
	LoadNV_vertex_program("look up specular vertex program.txt", lookUpSpecularVertexProgram);

	glGenProgramsNV(1, &diffuseVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, diffuseVertexProgram);
	LoadNV_vertex_program("diffuse vertex program.txt", diffuseVertexProgram);
	
	glGenProgramsNV(1, &decalVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, decalVertexProgram);
	LoadNV_vertex_program("decal vertex program.txt", decalVertexProgram);

	glGenProgramsNV(1, &simpleSpecularVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, simpleSpecularVertexProgram);
	LoadNV_vertex_program("simple specular vertex program.txt", simpleSpecularVertexProgram);

	//Set Tracking Matrix
	//Modelview Projection in registers c[0]-c[3]
	glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);

	return true;
}