Exemple #1
0
/* Create a texture in OpenGL.  First an image is loaded 
   and stored in a raster buffer, then it's  */
static void Create_Texture(ModeInfo *mi, const char *filename)
{
  int height, width;
  GLubyte *image;
  int format;

  if ( !strncmp(filename, "BUILTIN", 7))
    image = Generate_Image(&width, &height, &format);
  else
    {
      XImage *ximage = xpm_file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi),
                                           MI_COLORMAP (mi), filename);
      image  = (GLubyte *) ximage->data;
      width  = ximage->width;
      height = ximage->height;
      format = GL_RGBA;
    }

  /* GL_MODULATE or GL_DECAL depending on what you want */
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  /* perhaps we can edge a bit more speed at the expense of quality */
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

  if (do_tex_qual) {
	/* with texture_quality, the min and mag filters look *much* nice but are *much* slower */
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  }
  else {
	/* default is to do it quick and dirty */
	/* if you have mipmaps turned on, but not texture quality, nothing will happen! */
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  }

  /* mipmaps make the image look much nicer */
  if (do_mipmap)
    {
      int status;
      clear_gl_error();
      status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, format,
                                 GL_UNSIGNED_BYTE, image);
      if (status)
        {
          const char *s = (char *) gluErrorString (status);
          fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n",
                   progname, width, height,
                   (s ? s : "(unknown)"));
          exit (1);
        }
      check_gl_error("mipmapping");
    }
  else
    {
      clear_gl_error();
      glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0,
                   format, GL_UNSIGNED_BYTE, image);
      check_gl_error("texture");
    }
}
Exemple #2
0
/*
 * Initialize the variables
 */
void init(void)
{
    GLfloat color[4] = { 0.75, 0.75, 0.75, 1.0 };
    glClearColor(0.75, 0.75, 0.75, 1.0);
    glEnable(GL_DEPTH_TEST);                            // Depth testing
    glEnable(GL_CULL_FACE);                             // One-sided faces

    glEnable(GL_FOG);                                   // Fog
    glFogi(GL_FOG_MODE, GL_EXP2);
    glHint(GL_FOG_HINT, GL_NICEST);
    glFogf(GL_FOG_DENSITY, 0.025f);
    glFogfv(GL_FOG_COLOR, color);

    // Enable texture & sphere mapping
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    // Enable lighting
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, LIGHT0_POSITION);
    glLightfv(GL_LIGHT0, GL_AMBIENT , LIGHT0_AMBIENT);
    glLightfv(GL_LIGHT0, GL_DIFFUSE , LIGHT0_DIFFUSE);
    glLightfv(GL_LIGHT0, GL_SPECULAR, LIGHT0_SPECULAR);
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, LIGHT1_POSITION);
    glLightfv(GL_LIGHT1, GL_AMBIENT , LIGHT1_AMBIENT);
    glLightfv(GL_LIGHT1, GL_DIFFUSE , LIGHT1_DIFFUSE);
    glLightfv(GL_LIGHT1, GL_SPECULAR, LIGHT1_SPECULAR);

    // Initialize texture
    if( LoadTextures() )
    {
        MessageBox(NULL, "An error occured when loading the textures.", "Initialization Error", MB_ICONERROR);
        exit(1);
    }

    // Load models
    camera_init();
    if(
        player_init() ||
        LoadModelA3D(OBJECT_LANDSCAPE, "../models/landscape.a3d") ||
        LoadModelA3D(OBJECT_JEEP     , "../models/jeep.a3d") ||
        LoadModelA3D(OBJECT_DOCK     , "../models/dock.a3d") ||
        LoadModelA3D(OBJECT_LANDING  , "../models/landing.a3d") ||
        LoadModelA3D(OBJECT_BARRACK  , "../models/barrack.a3d"))
    {
        MessageBox(NULL, "An error occured when loading the models.", "Initialization Error", MB_ICONERROR);
        exit(1);
    }

    // Initialize models (buildings)
    srand(GetTickCount());
    g_pModels[0].call_identifier = OBJECT_LANDING;
    g_pModels[0].position[0]     = -50;
    g_pModels[0].position[1]     = -50;
    g_pModels[0].rotation        = rand() % 360;
    g_pModels[1].call_identifier = OBJECT_DOCK;
    g_pModels[1].position[0]     = -20;
    g_pModels[1].position[1]     = -60;
    g_pModels[1].rotation        = rand() % 360;
    g_pModels[2].call_identifier = OBJECT_BARRACK;
    g_pModels[2].position[0]     = -35;
    g_pModels[2].position[1]     = -20;
    g_pModels[2].rotation        = rand() % 360;
    g_pModels[3].call_identifier = OBJECT_BARRACK;
    g_pModels[3].position[0]     = -15;
    g_pModels[3].position[1]     = -40;
    g_pModels[3].rotation        = rand() % 360;
    g_pModels[4].call_identifier = OBJECT_DOCK;
    g_pModels[4].position[0]     = -35;
    g_pModels[4].position[1]     = -60;
    g_pModels[4].rotation        = rand() % 360;
    g_pModelJeep.call_identifier = OBJECT_JEEP;
    g_pModelJeep.position[0]     = 20.0f;
    g_pModelJeep.position[1]     =  0;
    g_pModelJeep.rotation        =  0;

    // Hide mouse cursor
    ShowCursor(FALSE);
    SetCursorPos(g_iWindowCenterX, g_iWindowCenterY);

    // Store current time
    g_dLastTime = Wallclock();
}
Exemple #3
0
bool World::Initialize(unsigned int windowWidth, unsigned int windowHeight, String windowName, bool antiAliasing, bool fullScreen, bool resizable)
{
	if (_initialized)
	{
		return false;
	}
	
	_running = true;

	// Windows DLL locations
	#if defined(WIN32) && defined(ANGEL_RELEASE)
		String bitsPath = "bits";
		char currentDir[MAX_PATH];
		_getcwd(currentDir, MAX_PATH);
		String currDir(currentDir);

		StringList libs;
		#if !ANGEL_DISABLE_DEVIL
			libs.push_back("DevIL.dll");
			libs.push_back("ILU.dll");
			libs.push_back("ILUT.dll");
		#endif
		#if ANGEL_DISABLE_FMOD
			libs.push_back("OpenAL32.dll");
		#else
			libs.push_back("fmodex.dll");
		#endif

		for	(int i=0; i < libs.size(); i++)
		{
			String libstring = currDir + "\\" + bitsPath + "\\" + libs[i];
			HMODULE work = LoadLibrary(libstring.c_str());
			if (work == 0)
			{
				DWORD err = GetLastError();
				_com_error error(err);
				LPCSTR errorText = error.ErrorMessage();
				sysLog.Printf("ERROR: Couldn't load DLL (%s); %s", libs[i].c_str(), errorText);
			}
		}

		// does bits directory exist?
		DWORD dwAttrib = GetFileAttributes(bitsPath.c_str());
		if (dwAttrib != INVALID_FILE_ATTRIBUTES && dwAttrib & FILE_ATTRIBUTE_DIRECTORY)
		{
			_chdir(bitsPath.c_str());
		}
	#endif
	
	// General windowing initialization
	#if !ANGEL_MOBILE
		glfwInit();
	#endif
	
	#if defined(__APPLE__)
		// Set up paths correctly in the .app bundle
		#if !ANGEL_MOBILE
			CFBundleRef mainBundle = CFBundleGetMainBundle();
			CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
			char path[PATH_MAX];
			if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
			{
				sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!");
			}
			CFRelease(resourcesURL);
			chdir(path);
			chdir("..");
			#if defined(ANGEL_DEBUG)
				// set paths to the local resources rather than the copied ones
				String fileName = __FILE__;
				String dirPath = fileName.substr(0, fileName.size() - String("Angel/Infrastructure/World.cpp").size());
				CFURLRef exeURL = CFBundleCopyExecutableURL(mainBundle);
				char exePath[PATH_MAX];
				if (!CFURLGetFileSystemRepresentation(exeURL, TRUE, (UInt8 *)exePath, PATH_MAX))
				{
					sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!");
				}
				CFRelease(exeURL);
				chdir(dirPath.c_str());
				StringList pathElements = SplitString(exePath, "/");
				String exeName = pathElements[pathElements.size()-1];
				chdir(exeName.c_str());
			#endif
		#else
			CFBundleRef mainBundle = CFBundleGetMainBundle();
			CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
			char path[PATH_MAX];
			if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
			{
				std::cout << "Problem setting up working directory! Probably nothing will work!" << std::endl;
			}
			CFRelease(resourcesURL);
			chdir(path);
			chdir("Angel"); // the iPhone doesn't like having a "Resources" directory in the root of the .app bundle
		#endif
	#endif
	
	//Start scripting
	LuaScriptingModule::Prep();

	//Reset values based on preferences
	antiAliasing = thePrefs.OverrideInt("WindowSettings", "antiAliasing", antiAliasing) == 1;
	fullScreen = thePrefs.OverrideInt("WindowSettings", "fullScreen", fullScreen) == 1;
	resizable = thePrefs.OverrideInt("WindowSettings", "resizable", resizable) == 1;
	int windowHeightPref = thePrefs.OverrideInt("WindowSettings", "height", (int)windowHeight);
	int windowWidthPref = thePrefs.OverrideInt("WindowSettings", "width", (int)windowWidth);

	if (windowHeightPref < 0 || windowWidthPref < 0)
	{
		sysLog.Log("Negative value for window dimensions founded; using defaults.");
	}
	else
	{
		windowHeight = (unsigned int)windowHeightPref;
		windowWidth = (unsigned int)windowWidthPref;
	}

	windowName = thePrefs.OverrideString("WindowSettings", "name", windowName);
	
	//Windowing system setup
	#if !ANGEL_MOBILE
		if (antiAliasing)
		{
			glfwWindowHint(GLFW_SAMPLES, 4); //4x looks pretty good
			_antiAliased = true;
		}
		else
		{
			_antiAliased = false;
		}
		
		GLFWmonitor* openOn = NULL; // windowed
		if (fullScreen)
		{
			openOn = glfwGetPrimaryMonitor();
		}
		if (resizable)
		{
			glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
		}
		else
		{
			glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
		}
		
		_mainWindow = glfwCreateWindow(windowWidth, windowHeight, windowName.c_str(), openOn, NULL);
		glfwMakeContextCurrent(_mainWindow);
	
		int fbw, fbh;
		glfwGetFramebufferSize(_mainWindow, &fbw, &fbh);
		if ((unsigned int)fbw == (windowWidth * 2))
		{
			SetHighResolutionScreen(true);
		}
	
		#if defined(WIN32)
			glfwSwapInterval(0); // because double-buffering and Windows don't get along apparently
		#else
			glfwSwapInterval(1);
		#endif
		glfwSetWindowSizeCallback(_mainWindow, Camera::ResizeCallback);
		glfwSetKeyCallback(_mainWindow, keyboardInput);
		glfwSetCharCallback(_mainWindow, charInput);
		glfwSetCursorPosCallback(_mainWindow, MouseMotion);
		glfwSetMouseButtonCallback(_mainWindow, MouseButton);
		glfwSetScrollCallback(_mainWindow, MouseWheel);
		glfwSetWindowCloseCallback(_mainWindow, windowClosed);
		_prevTime = (float)glfwGetTime();
	
		Camera::ResizeCallback(_mainWindow, fbw, fbh);
	#else
		struct timeval tv;
		gettimeofday(&tv, NULL);
		_currTime = _startTime = tv.tv_sec + (double) tv.tv_usec / 1000000.0;
	#endif
	
	//OpenGL state setup
	#if !ANGEL_MOBILE
		glClearDepth(1.0f);
		glPolygonMode(GL_FRONT, GL_FILL);
	#else
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(1.0f, -1.0f);
	#endif
	glShadeModel(GL_FLAT);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
	glCullFace(GL_BACK);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearStencil(0);
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

	//Get textures going
	InitializeTextureLoading();
	
	//Subscribe to camera changes
	theSwitchboard.SubscribeTo(this, "CameraChange");
	
	//initialize singletons
	#if !ANGEL_MOBILE
		theInput;
		theControllerManager.Setup();
	#endif
	theSound;
	theSpatialGraph;

	#if !ANGEL_MOBILE
		RegisterConsole(new TestConsole());
	#else
		// register fonts, since we don't have the console doing it for us on the phone
		RegisterFont("Resources/Fonts/Inconsolata.otf", 24, "Console");
		RegisterFont("Resources/Fonts/Inconsolata.otf", 18, "ConsoleSmall");
	#endif
	
	LuaScriptingModule::Initialize();

	return _initialized = true;
}
bool PinnedUnPackBuffer::init(sv_handle * sv, sv_direct_handle * dh_in, sv_direct_handle * dh_out, int buffercount)
{
  float quad[] = { -1.0f, -1.0f, 0.0f,   0.0f, 0.0f,
                    1.0f, -1.0f, 0.0f,   1.0f, 0.0f,
                    1.0f,  1.0f, 0.0f,   1.0f, 1.0f,
                   -1.0f,  1.0f, 0.0f,   0.0f, 1.0f };

  float rquad[]= { -1.0f, -1.0f, 0.0f,   0.0f, 1.0f,
                    1.0f, -1.0f, 0.0f,   1.0f, 1.0f,
                    1.0f,  1.0f, 0.0f,   1.0f, 0.0f,
                   -1.0f,  1.0f, 0.0f,   0.0f, 0.0f };

  int res = SV_OK;

  if((buffercount > 2) || (buffercount < 1)) {
    return false;
  }

  glClearColor(0.3f, 0.3f, 0.3f, 1.0f);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);
  glShadeModel(GL_SMOOTH);
  glPolygonMode(GL_FRONT, GL_FILL);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);

  glGenBuffers(1, &mUIQuad);
  glBindBuffer(GL_ARRAY_BUFFER, mUIQuad);
  glBufferData(GL_ARRAY_BUFFER, 20 * sizeof(float), quad, GL_STATIC_DRAW);
  glBindBuffer(GL_ARRAY_BUFFER, 0);

  glGenBuffers(1, &mUIRQuad);
  glBindBuffer(GL_ARRAY_BUFFER, mUIRQuad);
  glBufferData(GL_ARRAY_BUFFER, 20 * sizeof(float), rquad, GL_STATIC_DRAW);
  glBindBuffer(GL_ARRAY_BUFFER, 0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glViewport(0, 0, mWidth, mHeight);
  glOrtho(-1.0f, 1.0f, 1.0f, -1.0f, 0, 128);
  
  glGenBuffers(buffercount, mTextureInput);
  glGenBuffers(buffercount, mTextureOutput);

  for(int i = 0; i < buffercount; i++) {
    res = sv_direct_bind_opengl(sv, dh_in, i, mTextureInput[i]);
    if(res != SV_OK) {
      return false;
    }

    res = sv_direct_bind_opengl(sv, dh_out, i, mTextureOutput[i]);
    if(res != SV_OK) {
      return false;
    }
  }

  // Generate a texture into which tha data from teh buffer is dpwnloaded
  glGenTextures(1, &mUITexture);
  glBindTexture(GL_TEXTURE_2D, mUITexture);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  glBindTexture(GL_TEXTURE_2D, 0);

  mRenderTarget = new RenderTarget;
  mRenderTarget->createBuffer(mWidth, mHeight, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);

  return true;
}
//*************************************************************************//
long Graphics::Initialize(HWND hWindow, unsigned long ulWidth, unsigned long ulHeight)
{
    //-----------------------------------------------------------------------//
    // Create a data member to hold the result of this method. In this method's
    // case it will hold any error codes. By default set to 1 to signal no error.
    long lResultCode = 1;
    //-----------------------------------------------------------------------//

    smhWindow = hWindow;

    static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
    {
        sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
        1,											// Version Number
        PFD_DRAW_TO_WINDOW |						// Format Must Support Window
        PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
        PFD_DOUBLEBUFFER,							// Must Support Double Buffering
        PFD_TYPE_RGBA,								// Request An RGBA Format
        32,										// Select Our Color Depth
        0, 0, 0, 0, 0, 0,							// Color Bits Ignored
        0,											// No Alpha Buffer
        0,											// Shift Bit Ignored
        0,											// No Accumulation Buffer
        0, 0, 0, 0,									// Accumulation Bits Ignored
        16,											// 16Bit Z-Buffer (Depth Buffer)
        0,											// No Stencil Buffer
        0,											// No Auxiliary Buffer
        PFD_MAIN_PLANE,								// Main Drawing Layer
        0,											// Reserved
        0, 0, 0										// Layer Masks Ignored
    };

    GLuint		PixelFormat;
    if(!(smhDeviceContext = GetDC(hWindow)))
    {
        lResultCode = -1;
        smhDeviceContext = NULL;
    }

    if(lResultCode > 0 && !(PixelFormat = ChoosePixelFormat(smhDeviceContext, &pfd)))	// Did Windows Find A Matching Pixel Format?
    {
        lResultCode = -1;
    }

    if(lResultCode > 0 && !SetPixelFormat(smhDeviceContext, PixelFormat, &pfd))		// Are We Able To Set The Pixel Format?
    {
        lResultCode = -1;
    }

    if(lResultCode > 0 && !(smhRenderingContext = wglCreateContext(smhDeviceContext)))				// Are We Able To Get A Rendering Context?
    {
        lResultCode = -1;
    }

    if(lResultCode > 0 && !wglMakeCurrent(smhDeviceContext, smhRenderingContext))					// Try To Activate The Rendering Context
    {
        lResultCode = -1;
    }

    if(lResultCode > 0)
    {
        // Check Required Extensions
        GLenum err = glewInit();
        if(err == GLEW_OK)
        {
            glewGetString(GLEW_VERSION);
            /// \TODO DO something with version.
            if(GLEW_ARB_vertex_buffer_object)
            {

                glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
                glClearDepth(1.0f);									// Depth Buffer Setup
                glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
                glEnable ( GL_LIGHTING ) ;
                float global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
                glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
                GLfloat specular[] = {1.0f, 1.0f, 1.0f , 1.0f};
                glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
                glShadeModel(GL_SMOOTH);

                glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
                glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
                glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
                glEnable(GL_TEXTURE_2D);
            }
            else
            {
                lResultCode = -1;
            }
        }
        else
        {
            glewGetErrorString(err);
            lResultCode = -1;
            /// \TODO do something with error.
        }
    }

    //-----------------------------------------------------------------------//
    // Return result/error code
    return lResultCode;
    //-----------------------------------------------------------------------//
} // End of long Graphics::Initialize(HWND hWindow)
Exemple #6
0
//Called for initiation
bool Init(void)
{
	//Check for necessary extensions
	if(!GLEE_ARB_depth_texture || !GLEE_ARB_shadow)
	{
		printf("I require ARB_depth_texture and ARB_shadow extensionsn\n");
		return false;
	}
	
	//Load identity modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//Shading states
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Depth states
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	glEnable(GL_CULL_FACE);

	//We use glScale when drawing the scene
	glEnable(GL_NORMALIZE);

	//Create the shadow map texture
	glGenTextures(1, &shadowMapTexture);
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0,
					GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	//Use the color as the ambient and diffuse material
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
	
	//White specular material color, shininess 16
	glMaterialfv(GL_FRONT, GL_SPECULAR, white);
	glMaterialf(GL_FRONT, GL_SHININESS, 16.0f);

	//Calculate & save matrices
	glPushMatrix();
	
	glLoadIdentity();
	gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraProjectionMatrix);
	
	glLoadIdentity();
	gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
				0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraViewMatrix);
	
	glLoadIdentity();
	gluPerspective(45.0f, 1.0f, 2.0f, 8.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightProjectionMatrix);
	
	glLoadIdentity();
	gluLookAt(	lightPosition.x, lightPosition.y, lightPosition.z,
				0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix);
	
	glPopMatrix();

	//Reset timer
	timer.Reset();

	return true;
}
void CLT3DEngine::SetRedererState()
	{
	// Reinitialize viewport and projection.
	glViewport(0, 0, iScreenWidth, iScreenHeight);

	// Recalculate the view frustrum
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	GLfloat aspectRatio = (GLfloat) (iScreenWidth) / (GLfloat) (iScreenHeight);
	glFrustumf(FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
			FRUSTUM_BOTTOM, FRUSTUM_TOP,
			FRUSTUM_NEAR, FRUSTUM_FAR );
	glMatrixMode(GL_MODELVIEW);

	// Set the screen background color.
	glClearColor(0.f, 0.f, 0.f, 1.f);

	// Enable back face culling.
	glEnable(GL_CULL_FACE);
	glEnable(GL_TEXTURE_2D);

	// Enable vertex arrays.
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glScalef(1.0f / 255.0f, 1.0f / 255.0f, 1.0f);
	glTranslatef(128.0f, 128.0f, 0.0f);

	glMatrixMode(GL_MODELVIEW);

	// Set array pointers.
	glVertexPointer(3, GL_BYTE, 0, vertices);
	glTexCoordPointer(2, GL_BYTE, 0, nokTexCoords);

	// Enable color arrays.
	//glEnableClientState(GL_COLOR_ARRAY);

	// Set color pointers.
	//glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);

	// Set the initial shading mode
	glShadeModel(GL_FLAT);
	//	glShadeModel(GL_SMOOTH);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
	//	glBlendFunc(GL_ONE, GL_ONE );
	_LIT(KOGLESTexture, "Particle.bmp");
	iTextureManager->RequestToLoad(KOGLESTexture, &iOpenGLES);
	iTextureManager->DoLoadL();

	for (loop = 0; loop < MAX_PARTICLES; loop++) //初始化所有的粒子
		{
		particle[loop].active = true; // 使所有的粒子为激活状态
		particle[loop].life = 1.0f; // 所有的粒子生命值为最大
		particle[loop].fade = float(Math::Random() % 100) / 1000.0f + 0.003f; // 随机生成衰减速率
		particle[loop].r = colors[loop * (12 / MAX_PARTICLES)][0]; // 粒子的红色颜色
		particle[loop].g = colors[loop * (12 / MAX_PARTICLES)][1]; // 粒子的绿色颜色
		particle[loop].b = colors[loop * (12 / MAX_PARTICLES)][2]; // 粒子的蓝色颜色
		particle[loop].xi = float((Math::Random() % 50) - 25.0f) * 10.0f; // 随机生成X轴方向速度
		particle[loop].yi = float((Math::Random() % 50) - 25.0f) * 10.0f; // 随机生成Y轴方向速度
		particle[loop].zi = float((Math::Random() % 50) - 25.0f) * 10.0f; // 随机生成Z轴方向速度
		particle[loop].xg = float(Math::Random() % 50) / 1000.0f; // 设置X轴方向加速度为0
		particle[loop].yg = float(Math::Random() % 50) / 1000.0f; // 设置Y轴方向加速度为-0.8
		particle[loop].zg = float(Math::Random() % 50) / 1000.0f; // 设置Z轴方向加速度为0
		}

	}
	void display(Uint8* data, int width, int height, 
		const gameswf::matrix* m, const gameswf::rect* bounds, const gameswf::rgba& color)
	{

		// this can't be placed in constructor becuase opengl may not be accessible yet
		if (m_texture == 0)
		{
			glEnable(GL_TEXTURE_2D);
			glGenTextures(1, &m_texture);
			glBindTexture(GL_TEXTURE_2D, m_texture);

			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// GL_NEAREST ?
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		}

		glBindTexture(GL_TEXTURE_2D, m_texture);
		glEnable(GL_TEXTURE_2D);

	//	glDisable(GL_TEXTURE_GEN_S);
	//	glDisable(GL_TEXTURE_GEN_T);

		// update texture from video frame
		if (data)
		{
			int w2p = p2(width);
			int h2p = p2(height);
			m_scoord = (float) width / w2p;
			m_tcoord = (float) height / h2p;

			if (m_clear_background)
			{
				// set video background color
				// assume left-top pixel of the first frame as background color
				if (m_background_color.m_a == 0)
				{
					m_background_color.m_a = 255;
					m_background_color.m_r = data[2];
					m_background_color.m_g = data[1];
					m_background_color.m_b = data[0];
				}

				// clear video background, input data has BGRA format
				Uint8* p = data;
				for (int y = 0; y < height; y++)
				{
					for (int x = 0; x < width; x++)
					{
						// calculate color distance, dist is in [0..195075]
						int r = m_background_color.m_r - p[2];
						int g = m_background_color.m_g - p[1];
						int b = m_background_color.m_b - p[0];
						float dist = (float) (r * r + g * g + b * b);

						static int s_min_dist = 3 * 64 * 64;	// hack
						Uint8 a = (dist < s_min_dist) ? (Uint8) (255 * (dist / s_min_dist)) : 255;

						p[3] = a;		// set alpha
						p += 4;
					}
				}
			}

			// don't use compressed texture for video, it slows down video
			//			ogl::create_texture(GL_RGBA, m_width2p, m_height2p, NULL);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2p, h2p, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
		}

		if (m_scoord == 0.0f && m_scoord == 0.0f)
		{
			// no data
			return;
		}

		gameswf::point a, b, c, d;
		m->transform(&a, gameswf::point(bounds->m_x_min, bounds->m_y_min));
		m->transform(&b, gameswf::point(bounds->m_x_max, bounds->m_y_min));
		m->transform(&c, gameswf::point(bounds->m_x_min, bounds->m_y_max));
		d.m_x = b.m_x + c.m_x - a.m_x;
		d.m_y = b.m_y + c.m_y - a.m_y;

		glColor4ub(color.m_r, color.m_g, color.m_b, color.m_a);

//		glBegin(GL_TRIANGLE_STRIP);
//		{
//			glTexCoord2f(0, 0);
//			glVertex2f(a.m_x, a.m_y);
//			glTexCoord2f(m_scoord, 0);
//			glVertex2f(b.m_x, b.m_y);
//			glTexCoord2f(0, m_tcoord);
//			glVertex2f(c.m_x, c.m_y);
//			glTexCoord2f(m_scoord, m_tcoord);
//			glVertex2f(d.m_x, d.m_y);
//		}
//		glEnd();

		// this code is equal to code that above

		GLfloat squareVertices[8]; 
		squareVertices[0] = a.m_x;
		squareVertices[1] = a.m_y;
		squareVertices[2] = b.m_x;
		squareVertices[3] = b.m_y;
		squareVertices[4] = c.m_x;
		squareVertices[5] = c.m_y;
		squareVertices[6] = d.m_x;
		squareVertices[7] = d.m_y;

		GLfloat squareTextureCoords[8];
		squareTextureCoords[0] = 0;
		squareTextureCoords[1] = 0;
		squareTextureCoords[2] = m_scoord;
		squareTextureCoords[3] = 0;
		squareTextureCoords[4] = 0;
		squareTextureCoords[5] = m_tcoord;
		squareTextureCoords[6] = m_scoord;
		squareTextureCoords[7] = m_tcoord;

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT, 0, squareTextureCoords);

		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(2, GL_FLOAT, 0, squareVertices);

		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisable(GL_LINE_SMOOTH);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);

		glDisable(GL_TEXTURE_2D);
	}
	void	draw_bitmap(
		const gameswf::matrix& m,
		gameswf::bitmap_info* bi,
		const gameswf::rect& coords,
		const gameswf::rect& uv_coords,
		gameswf::rgba color)
	// Draw a rectangle textured with the given bitmap, with the
	// given color.	 Apply given transform; ignore any currently
	// set transforms.
	//
	// Intended for textured glyph rendering.
	{
		assert(bi);
		bi->layout();

		apply_color(color);

		gameswf::point a, b, c, d;
		m.transform(&a, gameswf::point(coords.m_x_min, coords.m_y_min));
		m.transform(&b, gameswf::point(coords.m_x_max, coords.m_y_min));
		m.transform(&c, gameswf::point(coords.m_x_min, coords.m_y_max));
		d.m_x = b.m_x + c.m_x - a.m_x;
		d.m_y = b.m_y + c.m_y - a.m_y;

		GLfloat squareVertices[8];
		squareVertices[0] = a.m_x;
		squareVertices[1] = a.m_y;
		squareVertices[2] = b.m_x;
		squareVertices[3] = b.m_y;
		squareVertices[4] = c.m_x;
		squareVertices[5] = c.m_y;
		squareVertices[6] = d.m_x;
		squareVertices[7] = d.m_y;
	
		GLfloat squareTextureCoords[8];
		squareTextureCoords[0] = uv_coords.m_x_min;
		squareTextureCoords[1] = uv_coords.m_y_min;
		squareTextureCoords[2] = uv_coords.m_x_max;
		squareTextureCoords[3] = uv_coords.m_y_min;
		squareTextureCoords[4] = uv_coords.m_x_min;
		squareTextureCoords[5] = uv_coords.m_y_max;
		squareTextureCoords[6] = uv_coords.m_x_max;
		squareTextureCoords[7] = uv_coords.m_y_max;

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT, 0, squareTextureCoords);

		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(2, GL_FLOAT, 0, squareVertices);

		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisable(GL_LINE_SMOOTH);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);

		glDisable(GL_TEXTURE_2D);
	}
Exemple #10
0
// Draw the stars and the constellation lines, if you want them.
void GLStars::DrawStarsVA(GLfloat ColorAlpha, int starCount, bool drawConstellations){
   // The colors for the stars, north star, and constellation lines
        SetDesiredStarCount(starCount);
   GLfloat StarWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
   GLfloat StarBlue[4] = {0.2f, 0.2f, 1.0f, 1.0f};
   GLfloat LineWhite[4] = {1.0f, 1.0f, 1.0f, 0.6f};

   // Set the alpha value
   StarWhite[3] = ColorAlpha;
   StarBlue[3] = ColorAlpha;

   // Store the lighting bit. We need a special lighting so the stars and lines will show.
   glPushAttrib(GL_LIGHTING_BIT);
   glLightfv(GL_LIGHT0, GL_AMBIENT, SOURCELIGHT99);
   
   // Anti-aliasing. 
   glEnable(GL_POINT_SMOOTH);
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);

   // We want to use vertex arrays for efficiency
   glEnableClientState(GL_VERTEX_ARRAY);
        glDisable(GL_DEPTH_TEST);
   // Point to our array of star vertices
   glVertexPointer(4, GL_DOUBLE, 0, StarsVA);

   // First the north star
   glColor4fv(StarBlue);

   // Make it big so it stands out
   glPointSize(8.0f);
   // Draw the north star only
   glDrawArrays(GL_POINTS, 0, 1);
   int TotalDrawnStars = 1;

   // The rest of the stars are white
   glColor4fv(StarWhite);
   // Point again to the stars array
   glVertexPointer(4, GL_DOUBLE, 0, StarsVA);
   // Iterate through the groups and draw them all
   for (int i = 1; i <= LastGroupUsed; i++){
      // Groups are organized by visual magnitude
      glPointSize(PointSize[i]);
      // Draw them all
      glDrawArrays(GL_POINTS, GroupIndex[i], GroupCount[i]);
      // Count the stars we've drawn so far
      TotalDrawnStars += GroupCount[i];
      // If we start getting too many, stop
      if (TotalDrawnStars >= DesiredStarCount || TotalDrawnStars >= MaxDrawStars)
         break;
   }

   // Draw the constellation lines if the user wants them
   if (drawConstellations){
      // Set the color
      glColor4fv(LineWhite);
      // Point to the vertex array
      glVertexPointer(4, GL_FLOAT, 0, CLines);
      // Enable smoothing and make these lines thin
      glEnable(GL_LINE_SMOOTH);
      glLineWidth(0.3f);
      // Draw the lines
      glDrawArrays(GL_LINES, 0, NumLines);

      for (int i = 1; i < NumConstellations; i++){
         DrawStringAt(ConstellationNames[i], CLines[ConstellationIndex[i][0]][0],
            CLines[ConstellationIndex[i][0]][1],
            CLines[ConstellationIndex[i][0]][2],
                                CLines[ConstellationIndex[i][0]][3]);
      }
   }
        glEnable(GL_DEPTH_TEST);
   // Disable vertex arrays
   glDisableClientState(GL_VERTEX_ARRAY);

   // Disable blending
   glDisable(GL_BLEND);
   // Pop the lighting bit back
   glPopAttrib();
}
void GraphicsInit() 
{
  int red_bits, green_bits, blue_bits;
  struct {GLint x, y, width, height;} viewport;
  glEnable(GL_DEPTH_TEST);	/* turn on z-buffer */

  glGetIntegerv(GL_RED_BITS, &red_bits);
  glGetIntegerv(GL_GREEN_BITS, &green_bits);
  glGetIntegerv(GL_BLUE_BITS, &blue_bits);
  glGetIntegerv(GL_VIEWPORT, &viewport.x);
  printf("OpenGL window has %d bits red, %d green, %d blue; viewport is %dx%d\n",
    red_bits, green_bits, blue_bits, viewport.width, viewport.height);

  /* setup perspective camera with OpenGL */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0,(double) viewport.width/viewport.height, 0.01, 200.0); 

  /* from here on we're setting modeling transformations */
  glMatrixMode(GL_MODELVIEW);

  //Move away from center
  glTranslatef(0.0, 0.0, -5.0);

  camera.zoom = 1;

  camera.tw = 0;
  camera.el = -15;
  camera.az = -25;

  camera.atx = 0;
  camera.aty = 0;
  camera.atz = 0;

  // two white lights
  GLfloat light_Ka[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat light_Kd[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat light_Ks[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat light0_pos[] = { 0.0, groundPlaneLightHeight, 0.0, 0.0 };
  // GLfloat light0_pos[] = { -50.0, 50.0, 30.0, 0.0 };
  GLfloat light1_pos[] = {  1.0, -1.0, 0.0, 0.0 };

  // lights
  glLightfv(GL_LIGHT0, GL_AMBIENT,  light_Ka);
  glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_Kd);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);

  glLightfv(GL_LIGHT1, GL_AMBIENT,  light_Ka);
  glLightfv(GL_LIGHT1, GL_DIFFUSE,  light_Kd);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light_Ks);
  glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);

  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_NORMALIZE);
  glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, true);

  // screen buffer
  glClearDepth(1.0);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_POLYGON_SMOOTH);
  glEnable(GL_LINE_SMOOTH);
  glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
  glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
  glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

  //&groundPlaneHeight, &groundPlaneLightHeight, &groundPlaneSize, &groundPlaneR, &groundPlaneG, &groundPlaneB, &groundPlaneAmbient, &groundPlaneDiffuse, &groundPlaneSpecular, &groundPlaneShininess;
  // 0.0,180.0,150.0,r0.81,g0.81,b0.55,a0.1,d0.4,s0.1,sh120.0
  double groundPlaneHeight = 0.0;
  double groundPlaneSize = 200.0;
  double groundPlaneR = 0.81;
  double groundPlaneG = 0.81;
  double groundPlaneB = 0.55;
  double groundPlaneAmbient = 0.1;
  double groundPlaneDiffuse = 0.9;
  double groundPlaneSpecular = 0.1;
  double groundPlaneShininess = 120.0;
  displayListGround = glGenLists(1);
  glNewList(displayListGround, GL_COMPILE);
  RenderGroundPlane(groundPlaneSize, groundPlaneHeight, groundPlaneR, groundPlaneG, groundPlaneB, groundPlaneAmbient, groundPlaneDiffuse, groundPlaneSpecular, groundPlaneShininess);
  glEndList();
}
Exemple #12
0
void Graphics::SetMode( int x, int y, int bpp, bool fullscreen, int fsaa, int af, int z_bits, double z_near, double z_far )
{
	// Make sure we've initialized SDL.
	if( ! Initialized )
		Initialize();
	if( ! Initialized )
		return;
	
	// Set up the video properties.
	W = x;
	H = y;
	BPP = bpp;
	AspectRatio = (W && H) ? ((float)( W )) / ((float)( H )) : 1.f;
	Fullscreen = fullscreen;
	FSAA = fsaa;
	AF = af;
	ZBits = z_bits;
	ZNear = z_near;
	ZFar = z_far;
	
	// Enable double-buffering and vsync.
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );
	
	// Set minimum depth buffer.
	if( z_bits )
		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, z_bits );
	
	// Enable multi-sample anti-aliasing.
	if( FSAA > 1 )
	{
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, FSAA );
	}
	else
	{
		FSAA = 0;
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0 );
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 1 );
	}
	
	// Make sure we're getting hardware-accelerated OpenGL.
	SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
	
	// The current OpenGL context will be invalid, so clear all textures from the ResourceManager first.
	Raptor::Game->Res.DeleteGraphics();
	
	// Free the current screen.
	if( Screen )
		SDL_FreeSurface( Screen );
	
	#ifndef __APPLE__
		// Set the titlebar icon.
		SDL_Surface *icon = SDL_LoadBMP( Raptor::Game->Res.Find("icon.bmp").c_str() );
		if( icon )
		{
			SDL_WM_SetIcon( icon, NULL );
			SDL_FreeSurface( icon );
		}
	#endif
	
	// Create a new screen.
	Screen = SDL_SetVideoMode( x, y, bpp, SDL_OPENGL | SDL_ANYFORMAT | (Fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE) );
	
	if( ! Screen )
	{
		fprintf( stderr, "Unable to set %s video mode %ix%ix%i: %s\n", (fullscreen ? "fullscreen" : "windowed"), x, y, bpp, SDL_GetError() );
		
		// We couldn't set that video mode, so try unspecified Z-depth, then 640x480, then windowed.
		if( z_bits )
			SetMode( x, y, bpp, fullscreen, fsaa, af, 0, z_near, z_far );
		else if( fullscreen && ((x != 640) || (y != 480)) )
			SetMode( 640, 480, bpp, fullscreen, fsaa, af, z_bits, z_near, z_far );
		else if( fullscreen )
			SetMode( 640, 480, bpp, false, fsaa, af, z_bits, z_near, z_far );
		else
		{
			fflush( stderr );
			exit( -1 );
		}
		return;
	}
	
	// We successfully set the video mode, so pull the resolution from the SDL_Screen.
	W = Screen->w;
	H = Screen->h;
	RealW = W;
	RealH = H;
	AspectRatio = (W && H) ? ((float)( W )) / ((float)( H )) : 1.f;
	BPP = Screen->format->BitsPerPixel;
	
	if( Fullscreen )
	{
		// If we weren't able to use the level of multi-sample anti-aliasing requested,
		// update the setting to reflect this.  Ignored for windowed mode because it lies.
		int max_fsaa = 0;
		SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &max_fsaa );
		if( FSAA > max_fsaa )
			FSAA = max_fsaa;
		if( FSAA == 1 )
			FSAA = 0;
	}
	
	// Determine maximum anisotropic filtering.
	if( AF < 1 )
		AF = 1;
	GLint max_af = 1;
	glGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_af );
	if( AF > max_af )
		AF = max_af;
	
	// Set hints to nicest.
	glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
	glHint( GL_TEXTURE_COMPRESSION_HINT, GL_NICEST );
	glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_NICEST );
	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
	glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
	glHint( GL_FOG_HINT, GL_NICEST );
	
	#ifdef GL_PROGRAM_POINT_SIZE
		// Allow fixed-function point sizes.
		glDisable( GL_PROGRAM_POINT_SIZE );
	#endif
	
	// Tell the ResourceManager to reload any previously-loaded textures and shaders.
	Raptor::Game->Res.ReloadGraphics();
	
	// Set the titlebar name.
	SDL_WM_SetCaption( Raptor::Game->Game.c_str(), NULL );
	
	// Set the OpenGL state after creating the context with SDL_SetVideoMode.
	glViewport( 0, 0, W, H );
	
	// Enable alpha blending.
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
	// Disable the system cursor.
	SDL_ShowCursor( SDL_DISABLE );
	
	// Update the client config.
	if( Fullscreen )
	{
		Raptor::Game->Cfg.Settings[ "g_fullscreen" ] = "true";
		
		// We use x,y instead of W,H so 0,0 (native res) can be retained.
		Raptor::Game->Cfg.Settings[ "g_res_fullscreen_x" ] = Num::ToString(x);
		Raptor::Game->Cfg.Settings[ "g_res_fullscreen_y" ] = Num::ToString(y);
	}
	else
	{
		Raptor::Game->Cfg.Settings[ "g_fullscreen" ] = "false";
		
		// We use x,y instead of W,H so 0,0 (native res) can be retained.
		Raptor::Game->Cfg.Settings[ "g_res_windowed_x" ] = Num::ToString(x);
		Raptor::Game->Cfg.Settings[ "g_res_windowed_y" ] = Num::ToString(y);
	}
	Raptor::Game->Cfg.Settings[ "g_fsaa" ] = Num::ToString(FSAA);
	Raptor::Game->Cfg.Settings[ "g_af" ] = Num::ToString(AF);
	Raptor::Game->Cfg.Settings[ "g_znear" ] = Num::ToString(ZNear);
	Raptor::Game->Cfg.Settings[ "g_zfar" ] = Num::ToString(ZFar);
}
Exemple #13
0
// FUNCTION ======	setup
void setup(){
	//---- SDL initialization
	if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {        printf("Unable to initialize SDL: %s\n", SDL_GetError()); getchar() ;    }
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 
	//screen = SDL_SetVideoMode( WIDTH, HEIGHT, COLDEPTH, SDL_OPENGL |  SDL_SWSURFACE  ); 
	screen = SDL_SetVideoMode( WIDTH, HEIGHT, COLDEPTH, SDL_OPENGL ); 
    if(!screen)  { printf("Couldn't set %dx%d GL video mode: %s\n", WIDTH,HEIGHT, SDL_GetError()); SDL_Quit();  exit(2); }
	SDL_WM_SetCaption(" Prokop's test SDL+ OpenGL", "SDL+ OpenGL");

	//materialy
	float ambient  [] = { 0.10f, 0.15f, 0.25f, 1.0f}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,   ambient);
	float diffuse  [] = { 0.50f, 0.50f, 0.50f, 1.0f}; glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,   diffuse);
	float specular [] = { 0.00f, 0.00f, 0.00f, 1.0f}; glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  specular);
	float shininess[] = { 0.0f                     }; glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
	glEnable  (GL_LIGHT0);
	float light0_pos  [] = { 1000.0f, 0.0f, 0.0f, 1.00f}; glLightfv (GL_LIGHT0, GL_POSITION, light0_pos  );
	float light0_color[] = { 0.8f, 0.5f, 0.5f, 1.00f}; glLightfv (GL_LIGHT0, GL_DIFFUSE,  light0_color);
	glEnable  (GL_LIGHT1);
	float light1_pos  [] = { 0.0f, 1000.0f, 0.0f, 1.00f}; glLightfv (GL_LIGHT1, GL_POSITION, light1_pos  );
	float light1_color[] = { 0.5f, 0.8f, 0.5f, 1.00f}; glLightfv (GL_LIGHT1, GL_DIFFUSE,  light1_color);
	glEnable  (GL_LIGHT2);
	float light2_pos  [] = { 0.0f, 0.0f, 1000.0f, 1.00f}; glLightfv (GL_LIGHT2, GL_POSITION, light2_pos  );
	float light2_color[] = { 0.5f, 0.5f, 0.8f, 1.00f}; glLightfv (GL_LIGHT2, GL_DIFFUSE,  light2_color);
	glEnable  (GL_LIGHTING);
	glEnable (GL_COLOR_MATERIAL);
	glEnable  (GL_NORMALIZE);
	glEnable  (GL_DEPTH_TEST);
	//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	//glEnable(GL_BLEND) ;
	//glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);	
	glShadeModel(GL_SMOOTH);
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

	glClearColor( 0.9, 0.9, 0.9, 0.0);                      
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   

	srand(1234);

	trackball (qCamera, 0, 0, 0, 0); // qCameraOld[3] = 1.0;


	printf( "1\n" );

	body.pos.set( 1,1,1 ); 
	body.vel.set( 1,-1,1 );

	//const int len = 6; 
	//double masses[len]  = { 1,1, 1,1, 1,1 };
	//Vec3d  poss[len]    = { {-1,0,0}, {+1,0,0}, {0,-2,0}, {0,+2,0}, {0,0,-3}, {0,0,+3} }
	//printf( " %f %f \n", poss[0].x, poss_[0]  );

	printf( "2\n" );

	int boxList = makeBoxList( -1,1, -2,2, -3, 3,    0.9, 0.9, 0.9  );
	//rbody.shape = boxList;
	rbody.from_mass_points( len, masses, poss );
	//rbody.qrot.setOne();

	printf( "3\n" );

	rbody.qrot.set(4,-3,2,-1);	rbody.qrot.normalize();
	//rbody.pos.add( 5.0d,5.0d,5.0d );

	printf( "4\n" );

	rbody.vel.set(0.0);
	//rbody.L  .set(10,10,10);
	rbody.init( );
	rbody.shape = shapePointsCenter( len, poss, rbody.pos, 0.5 );

	printf( "5\n" );


	rbody2.shape = boxList;
	rbody2.from_mass_points( len, masses, poss );
	rbody2.qrot.setOne();
	rbody2.vel.set(0.0);
	//rbody2.L  .set(10,10,10);
	rbody2.init( );
	constrain1 = new SpringConstrain( 20, &rbody, &rbody2, {-1,-2,-3}, {1,2,3} );
	//Vec3d p1,p2; p1.set(-1,-2,-3); p2.set(1,2,3);
	//constrain1 = new SpringConstrain( 20, &rbody, &rbody2, p1, p2 );


	printf("mass: %f invMass %f \n", rbody.mass, rbody.invMass  );
	printf("Ibody\n");
	printMat(rbody.Ibody);
	printf("invIbody\n");
	printMat(rbody.invIbody);
}
__private_extern__ void initSaver(int width,int height,SolarWindsSaverSettings * inSettings)
{
    int i, j;
    float x,x2, y, temp;

    srand((unsigned)time(NULL));
    rand(); rand(); rand(); rand(); rand();

    // Window initialization

    glViewport(0,0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.0, float(width) / float(height), 1.0, 10000);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    if(!inSettings->dGeometry)
        glBlendFunc(GL_ONE, GL_ONE);
    else
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);  // Necessary for point and line smoothing (I don't know why)
    
    glEnable(GL_BLEND);

    if (glIsTexture(1))
    {
        GLuint tTex=1;
        
        glDeleteTextures(1, &tTex);
    }
    
    if(!inSettings->dGeometry)
    {
        // Init lights
        
        for(i=0; i<LIGHTSIZE; i++)
        {
            x = float(i - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);
            
            x2=x*x;
            
            for(j=0; j<LIGHTSIZE; j++)
            {
                y = float(j - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);

                temp = 1.0f - float(sqrt(x2 + (y * y)));

                if(temp > 1.0f)
                {
                    temp = 1.0f;
                }
                else
                {
                    if(temp < 0.0f)
                        temp = 0.0f;
                }
                
                inSettings->lightTexture[i][j] = (unsigned char) (255.0f * temp);
            }
        }
        
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 1);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, 1, LIGHTSIZE, LIGHTSIZE, 0,
                GL_LUMINANCE, GL_UNSIGNED_BYTE, inSettings->lightTexture);
        temp = 0.02f * float(inSettings->dSize);
        glNewList(1, GL_COMPILE);
            glBindTexture(GL_TEXTURE_2D, 1);
            glBegin(GL_TRIANGLE_STRIP);
                    glTexCoord2f(0.0f, 0.0f);
                    glVertex3f(-temp, -temp, 0.0f);
                    glTexCoord2f(1.0f, 0.0f);
                    glVertex3f(temp, -temp, 0.0f);
                    glTexCoord2f(0.0f, 1.0f);
                    glVertex3f(-temp, temp, 0.0f);
                    glTexCoord2f(1.0f, 1.0f);
                    glVertex3f(temp, temp, 0.0f);
            glEnd();
    
        glEndList();
    }
    else
    {
        glDisable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);
        
        if(inSettings->dGeometry == 1)
        {  // init point smoothing
            glEnable(GL_POINT_SMOOTH);
            glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
        }
        else
        {
            if(inSettings->dGeometry == 2)
            {  // init line smoothing
                glEnable(GL_LINE_SMOOTH);
                glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
            }
        }
    }

    // Initialize surfaces
    
    inSettings->winds = new wind[inSettings->dWinds];
	
	for(i=0;i<inSettings->dWinds;i++)
	{
		inSettings->winds[i].initializeWithSetting(inSettings);
	}
}
Exemple #15
0
// Fonction pour charger une texture à partir d'un fichier *.bmp
int LoadBMP(char *File)
{
	unsigned char	*Data;
	FILE			*fichier;
	unsigned char	Header[0x36];
	GLuint			DataPos,DataSize;
	GLint			Components;
	GLsizei			Width,Height;
	GLenum			Format,Type;
	GLuint			Name[1];

//Lit le fichier et son header
	fichier = fopen(File,"rb");if (!fichier) return -1;
	if (fread(Header,1,0x36,fichier)!=0x36) EXIT;
	if (Header[0]!='B' || Header[1]!='M')	EXIT;
	if (CTOI(Header[0x1E])!=0)				EXIT;
	if (CTOI(Header[0x1C])!=24)				EXIT;

//Récupère les infos du fichier
	DataPos			= CTOI(Header[0x0A]);
	DataSize		= CTOI(Header[0x22]);
//Récupère les infos de l'image
	Width			= CTOI(Header[0x12]);
	Height			= CTOI(Header[0x16]);
	Type = GL_UNSIGNED_BYTE;
	Format = GL_RGB;
	Components = 3;

	//!!!!
	if (DataSize==0) DataSize=Width*Height*Components;
	if (DataPos==0)  DataPos=0x36;

//Charge l'image
	fseek(fichier,DataPos,0);
	Data = new unsigned char[DataSize];
	if (!Data) EXIT;

	if (fread(Data,1,DataSize,fichier)!=DataSize)
	{
		delete Data;
		fclose(fichier);
		return -1;
	}

	fclose(fichier);

//Inverse R et B
	unsigned char t;
	for (int x=0;x<Width*Height;x++)
	{
		t=Data[x*3];
		Data[x*3]=Data[x*3+2];
		Data[x*3+2]=t;
	}

//Envoie la texture à OpenGL
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glGenTextures(1, Name);
	glBindTexture(GL_TEXTURE_2D, Name[0]);


	glTexImage2D
	(
		GL_TEXTURE_2D, 	//target
		0,				//mipmap level
		Components,		//nb couleurs
		Width,			//largeur
		Height,			//hauteur
		0,			 	//largeur du bord
		Format,			//type des couleurs
		Type,			//codage de chaque composante
		Data			//Image
	);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

	return Name[0];
}
Exemple #16
0
int RenderEngine::init() {


		p_camera = vec3(16,10,0);
		//Camera lookAt
		l_camera = vec3(0,0,0);
		//Camera up
		u_camera = vec3(0,1,0);
		//Light position
		p_light = vec3(110,60,0);
		//Light lookAt
		l_light = vec3(0,0,0);
		//Light Scatter Physical Light Location (used for demonstrations like title screen, where illumination is not same place as physical light in light scatter render)
		p_light_scatter = vec3(110,60,0);
		//Sky Color
		skyColor = vec4(0,0,0,0);
		//Trippy Light Scattering Mode
		deathScatter = false;

		FreeImage_Initialise();

		// set some lights
		{
				//float ambient[4] = { .5f, .5f, .5f, 1.f };
				float diffuse[4] = { 1.0f, 1.0f, 1.0f, 1.f };
				float pos[4] = { p_light[0], p_light[1], p_light[2], 0 };
				//glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
				glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
				glLightfv(GL_LIGHT0, GL_POSITION, pos);
				glEnable(GL_LIGHT0);
		}

		glEnable(GL_DEPTH_TEST);
		glClearColor(0,0,0,1.0f);
		glEnable(GL_CULL_FACE);
		glFrontFace(GL_CCW);
		glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

		this->activate();	

		glutDisplayFunc(renderFunction);
		glutIdleFunc(renderFunction);


		glewInit();

		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
				printf("Ready for GLSL\n");
		else {
				printf("No GLSL support\n");
				exit(1);
		}

		//Generate FBOs
		generateShadowFBO();
		generateBlurFBO();
		generateLightFBO();

		//Load Shaders
		shade = new ShadowShader("shaders/MainVertexShader.c", "shaders/MainFragmentShader.c");
		blurShade = new BlurShader("shaders/GaussianBlurVertexShader.c", "shaders/GaussianBlurFragmentShader.c");
		depthShade = new GeometryShader("shaders/DepthVertexShader.c", "shaders/DepthFragmentShader.c");
		scatterShade = new ScatterShader("shaders/ScatteringVertexShader.c", "shaders/ScatteringFragmentShader.c");
		darkShade = new GeometryShader("shaders/SimpleDarkVertexShader.c", "shaders/SimpleDarkFragmentShader.c");

		return 0;


}
Exemple #17
0
void processFn(struct fnargs* args) {
	switch (args->fn) {
	case glfnUNDEFINED:
		abort(); // bad glfn
		break;
	case glfnActiveTexture:
		glActiveTexture((GLenum)args->a0);
		break;
	case glfnAttachShader:
		glAttachShader((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnBindAttribLocation:
		glBindAttribLocation((GLint)args->a0, (GLint)args->a1, (GLchar*)args->a2);
		free((void*)args->a2);
		break;
	case glfnBindBuffer:
		glBindBuffer((GLenum)args->a0, (GLuint)args->a1);
		break;
	case glfnBindFramebuffer:
		glBindFramebuffer((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBindRenderbuffer:
		glBindRenderbuffer((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBindTexture:
		glBindTexture((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBlendColor:
		glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnBlendEquation:
		glBlendEquation((GLenum)args->a0);
		break;
	case glfnBlendEquationSeparate:
		glBlendEquationSeparate((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnBlendFunc:
		glBlendFunc((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnBlendFuncSeparate:
		glBlendFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3);
		break;
	case glfnBufferData:
		glBufferData((GLenum)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2, (GLenum)args->a3);
		break;
	case glfnBufferSubData:
		glBufferSubData((GLenum)args->a0, (GLint)args->a1, (GLsizeiptr)args->a2, (GLvoid*)args->a3);
		break;
	case glfnCheckFramebufferStatus:
		ret = glCheckFramebufferStatus((GLenum)args->a0);
		break;
	case glfnClear:
		glClear((GLenum)args->a0);
		break;
	case glfnClearColor:
		glClearColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnClearDepthf:
		glClearDepthf(*(GLfloat*)&args->a0);
		break;
	case glfnClearStencil:
		glClearStencil((GLint)args->a0);
		break;
	case glfnColorMask:
		glColorMask((GLboolean)args->a0, (GLboolean)args->a1, (GLboolean)args->a2, (GLboolean)args->a3);
		break;
	case glfnCompileShader:
		glCompileShader((GLint)args->a0);
		break;
	case glfnCompressedTexImage2D:
		glCompressedTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLsizeiptr)args->a6, (GLvoid*)args->a7);
		break;
	case glfnCompressedTexSubImage2D:
		glCompressedTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLenum)args->a6, (GLsizeiptr)args->a7, (GLvoid*)args->a8);
		break;
	case glfnCopyTexImage2D:
		glCopyTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7);
		break;
	case glfnCopyTexSubImage2D:
		glCopyTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7);
		break;
	case glfnCreateProgram:
		ret = glCreateProgram();
		break;
	case glfnCreateShader:
		ret = glCreateShader((GLenum)args->a0);
		break;
	case glfnCullFace:
		glCullFace((GLenum)args->a0);
		break;
	case glfnDeleteBuffer:
		glDeleteBuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteFramebuffer:
		glDeleteFramebuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteProgram:
		glDeleteProgram((GLint)args->a0);
		break;
	case glfnDeleteRenderbuffer:
		glDeleteRenderbuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteShader:
		glDeleteShader((GLint)args->a0);
		break;
	case glfnDeleteTexture:
		glDeleteTextures(1, (const GLuint*)(&args->a0));
		break;
	case glfnDepthFunc:
		glDepthFunc((GLenum)args->a0);
		break;
	case glfnDepthMask:
		glDepthMask((GLboolean)args->a0);
		break;
	case glfnDepthRangef:
		glDepthRangef(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnDetachShader:
		glDetachShader((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnDisable:
		glDisable((GLenum)args->a0);
		break;
	case glfnDisableVertexAttribArray:
		glDisableVertexAttribArray((GLint)args->a0);
		break;
	case glfnDrawArrays:
		glDrawArrays((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2);
		break;
	case glfnDrawElements:
		glDrawElements((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (void*)args->a3);
		break;
	case glfnEnable:
		glEnable((GLenum)args->a0);
		break;
	case glfnEnableVertexAttribArray:
		glEnableVertexAttribArray((GLint)args->a0);
		break;
	case glfnFinish:
		glFinish();
		break;
	case glfnFlush:
		glFlush();
		break;
	case glfnFramebufferRenderbuffer:
		glFramebufferRenderbuffer((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3);
		break;
	case glfnFramebufferTexture2D:
		glFramebufferTexture2D((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4);
		break;
	case glfnFrontFace:
		glFrontFace((GLenum)args->a0);
		break;
	case glfnGenBuffer:
		glGenBuffers(1, (GLuint*)&ret);
		break;
	case glfnGenFramebuffer:
		glGenFramebuffers(1, (GLuint*)&ret);
		break;
	case glfnGenRenderbuffer:
		glGenRenderbuffers(1, (GLuint*)&ret);
		break;
	case glfnGenTexture:
		glGenTextures(1, (GLuint*)&ret);
		break;
	case glfnGenerateMipmap:
		glGenerateMipmap((GLenum)args->a0);
		break;
	case glfnGetActiveAttrib:
		glGetActiveAttrib(
			(GLuint)args->a0,
			(GLuint)args->a1,
			(GLsizei)args->a2,
			NULL,
			(GLint*)args->a4,
			(GLenum*)args->a5,
			(GLchar*)args->a6);
		break;
	case glfnGetActiveUniform:
		glGetActiveUniform(
			(GLuint)args->a0,
			(GLuint)args->a1,
			(GLsizei)args->a2,
			NULL,
			(GLint*)args->a4,
			(GLenum*)args->a5,
			(GLchar*)args->a6);
		break;
	case glfnGetAttachedShaders:
		glGetAttachedShaders((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)args->a2, (GLuint*)args->a3);
		break;
	case glfnGetAttribLocation:
		ret = glGetAttribLocation((GLint)args->a0, (GLchar*)args->a1);
		free((void*)args->a1);
		break;
	case glfnGetBooleanv:
		glGetBooleanv((GLenum)args->a0, (GLboolean*)args->a1);
		break;
	case glfnGetBufferParameteri:
		glGetBufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetFloatv:
		glGetFloatv((GLenum)args->a0, (GLfloat*)args->a1);
		break;
	case glfnGetIntegerv:
		glGetIntegerv((GLenum)args->a0, (GLint*)args->a1);
		break;
	case glfnGetError:
		ret = glGetError();
		break;
	case glfnGetFramebufferAttachmentParameteriv:
		glGetFramebufferAttachmentParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint*)&ret);
		break;
	case glfnGetProgramiv:
		glGetProgramiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetProgramInfoLog:
		glGetProgramInfoLog((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)args->a2, (GLchar*)args->a3);
		break;
	case glfnGetRenderbufferParameteriv:
		glGetRenderbufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetShaderiv:
		glGetShaderiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetShaderInfoLog:
		glGetShaderInfoLog((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)args->a2, (GLchar*)args->a3);
		break;
	case glfnGetShaderPrecisionFormat:
		glGetShaderPrecisionFormat((GLenum)args->a0, (GLenum)args->a1, (GLint*)args->a2, (GLint*)args->a3);
		break;
	case glfnGetShaderSource:
		glGetShaderSource((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)args->a2, (GLchar*)args->a3);
		break;
	case glfnGetString:
		ret = (uintptr_t)glGetString((GLenum)args->a0);
		break;
	case glfnGetTexParameterfv:
		glGetTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)args->a2);
		break;
	case glfnGetTexParameteriv:
		glGetTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)args->a2);
		break;
	case glfnGetUniformfv:
		glGetUniformfv((GLuint)args->a0, (GLint)args->a1, (GLfloat*)args->a2);
		break;
	case glfnGetUniformiv:
		glGetUniformiv((GLuint)args->a0, (GLint)args->a1, (GLint*)args->a2);
		break;
	case glfnGetUniformLocation:
		ret = glGetUniformLocation((GLint)args->a0, (GLchar*)args->a1);
		free((void*)args->a1);
		break;
	case glfnGetVertexAttribfv:
		glGetVertexAttribfv((GLuint)args->a0, (GLenum)args->a1, (GLfloat*)args->a2);
		break;
	case glfnGetVertexAttribiv:
		glGetVertexAttribiv((GLuint)args->a0, (GLenum)args->a1, (GLint*)args->a2);
		break;
	case glfnHint:
		glHint((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnIsBuffer:
		ret = glIsBuffer((GLint)args->a0);
		break;
	case glfnIsEnabled:
		ret = glIsEnabled((GLenum)args->a0);
		break;
	case glfnIsFramebuffer:
		ret = glIsFramebuffer((GLint)args->a0);
		break;
	case glfnIsProgram:
		ret = glIsProgram((GLint)args->a0);
		break;
	case glfnIsRenderbuffer:
		ret = glIsRenderbuffer((GLint)args->a0);
		break;
	case glfnIsShader:
		ret = glIsShader((GLint)args->a0);
		break;
	case glfnIsTexture:
		ret = glIsTexture((GLint)args->a0);
		break;
	case glfnLineWidth:
		glLineWidth(*(GLfloat*)&args->a0);
		break;
	case glfnLinkProgram:
		glLinkProgram((GLint)args->a0);
		break;
	case glfnPixelStorei:
		glPixelStorei((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnPolygonOffset:
		glPolygonOffset(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnReadPixels:
		glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)args->a6);
		break;
	case glfnReleaseShaderCompiler:
		glReleaseShaderCompiler();
		break;
	case glfnRenderbufferStorage:
		glRenderbufferStorage((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnSampleCoverage:
		glSampleCoverage(*(GLfloat*)&args->a0, (GLboolean)args->a1);
		break;
	case glfnScissor:
		glScissor((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnShaderSource:
#if defined(os_ios) || defined(os_osx)
		glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar *const *)args->a2, NULL);
#else
		glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar **)args->a2, NULL);
#endif
		free(*(void**)args->a2);
		free((void*)args->a2);
		break;
	case glfnStencilFunc:
		glStencilFunc((GLenum)args->a0, (GLint)args->a1, (GLuint)args->a2);
		break;
	case glfnStencilFuncSeparate:
		glStencilFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLuint)args->a3);
		break;
	case glfnStencilMask:
		glStencilMask((GLuint)args->a0);
		break;
	case glfnStencilMaskSeparate:
		glStencilMaskSeparate((GLenum)args->a0, (GLuint)args->a1);
		break;
	case glfnStencilOp:
		glStencilOp((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2);
		break;
	case glfnStencilOpSeparate:
		glStencilOpSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3);
		break;
	case glfnTexImage2D:
		glTexImage2D(
			(GLenum)args->a0,
			(GLint)args->a1,
			(GLint)args->a2,
			(GLsizei)args->a3,
			(GLsizei)args->a4,
			0, // border
			(GLenum)args->a5,
			(GLenum)args->a6,
			(const GLvoid*)args->a7);
		break;
	case glfnTexSubImage2D:
		glTexSubImage2D(
			(GLenum)args->a0,
			(GLint)args->a1,
			(GLint)args->a2,
			(GLint)args->a3,
			(GLsizei)args->a4,
			(GLsizei)args->a5,
			(GLenum)args->a6,
			(GLenum)args->a7,
			(const GLvoid*)args->a8);
		break;
	case glfnTexParameterf:
		glTexParameterf((GLenum)args->a0, (GLenum)args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnTexParameterfv:
		glTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)args->a2);
		break;
	case glfnTexParameteri:
		glTexParameteri((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2);
		break;
	case glfnTexParameteriv:
		glTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)args->a2);
		break;
	case glfnUniform1f:
		glUniform1f((GLint)args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnUniform1fv:
		glUniform1fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform1i:
		glUniform1i((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnUniform1iv:
		glUniform1iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform2f:
		glUniform2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnUniform2fv:
		glUniform2fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform2i:
		glUniform2i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2);
		break;
	case glfnUniform2iv:
		glUniform2iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform3f:
		glUniform3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnUniform3fv:
		glUniform3fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform3i:
		glUniform3i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnUniform3iv:
		glUniform3iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform4f:
		glUniform4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4);
		break;
	case glfnUniform4fv:
		glUniform4fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniform4i:
		glUniform4i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4);
		break;
	case glfnUniform4iv:
		glUniform4iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)args->a2);
		break;
	case glfnUniformMatrix2fv:
		glUniformMatrix2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)args->a2);
		break;
	case glfnUniformMatrix3fv:
		glUniformMatrix3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)args->a2);
		break;
	case glfnUniformMatrix4fv:
		glUniformMatrix4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)args->a2);
		break;
	case glfnUseProgram:
		glUseProgram((GLint)args->a0);
		break;
	case glfnValidateProgram:
		glValidateProgram((GLint)args->a0);
		break;
	case glfnVertexAttrib1f:
		glVertexAttrib1f((GLint)args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnVertexAttrib1fv:
		glVertexAttrib1fv((GLint)args->a0, (GLfloat*)args->a1);
		break;
	case glfnVertexAttrib2f:
		glVertexAttrib2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnVertexAttrib2fv:
		glVertexAttrib2fv((GLint)args->a0, (GLfloat*)args->a1);
		break;
	case glfnVertexAttrib3f:
		glVertexAttrib3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnVertexAttrib3fv:
		glVertexAttrib3fv((GLint)args->a0, (GLfloat*)args->a1);
		break;
	case glfnVertexAttrib4f:
		glVertexAttrib4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4);
		break;
	case glfnVertexAttrib4fv:
		glVertexAttrib4fv((GLint)args->a0, (GLfloat*)args->a1);
		break;
	case glfnVertexAttribPointer:
		glVertexAttribPointer((GLuint)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLboolean)args->a3, (GLsizei)args->a4, (const GLvoid*)args->a5);
		break;
	case glfnViewport:
		glViewport((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	}
}
Exemple #18
0
void OGLRender::Initialize(void)
{
    glMatrixMode(GL_MODELVIEW);
    OPENGL_CHECK_ERRORS;
    glLoadIdentity();
    OPENGL_CHECK_ERRORS;

    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
    OPENGL_CHECK_ERRORS;

#if SDL_VIDEO_OPENGL
    COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
    if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_IBM;
    }
    else if( pcontext->IsExtensionSupported("ARB_texture_mirrored_repeat") )
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_ARB;
    }
    else
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_REPEAT;
    }

    if( pcontext->IsExtensionSupported("GL_ARB_texture_border_clamp") || pcontext->IsExtensionSupported("GL_EXT_texture_edge_clamp") )
    {
        m_bSupportClampToEdge = true;
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
    }
    else
    {
        m_bSupportClampToEdge = false;
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP;
    }

    glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
    OPENGL_CHECK_ERRORS;
    glEnableClientState( GL_VERTEX_ARRAY );
    OPENGL_CHECK_ERRORS;

    if( m_bMultiTexture )
    {
        pglClientActiveTextureARB( GL_TEXTURE0_ARB );
        OPENGL_CHECK_ERRORS;
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;

        pglClientActiveTextureARB( GL_TEXTURE1_ARB );
        OPENGL_CHECK_ERRORS;
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;
    }
    else
    {
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;
    }

    if (m_bSupportFogCoordExt)
    {
        pglFogCoordPointerEXT( GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][4]) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
        OPENGL_CHECK_ERRORS;
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
        OPENGL_CHECK_ERRORS;
        glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
        OPENGL_CHECK_ERRORS;
        glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be
        OPENGL_CHECK_ERRORS;
        glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value
        OPENGL_CHECK_ERRORS;
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
        OPENGL_CHECK_ERRORS;
        glFogf( GL_FOG_START, 0.0f );
        OPENGL_CHECK_ERRORS;
        glFogf( GL_FOG_END, 1.0f );
        OPENGL_CHECK_ERRORS;
    }

    //glColorPointer( 1, GL_UNSIGNED_BYTE, sizeof(TLITVERTEX), &g_vtxBuffer[0].r);
    glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
    OPENGL_CHECK_ERRORS;
    glEnableClientState( GL_COLOR_ARRAY );
    OPENGL_CHECK_ERRORS;

    if( pcontext->IsExtensionSupported("GL_NV_depth_clamp") )
    {
        glEnable(GL_DEPTH_CLAMP_NV);
        OPENGL_CHECK_ERRORS;
    }

#elif SDL_VIDEO_OPENGL_ES2
    OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT;
    m_bSupportClampToEdge = true;
    OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;

    glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
    OPENGL_CHECK_ERRORS;

    if( m_bMultiTexture )
    {
        glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
        OPENGL_CHECK_ERRORS;
        glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
        OPENGL_CHECK_ERRORS;
    }
    else
    {
        glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
        OPENGL_CHECK_ERRORS;
    }

    if (m_bSupportFogCoordExt)
    {
        glVertexAttribPointer(VS_FOG,1,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][4]));
        OPENGL_CHECK_ERRORS;
    }

    glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
    OPENGL_CHECK_ERRORS;
#endif

#ifdef ANDROID_EDITION
    hardwareType = Android_JNI_GetHardwareType();
#endif
}
Exemple #19
0
void display (void) {
    
    glClearColor (0.0,0.0,0.0,1.0); //clear the screen to black
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the color buffer and the depth buffer
    glMatrixMode( GL_MODELVIEW );
    glColor4f(1.0f,0.0f,0.0f,1.0f);
    
    glEnable(GL_SCISSOR_TEST);
    glMatrixMode (GL_PROJECTION); //set the matrix to projection
    
    // Draw the primary view
    glViewport (0, 0, (GLsizei)screen_width, (GLsizei)screen_height); //set the viewport to the current window specifications
    glScissor(0, 0, (GLsizei)screen_width, (GLsizei)screen_height);
    glLoadIdentity ();
    
    if (lighting) {
        GLfloat AmbientLight[] = {0.1, 0.1, 0.2};
        glLightfv (GL_LIGHT0, GL_AMBIENT, AmbientLight);
        GLfloat DiffuseLight[] = {1, 1, 1};
        glLightfv (GL_LIGHT1, GL_DIFFUSE, DiffuseLight);
        GLfloat LightPosition[] = {xpos, ypos, zpos, 1};
        glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
    }
    gluPerspective (60, (GLfloat)screen_width / (GLfloat)screen_height, 1.0, 100.0);
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //camera position, x,y,z, looking at x,y,z, Up Positions of the camera
    camera();
    glPushMatrix();
    if (lighting) {
        texture1 = LoadTexture( "texture.raw", 256, 256 );
        texture2 = LoadTexture( "/dev/urandom", 256, 256 );
        texture3 = LoadTexture( "water.raw", 500, 375 );
        texture4 = LoadTexture( "bubbles.raw", 200, 200 );
        glEnable( GL_TEXTURE_2D ); //enable 2D texturing
        glEnable(GL_TEXTURE_GEN_S); //enable texture coordinate generation
        glEnable(GL_TEXTURE_GEN_T);
        
        if (fog) {
            GLfloat fogColor[4]= {0.5f, 1.0f, 0.5f, 1};  // Fog Color
            glFogi(GL_FOG_MODE, GL_EXP);        // Fog Mode
            glFogfv(GL_FOG_COLOR, fogColor);    // Set Fog Color
            glFogf(GL_FOG_DENSITY, 1.0f);       // How Dense Will The Fog Be
            glHint(GL_FOG_HINT, GL_DONT_CARE);  // Fog Hint Value
            glFogf(GL_FOG_START, n*space);      // Fog Start Depth
            glFogf(GL_FOG_END,-n*space);          // Fog End Depth
        }
        
        if (nurb) {
            glPushMatrix();
            glRotatef(270,0.0,1.0,0.0);
            glTranslated(n*space/2,n*space/2,-n*space);
            GLfloat ctlpoints[4][4][3];
            GLUnurbsObj *theNurb;
            GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
            int u, v;
            for (u = 0; u < 4; u++) {
               for (v = 0; v < 4; v++) {
                  ctlpoints[u][v][0] = 2.0*((GLfloat)u - 1.5);
                  ctlpoints[u][v][1] = 2.0*((GLfloat)v - 1.5);

                  if ( (u == 1 || u == 2) && (v == 1 || v == 2))
                     ctlpoints[u][v][2] = 3.0;
                  else
                     ctlpoints[u][v][2] = -3.0;
               }
            }

            theNurb = gluNewNurbsRenderer();
            gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
            gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
            gluBeginSurface(theNurb);
            gluNurbsSurface(theNurb, 
                               8, knots, 8, knots,
                               4 * 3, 3, &ctlpoints[0][0][0], 
                               4, 4, GL_MAP2_VERTEX_3);
            gluEndSurface(theNurb);
            glPopMatrix();
        }
    }
    cube(); //call the cube drawing function
    glPopMatrix();
    if (lighting) {
        FreeTexture( texture1 );
        FreeTexture( texture2 );
        FreeTexture( texture3 );
        FreeTexture( texture4 );
    }
    glPushMatrix();
    glTranslated(space*((n/2)+1),space*(n/2),space*(n/2));
    glutWireCube(space*n);
    glPopMatrix();
    
    // Draw the secondary view
    glViewport (3*(screen_width/4), 3*(screen_height/4), screen_width/4, screen_width/4); //set the viewport to the current window specifications
    glScissor(3*(screen_width/4), 3*(screen_height/4), screen_width/4, screen_width/4);
    glLoadIdentity();
    glOrtho(-1, 13, -1, 13, -1, 13);
    glRotatef(90,0.0,1.0,0.0); 
    cube();
    glDisable(GL_SCISSOR_TEST);
    glutSwapBuffers(); //swap the buffers
}
void Init_Graphics(int x, int y, int windowed)
{
  Uint32 Vflags = SDL_ANYFORMAT | SDL_SRCALPHA;
    Uint32 HWflag = 0;



    S_Data.xres = 1024;
    S_Data.yres = 768;
    if(!windowed)Vflags |= SDL_FULLSCREEN;
      Vflags |= SDL_OPENGL;

    #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
    #else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
    #endif

    
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 )
      {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
      }

    else if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_DOUBLEBUF) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);
   

    if(SDL_VideoModeOK(x, y, 32, Vflags | SDL_HWSURFACE))
    {
      S_Data.xres = x;
      S_Data.yres = y;
        S_Data.depth = 32;
        HWflag = SDL_HWSURFACE;

          SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
          SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
          SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
          SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
          SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    }
    else if(SDL_VideoModeOK(1280, 720, 32, Vflags | SDL_HWSURFACE))
    {
        S_Data.xres = 1024;
        S_Data.yres = 768;
        S_Data.depth = 32;

        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        HWflag = SDL_HWSURFACE;
    }
    else
    {
        fprintf(stderr, "Unable to Use your crap: %s\n Upgrade \n", SDL_GetError());
        exit(1);
    }
    videobuffer = SDL_SetVideoMode(S_Data.xres, S_Data.yres,S_Data.depth, Vflags | HWflag);
    if ( videobuffer == NULL )
    {
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
        exit(1);
    }
    pixelFormat = videobuffer->format;
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
    SDL_ShowCursor(SDL_DISABLE);

    glCamera.position.x = -250.0f;
    glCamera.position.y = -900.0f;
    glCamera.position.z = 1000.0f;
    glCamera.rotation.x = -225.0f;
    glCamera.rotation.y = 0.0f;
    glCamera.rotation.z = 0.0f;
    SDL_JoystickEventState(SDL_ENABLE);
    /*sets the viewing port to the size of the videobuffer*/
    glViewport(0,0,XRES, YRES);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    /*view angle, aspect ratio, near clip distance, far clip distance*/
    gluPerspective( 40, (float)XRES / (float)YRES, .1, 10000.0f);
    /*gluOrtho2D(0,S_Data.xres,S_Data.yres,0);*/
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    /*Clear color for the buffer*/
    glClearColor(0.2,0.2,0.2,0);
    /*Enables drawing pixels according to thier depth*/
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    /*Enables alpha testing*/
    glAlphaFunc(GL_GREATER,0);
    glEnable(GL_ALPHA_TEST);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    srand(time(NULL));

}
Exemple #21
0
BOOL InitOpenGL()
{
	GLfloat pos[]={1.0,1.0,-6.0};
    g_eye[0]=0.0;
	g_eye[1]=0.0;
	g_eye[2]=-100.0;
	g_center[0]= 0.0;
	g_center[1]= 0.0;
	g_center[2]= 0.0;
	glClearColor(0.0,0.0,0.0,1.0);
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LINE_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
	LoadTexture("floor.bmp");	
	g_obj.InitObject("tris.md2","tris.tga");
	g_obj.SetState(CROUCH_STAND);
	//g_loader.LoadModel("tris.md2");
	//g_loader.LoadSkin("tris.tga");
	//g_loader.SetAnim(POINT_A);
 //   g_loader.ScaleModel(1.5);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	glTexEnvf(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_REPLACE);

	glLightfv(GL_LIGHT0,GL_POSITION,pos);

	//glEnable(GL_LIGHTING);
	//glEnable(GL_LIGHT0);
	glEnable(GL_TEXTURE);
	glEnable(GL_TEXTURE_2D);

	LoadTerrain("Terrain.bmp");

	g_envList=glGenLists(1);
	glNewList(g_envList,GL_COMPILE);
	glPushMatrix();
	glEnable(GL_TEXTURE);
	glBindTexture(GL_TEXTURE_2D,texname);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	glTexEnvf(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_MODULATE);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(-500.0,0.0,500.0);
	glTexCoord2d(4.0,0.0);glVertex3f(500.0,0.0,500.0);
	glTexCoord2d(4.0,4.0);glVertex3f(500.0,0.0,-500.0);
	glTexCoord2d(0.0,4.0);glVertex3f(-500.0,0.0,-500.0);
	glEnd();	
#define SCALE_X            (1100.0f/32)
#define SCALE_Z            (1100.0f/32)
//    GLfloat x= -550.0;
//    GLfloat z= -550.0;
//	for (int i=0;i<MAP_X-1;x+=SCALE_X,++i)
//	{
//		z = -550.0;
//		for (int e=0;e < MAP_Z-1;z+=SCALE_Z,++e)
//		{
//	        glBegin(GL_QUADS);
//			glTexCoord2f(x,z);    glVertex3f(x,g_imageData[i][e],z);
//			glTexCoord2f(x+1,z);  glVertex3f(x+SCALE_X,g_imageData[i+1][e],z);
//			glTexCoord2f(x+1,z+1);glVertex3f(x+SCALE_X,g_imageData[i+1][e+1],z+SCALE_Z);
//			glTexCoord2f(x,z+1);  glVertex3f(x,g_imageData[i][e+1],z+SCALE_Z);
//            glEnd();
//		}
//	}
	

	glBindTexture(GL_TEXTURE_2D,texTop);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(-500.0,500.0,500.0);
	glTexCoord2d(1.0,0.0);glVertex3f(500.0,500.0,500.0);
	glTexCoord2d(1.0,1.0);glVertex3f(500.0,500.0,-500.0);
	glTexCoord2d(0.0,1.0);glVertex3f(-500.0,500.0,-500.0);
	glEnd();

	glMatrixMode(GL_MODELVIEW);

	glBindTexture(GL_TEXTURE_2D,texFront);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(-500.0,500.0,-500.0);
	glTexCoord2d(1.0,0.0);glVertex3f(500.0,500.0,-500.0);
	glTexCoord2d(1.0,1.0);glVertex3f(500.0,0.0,-500.0);
	glTexCoord2d(0.0,1.0);glVertex3f(-500.0,0.0,-500.0);
	glEnd();

	glBindTexture(GL_TEXTURE_2D,texRight);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(-500.0,500.0,500.0);
	glTexCoord2d(1.0,0.0);glVertex3f(-500.0,500.0,-500.0);
	glTexCoord2d(1.0,1.0);glVertex3f(-500.0,0.0,-500.0);
	glTexCoord2d(0.0,1.0);glVertex3f(-500.0,0.0,500.0);
	glEnd();

	glBindTexture(GL_TEXTURE_2D,texLeft);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(500.0,500.0,-500.0);
	glTexCoord2d(1.0,0.0);glVertex3f(500.0,500.0,500.0);
	glTexCoord2d(1.0,1.0);glVertex3f(500.0,0.0,500.0);
	glTexCoord2d(0.0,1.0);glVertex3f(500.0,0.0,-500.0);
	glEnd();

	glBindTexture(GL_TEXTURE_2D,texBack);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
	glBegin(GL_POLYGON);
	glTexCoord2d(0.0,0.0);glVertex3f(500.0,500.0,500.0);
	glTexCoord2d(1.0,0.0);glVertex3f(-500.0,500.0,500.0);
	glTexCoord2d(1.0,1.0);glVertex3f(-500.0,0.0,500.0);
	glTexCoord2d(0.0,1.0);glVertex3f(500.0,0.0,500.0);
	glEnd();

	glDisable(GL_TEXTURE);
	glPopMatrix();
	glEndList();
	return TRUE;
}
int graphics3d_init(int sw,int sh,int fullscreen,const char *project,Uint32 frameDelay)
{
    const unsigned char *version;
    GLenum glew_status;
        
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        slog("failed to initialize SDL!");
        return -1;
    }
    atexit(SDL_Quit);
    __graphics3d_frame_delay = frameDelay;
    
    __graphics3d_window = SDL_CreateWindow(project?project:"gametest3d",
                              SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              sw, sh,
                              SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
    
    
    __graphics3d_gl_context = SDL_GL_CreateContext(__graphics3d_window);
    if (__graphics3d_gl_context == NULL)
    {
        slog("There was an error creating the OpenGL context!\n");
        return -1;
    }
    
    version = glGetString(GL_VERSION);
    if (version == NULL) 
    {
        slog("There was an error creating the OpenGL context!\n");
        return -1;
    }
    
    SDL_GL_MakeCurrent(__graphics3d_window, __graphics3d_gl_context);
    
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
    
    //MUST make a context AND make it current BEFORE glewInit()!
    glewExperimental = GL_TRUE;
    glew_status = glewInit();
    if (glew_status != 0) 
    {
        slog("Error: %s", glewGetErrorString(glew_status));
        return -1;
    }
    
    
    __graphics3d_shader_program = BuildShaderProgram("shaders/vs1.glsl", "shaders/fs1.glsl");
    if (__graphics3d_shader_program == -1)
    {
        return -1;
    }
    
    
    glViewport(0,0,sw, sh);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    /*view angle, aspect ratio, near clip distance, far clip distance*/
    /*TODO: put near/far clip in graphics view config*/
    gluPerspective( 90, (float)sw / (float)sh, .01, 2000.0f);
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glClearColor(0.0,0.0,0.0,0.0);
    glClear( 1 );
    
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    /*Enables alpha testing*/
/*    glAlphaFunc(GL_GREATER,0);
    glEnable(GL_ALPHA_TEST);*/
    
    graphics3d_setup_default_light();
    atexit(graphics3d_close);
    return 0;
}
Exemple #23
0
void GL_Enter3D( double dFOV, int iWindowWidth, int iWindowDepth, bool bWireFrame, bool bCLS/* = true */)
{
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
	if (iWindowDepth > 0) 
		gluPerspective( dFOV, (double)iWindowWidth/(double)iWindowDepth, NEAR_GL_PLANE, FAR_GL_PLANE );
	glViewport( 0, 0, iWindowWidth, iWindowDepth );
    
    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_DEPTH_TEST);	

	if (bCLS)
	{
//		glClearColor	(0,0,0,0);
		glClearColor((float)1/((float)256/(float)AppVars._R), (float)1/((float)256/(float)AppVars._G), (float)1/((float)256/(float)AppVars._B), 0.0f);
		glClear			(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}


	if (AppVars.bShowPolysAsDoubleSided && !AppVars.bForceWhite)
	{
		glDisable(GL_CULL_FACE);
	}
	else
	{
		glEnable(GL_CULL_FACE);	
	}
	
	if (bWireFrame)
	{
//		glDisable(GL_CULL_FACE);	
		glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
		glDisable(GL_LIGHTING);
	}
	else
	{
//		glEnable(GL_CULL_FACE);	
		glCullFace(GL_FRONT);
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// hitech: not this
		if (AppVars.bBilinear)
		{
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );	// ?
		}
		else
		{
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
		}

	}

	glColor3f		(1,1,1);
}
Exemple #24
0
void svClockGlyph::GenerateDisplay(float *x, float *y, int *index, int num,float R)
{
	glEnable( GL_LINE_SMOOTH );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        theList = glGenLists(1);
	if(theList==0)
	{
		glDeleteLists(theList, 1);
		theList = glGenLists(1);
	}
        glNewList(theList, GL_COMPILE);

	int i,j,k;
	int section;
	int size = glyphPos[0].size();
	svVector3 z1,z2;
	svVector3 draw,startp;
	svVector3 p;
	float bar;
	float angle,subangle;
	float radius=R/2.;
	float deltar=0.01;
	int round;
	float barlength=radius;
	float base;
	z1[0]=0.;z1[1]=0.;z1[2]=1.;
	z2[0]=0.;z2[1]=0.;z2[2]=-1.;

	glLineWidth(2.5);
	glPointSize(3);
	for(int jj=0;jj<num;jj++)
	{	
		i = index[jj];
		glColor3f(glyphColors[0][i][0],glyphColors[0][i][1],glyphColors[0][i][2]);
		glBegin(GL_LINE_STRIP);
		startp[0]=0;
		startp[1]=radius;
		startp[2]=glyphPos[0][i][2];
		angle = 2*PI*exp[i]/12.*(-1);//clockwise:positive
		section = fabs(exp[i]);
		round = section/13;
		for(k=0;k<=round;k++)
		{
			for(j=0;j<=section;j++)
			{		
				subangle = angle * j/ section;	
				p[0]=(startp[0]-deltar*k)*cos(subangle)-startp[1]*sin(subangle);
				p[1]=(startp[0]-deltar*k)*sin(subangle)+startp[1]*cos(subangle);
				p[2]=startp[2];
				glVertex2f(p[0]+x[jj],p[1]+y[jj]);
			}
			section=section-12;
		}
		glEnd();
			
		/*glColor3f(1.,1.,1.);
		base = (glyphMag[i]/maxMag) * radius;
		glBegin(GL_LINE_LOOP);
		glVertex2f(startp[0]+x[jj],startp[1]+y[jj]);
		glVertex2f(x[jj],y[jj]-base/2.);
		glVertex2f(x[jj],y[jj]+base/2.);
		glEnd();*/
		
		glColor3f(253./256.,212./256.,158./256.); //x
		p[0]=startp[0]*cos(thetax[i])-startp[1]*sin(thetax[i]);
		p[1]=startp[0]*sin(thetax[i])+startp[1]*cos(thetax[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(252./256.,141./256.,89./256.); //y	
		p[0]=startp[0]*cos(thetay[i])-startp[1]*sin(thetay[i]);
		p[1]=startp[0]*sin(thetay[i])+startp[1]*cos(thetay[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(215./256.,48./256.,31./256.); //z	
		p[0]=startp[0]*cos(thetaz[i])-startp[1]*sin(thetaz[i]);
		p[1]=startp[0]*sin(thetaz[i])+startp[1]*cos(thetaz[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(127./255.,0.,0.);
		//bar=startp[0]-coe[i]/10.*barlength;
		bar = coe[i]/10. * radius;
		glBegin(GL_LINES);
		//glVertex3f(startp[0]+glyphPos[0][i][0],startp[1]+glyphPos[0][i][1],startp[2]);
		glVertex2f(x[jj],y[jj]);
		glVertex2f(x[jj]-bar,y[jj]);
		glEnd();	

		i = i + glyphFrequency;
	}
	glLineWidth(1);
	glPointSize(1);

	glEndList();
}
void GraphicsContext3D::hint(GC3Denum target, GC3Denum mode)
{
    makeContextCurrent();
    glHint(target, mode);
}
Exemple #26
0
void svClockGlyph::RenderClock(float *x, float *y, int num,float R)
{
	glEnable( GL_LINE_SMOOTH );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	int i,j,k;
	int section;
	int size = glyphPos[0].size();
	svVector3 z1,z2;
	svVector3 draw,startp;
	svVector3 p;
	float bar;
	float angle,subangle;
	float rr ;
	if(R<=1)rr =R/4.;
	else rr=0.25;
	float radius=R/4.;
	float deltar=0.01;
	int round;
	float barlength=radius;
	float base;
	z1[0]=0.;z1[1]=0.;z1[2]=1.;
	z2[0]=0.;z2[1]=0.;z2[2]=-1.;


	glPointSize(3);
	for(int jj=0;jj<num;jj++)
	{	
		glLineWidth(2.5);
		i = jj;
		if(exp[i]!=0||coe[i]!=0)
		{
		if(exp[i]>=0)
			radius = exp[i]/maxexp * rr;
		else
			radius = fabs(exp[i])/maxexp * rr;
		glColor3f(glyphColors[0][i][0],glyphColors[0][i][1],glyphColors[0][i][2]);
		glBegin(GL_LINE_STRIP);
		startp[0]=0;
		startp[1]=radius;
		startp[2]=glyphPos[0][i][2];
		angle = 2*PI*exp[i]/maxexp*(-1);//clockwise:positive
		section = fabs(exp[i]);
		round = section/(maxexp+1);
		for(k=0;k<=round;k++)
		{
			for(j=0;j<=section;j++)
			{		
				subangle = angle * j/ section;	
				p[0]=startp[0]*cos(subangle)-(startp[1]-deltar*k)*sin(subangle);
				p[1]=startp[0]*sin(subangle)+(startp[1]-deltar*k)*cos(subangle);
				p[2]=startp[2];
				glVertex2f(p[0]+x[jj],p[1]+y[jj]);
			}
			section=section-12;
		}
		glEnd();
		glLineWidth(1);
	
		/*glColor3f(1.,1.,1.);
		base = (glyphMag[i]/maxMag) * radius;
		glBegin(GL_LINE_LOOP);
		glVertex2f(startp[0]+x[jj],startp[1]+y[jj]);
		glVertex2f(x[jj],y[jj]-base/2.);
		glVertex2f(x[jj],y[jj]+base/2.);
		glEnd();*/
		
		glColor3f(227./256.,26./256.,28./256.); //x
		p[0]=startp[0]*cos(thetax[i])-startp[1]*sin(thetax[i]);
		p[1]=startp[0]*sin(thetax[i])+startp[1]*cos(thetax[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(35./256.,139./256.,69./256.); //y	
		p[0]=startp[0]*cos(thetay[i])-startp[1]*sin(thetay[i]);
		p[1]=startp[0]*sin(thetay[i])+startp[1]*cos(thetay[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(33./256.,113./256.,181./256.); //z	
		p[0]=startp[0]*cos(thetaz[i])-startp[1]*sin(thetaz[i]);
		p[1]=startp[0]*sin(thetaz[i])+startp[1]*cos(thetaz[i]);
		p[2]=startp[2];
		glBegin(GL_LINES);
		glVertex2f(x[jj],y[jj]);	
		glVertex2f(p[0]+x[jj],p[1]+y[jj]);
		glEnd();

		glColor3f(127./255.,0.,0.);
		//bar=startp[0]-coe[i]/10.*barlength;
		bar = coe[i]/10. * radius;
		glBegin(GL_LINES);
		//glVertex3f(startp[0]+glyphPos[0][i][0],startp[1]+glyphPos[0][i][1],startp[2]);
		glVertex2f(x[jj],y[jj]);
		glVertex2f(x[jj],y[jj]+bar);
		glEnd();	
		}
		i = i + glyphFrequency;
	}

	glPointSize(1);
}
bool Renderer::initialize()
{
    const EGLint attribs[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_RED_SIZE, 8,
        EGL_NONE
    };
    EGLDisplay display;
    EGLConfig config;    
    EGLint numConfigs;
    EGLint format;
    EGLSurface surface;
    EGLContext context;
    EGLint width;
    EGLint height;
    GLfloat ratio;
    
    LOG_INFO("Initializing context");
    
    if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
        LOG_ERROR("eglGetDisplay() returned error %d", eglGetError());
        return false;
    }
    if (!eglInitialize(display, 0, 0)) {
        LOG_ERROR("eglInitialize() returned error %d", eglGetError());
        return false;
    }

    if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
        LOG_ERROR("eglChooseConfig() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
        LOG_ERROR("eglGetConfigAttrib() returned error %d", eglGetError());
        destroy();
        return false;
    }

    ANativeWindow_setBuffersGeometry(_window, 0, 0, format);

    if (!(surface = eglCreateWindowSurface(display, config, _window, 0))) {
        LOG_ERROR("eglCreateWindowSurface() returned error %d", eglGetError());
        destroy();
        return false;
    }
    
    if (!(context = eglCreateContext(display, config, 0, 0))) {
        LOG_ERROR("eglCreateContext() returned error %d", eglGetError());
        destroy();
        return false;
    }
    
    if (!eglMakeCurrent(display, surface, surface, context)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglQuerySurface(display, surface, EGL_WIDTH, &width) ||
        !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) {
        LOG_ERROR("eglQuerySurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    _display = display;
    _surface = surface;
    _context = context;

    glDisable(GL_DITHER);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glClearColor(0, 0, 0, 0);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    
    glViewport(0, 0, width, height);

    ratio = (GLfloat) width / height;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    return true;
}
void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glViewport(0,0,screen_width,screen_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,0.0f,100.0f);

    glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient);
    glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse);
    glLightfv (GL_LIGHT1, GL_DIFFUSE, light_specular);
    glLightfv (GL_LIGHT1, GL_POSITION, light_position);
    glEnable (GL_LIGHT1);
    glEnable (GL_LIGHTING);

    glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_specular);
    glMaterialfv (GL_FRONT, GL_POSITION, mat_shininess);

    glShadeModel(GL_SMOOTH);
    glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Texture mapping perspective correction (OpenGL... thank you so much!)
    glEnable(GL_TEXTURE_2D);                            // Texture mapping ON
    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);         // Polygon rasterization mode (polygon filled)
    glEnable(GL_CULL_FACE);                             // Enable the back face culling
    glEnable(GL_DEPTH_TEST);                            // Enable the depth test (also called z buffer)


    ObjLoad ("smokeSphereSmall.3ds","skull.bmp");



    GLfloat textureMapID = 510;
    GLuint  vboID        = 510;



//////////////////////////////////////////////////////_______GLOBALS_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////_______GLOBALS_______///////////////////////////////////////////////////////////

    system("MKDIR smokeSphereSmall");

    ofstream out_vboGlobals("smokeSphereSmall/smokeSphereSmall_vboGlobals.cpp");
    out_vboGlobals << "GLuint  smokeSphereSmall_vboID   =  " << vboID <<" ;"                               << "\n\n";
    out_vboGlobals << "GLuint  smokeSphereSmall_SHADER;"                                                   << "\n";
    out_vboGlobals << "GLuint  smokeSphereSmall_SHADER_Vertex;"                                            << "\n";
    out_vboGlobals << "GLuint  smokeSphereSmall_SHADER_Fragment;"                                          << "\n\n";

    out_vboGlobals << "#include \"smokeSphereSmall_VERT.cpp\""                                            << "\n";
    out_vboGlobals << "#include \"smokeSphereSmall_NORM.cpp\""                                            << "\n";
    out_vboGlobals << "#include \"smokeSphereSmall_TEX.cpp\""                                             << "\n";

    out_vboGlobals << "GLfloat lightPos_smokeSphereSmall[]               =  {0.132818, 30.1442, -4.0103};"<< "\n";
    out_vboGlobals << "GLfloat lightAttenuation_smokeSphereSmall         =   0.774731;"                   << "\n\n";
    out_vboGlobals << "GLfloat MaterialShininess_smokeSphereSmall        =  16.7859;"                     << "\n\n";

    out_vboGlobals << "GLfloat rotation_AXIS_smokeSphereSmall[]          =  {1.0, 1.0, 1.0};"             << "\n";
    out_vboGlobals << "GLfloat smokeSphereSmall_POSITION[]               =  {0.0, 0.0, 0.0};"             << "\n";

    out_vboGlobals << "GLfloat     smokeSphereSmall_counter              = 0;"                            << "\n";
    out_vboGlobals << "GLuint      UNIFORM_counter_smokeSphereSmall;"                                     << "\n\n";

    out_vboGlobals << "GLfloat     LightAmbient_smokeSphereSmall[]       = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     LightDiffuse_smokeSphereSmall[]       = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     LightSpecular_smokeSphereSmall[]      = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     MaterialAmbient_smokeSphereSmall[]    = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     MaterialDiffuse_smokeSphereSmall[]    = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     MaterialEmission_smokeSphereSmall[]   = { 1.0f, 1.0f, 1.0f, 1.0f};"    << "\n";
    out_vboGlobals << "GLfloat     MaterialSpecular_smokeSphereSmall[]   = { 0.0, 0, 0};"                 << "\n";


    out_vboGlobals << "GLfloat     scalesmokeSphereSmallShadowY[]            = {1.26801, 0.0, 1.26801};"  << "\n";
//////////////////////////////////////////////////////_______GLOBALS_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////_______GLOBALS_______///////////////////////////////////////////////////////////
    //---------------------------------------------
//////////////////////////////////////////////////////________INIT_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////________INIT_______///////////////////////////////////////////////////////////
    ofstream out_vboInit("smokeSphereSmall/smokeSphereSmall_vboInit.cpp");

    out_vboInit << "glGenBuffersARB(1, &smokeSphereSmall_vboID);" << "\n";
    out_vboInit << "glBindBufferARB(GL_ARRAY_BUFFER_ARB, smokeSphereSmall_vboID);" << "\n";
    out_vboInit << "glBufferDataARB(GL_ARRAY_BUFFER_ARB,       sizeof(smokeSphereSmall_VERT) + sizeof(smokeSphereSmall_NORM) + sizeof(smokeSphereSmall_TEX), 0, GL_STATIC_DRAW_ARB);" << "\n";
    out_vboInit << "glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(smokeSphereSmall_VERT), smokeSphereSmall_VERT);" << "\n";
    out_vboInit << "glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,    sizeof(smokeSphereSmall_VERT),  sizeof(smokeSphereSmall_NORM), smokeSphereSmall_NORM);" << "\n";
    out_vboInit << "glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,    sizeof(smokeSphereSmall_VERT) + sizeof(smokeSphereSmall_NORM), sizeof(smokeSphereSmall_TEX), smokeSphereSmall_TEX);" << "\n\n";

    out_vboInit << "    loadTexture(\"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall.jpg\",      textureMap[" << textureMapID << "]);"   << "\n";
    out_vboInit << "    loadTexture(\"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_DOT3.bmp\", normalMap[" << textureMapID << "]);" << "\n\n";
    out_vboInit << "    //loadTexture(\"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_BUMP.jpg\", specularMap[" << textureMapID << "]);"   << "\n";
//////////////////////////////////////////////////////________INIT_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////________INIT_______///////////////////////////////////////////////////////////
    //---------------------------------------------
/////////////////////////////////////////////////////_____SHADER_SETUP_____//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////_____SHADER_SETUP_____//////////////////////////////////////////////////////////
    ofstream out_SHADER_INIT("smokeSphereSmall/smokeSphereSmall_shaderInit.cpp");

    out_SHADER_INIT << "    const char *smokeSphereSmall_SHADER_VertexStrings[1];" << "\n";
    out_SHADER_INIT << "    const char *smokeSphereSmall_SHADER_FragmentStrings[1];" << "\n\n";

    out_SHADER_INIT << "    smokeSphereSmall_SHADER_Vertex = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );" << "\n\n";

    out_SHADER_INIT << "	 unsigned char *smokeSphereSmall_SHADER_VertexAssembly   = readShaderFile( \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall.vert\" );" << "\n";
    out_SHADER_INIT << "    smokeSphereSmall_SHADER_VertexStrings[0] = (char*)smokeSphereSmall_SHADER_VertexAssembly;" << "\n";
    out_SHADER_INIT << "    glShaderSourceARB( smokeSphereSmall_SHADER_Vertex, 1, smokeSphereSmall_SHADER_VertexStrings, NULL );" << "\n";
    out_SHADER_INIT << "    glCompileShaderARB( smokeSphereSmall_SHADER_Vertex);" << "\n";
    out_SHADER_INIT << "    delete smokeSphereSmall_SHADER_VertexAssembly;" << "\n\n";

    out_SHADER_INIT << "    smokeSphereSmall_SHADER_Fragment = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );" << "\n\n";

    out_SHADER_INIT << "    unsigned char *smokeSphereSmall_SHADER_FragmentAssembly = readShaderFile( \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall.frag\" );" << "\n";
    out_SHADER_INIT << "    smokeSphereSmall_SHADER_FragmentStrings[0] = (char*)smokeSphereSmall_SHADER_FragmentAssembly;" << "\n";
    out_SHADER_INIT << "    glShaderSourceARB( smokeSphereSmall_SHADER_Fragment, 1, smokeSphereSmall_SHADER_FragmentStrings, NULL );" << "\n";
    out_SHADER_INIT << "    glCompileShaderARB( smokeSphereSmall_SHADER_Fragment );" << "\n\n";

    out_SHADER_INIT << "    delete smokeSphereSmall_SHADER_FragmentAssembly;" << "\n\n";

    out_SHADER_INIT << "	 smokeSphereSmall_SHADER = glCreateProgramObjectARB();" << "\n\n";
    out_SHADER_INIT << "    glAttachObjectARB( smokeSphereSmall_SHADER, smokeSphereSmall_SHADER_Vertex );" << "\n";
    out_SHADER_INIT << "    glAttachObjectARB( smokeSphereSmall_SHADER, smokeSphereSmall_SHADER_Fragment );" << "\n\n";

    out_SHADER_INIT << "    glLinkProgramARB(smokeSphereSmall_SHADER); " << "\n\n";

    out_SHADER_INIT << "    UNIFORM_counter_smokeSphereSmall = glGetUniformLocationARB( smokeSphereSmall_SHADER, \"counter\" );" << "\n\n";

/////////////////////////////////////////////////////_____SHADER_SETUP_____//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////_____SHADER_SETUP_____//////////////////////////////////////////////////////////
    //---------------------------------------------
//////////////////////////////////////////////////////_______RENDER_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////_______RENDER_______///////////////////////////////////////////////////////////
    ofstream out_vboRender("smokeSphereSmall/smokeSphereSmall_vboRender.cpp");

    //out_vboRender << "          glPushMatrix();                                                                                      "                       << "\n";
    out_vboRender << "              glTranslatef(moveSet[0], moveSet[1], moveSet[2]);                                                "                       << "\n";
    out_vboRender << "              glTranslatef(smokeSphereSmall_POSITION[0], smokeSphereSmall_POSITION[1], smokeSphereSmall_POSITION[2]);"                       << "\n";
    out_vboRender << "              glRotatef(spinFloat,rotation_AXIS_smokeSphereSmall[0], rotation_AXIS_smokeSphereSmall[1], rotation_AXIS_smokeSphereSmall[2]);" << "\n\n";

    out_vboRender << "              glPushMatrix();"                                                                                                   << "\n";
    out_vboRender << "                   glLoadIdentity();"                                                                                            << "\n";
    out_vboRender << "                   //_ADDITIONAL_ROTATIONS_GO_HERE"                                                                              << "\n";
    out_vboRender << "                   glRotatef(-look_LEFT_RIGHT, 0, -1, 0);"                                                                       << "\n";
    out_vboRender << "                   glTranslatef(-eyePosition[0],-eyePosition[1],-eyePosition[2]);"                                               << "\n";
    out_vboRender << "                   glLightfv(GL_LIGHT0,GL_POSITION,lightPos_smokeSphereSmall);"                                                      << "\n";
    out_vboRender << "                   glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION, lightAttenuation_smokeSphereSmall);"                               << "\n";
    out_vboRender << "              glPopMatrix();"                                                                                                    << "\n\n";
    //out_vboRender << "          glPopMatrix();                                                                                      "                       << "\n";
    out_vboRender << "              glUseProgramObjectARB(smokeSphereSmall_SHADER);"                                                                       << "\n\n\n";
    out_vboRender << "              glBindBufferARB(GL_ARRAY_BUFFER_ARB, smokeSphereSmall_vboID);"                                                         << "\n\n\n";
    out_vboRender << "              glLightfv(GL_LIGHT0, GL_AMBIENT,     LightAmbient_smokeSphereSmall);"                                                  << "\n";
    out_vboRender << "              glLightfv(GL_LIGHT0, GL_DIFFUSE,     LightDiffuse_smokeSphereSmall);"                                                  << "\n";
    out_vboRender << "              glLightfv(GL_LIGHT0, GL_SPECULAR,    LightSpecular_smokeSphereSmall);"                                                 << "\n";
    out_vboRender << "              glMaterialfv(GL_FRONT, GL_AMBIENT,   MaterialAmbient_smokeSphereSmall);"                                               << "\n";
    out_vboRender << "              glMaterialfv(GL_FRONT, GL_DIFFUSE,   MaterialDiffuse_smokeSphereSmall);"                                               << "\n";
    out_vboRender << "              glMaterialfv(GL_FRONT, GL_EMISSION,  MaterialEmission_smokeSphereSmall);"                                              << "\n";
    out_vboRender << "              glMaterialfv(GL_FRONT, GL_SPECULAR,  MaterialSpecular_smokeSphereSmall);"                                              << "\n";
    out_vboRender << "              glMaterialf(GL_FRONT, GL_SHININESS,  MaterialShininess_smokeSphereSmall);"                                             << "\n\n";

    out_vboRender << "              glUniform1fARB( UNIFORM_counter_smokeSphereSmall, smokeSphereSmall_counter);"<< "\n\n";

    out_vboRender << "              glEnableClientState(GL_TEXTURE_COORD_ARRAY );"                                                                     << "\n";
    out_vboRender << "              glEnableClientState(GL_NORMAL_ARRAY);"                                                                             << "\n";
    out_vboRender << "              glEnableClientState(GL_VERTEX_ARRAY);"                                                                             << "\n";

    out_vboRender << "              glTexCoordPointer(3, GL_FLOAT, 0, (void*)(sizeof(smokeSphereSmall_VERT) + sizeof(smokeSphereSmall_NORM)));"          << "\n";
    out_vboRender << "              glNormalPointer(GL_FLOAT, 0, (void*)sizeof(smokeSphereSmall_VERT));"                                                << "\n";
    out_vboRender << "              glVertexPointer(3, GL_FLOAT, 0, 0);"                                                                               << "\n\n";


    out_vboRender << "              SHADOW_MAP_textureID;"                                                                                             << "\n";
    out_vboRender << "              SHADOW_MAP_textureID = glGetUniformLocationARB(treeBarkPath_SHADER,\"ShadowMap\");"                                << "\n";
    out_vboRender << "              glUniform1iARB(SHADOW_MAP_textureID, 2);"                                                                          << "\n";
    out_vboRender << "              glActiveTextureARB(GL_TEXTURE2_ARB);"                                                                               << "\n ";
    out_vboRender << "              glBindTexture(GL_TEXTURE_2D,  textureMap[299]);"                                                                    << "\n\n";


    out_vboRender << "              DOT3_textureID     = glGetUniformLocationARB(smokeSphereSmall_SHADER,\"NormalMap\");"                                << "\n";
    out_vboRender << "              glUniform1iARB(DOT3_textureID, 1);"                                                                                << "\n";
    out_vboRender << "              glActiveTextureARB(GL_TEXTURE1_ARB);"                                                                              << "\n";
    out_vboRender << "              glBindTexture(GL_TEXTURE_2D,  normalMap[" << textureMapID << "]);"                                                 << "\n\n";


    out_vboRender << "              textureID     = glGetUniformLocationARB(smokeSphereSmall_SHADER,\"Texture1\");"                                     << "\n";
    out_vboRender << "              glUniform1iARB(textureID, 0);"                                                                                     << "\n";
    out_vboRender << "              glActiveTextureARB(GL_TEXTURE0_ARB);"                                                                              << "\n";
    out_vboRender << "              glBindTexture(GL_TEXTURE_2D, textureMap[" << textureMapID << "]);"                                                 << "\n\n";

    out_vboRender << "              glDrawArrays(GL_TRIANGLES, 0, " << object.polygons_qty*3 << ");"                                                   << "\n\n";

    out_vboRender << "              glDisableClientState(GL_VERTEX_ARRAY);"                                                                            << "\n";
    out_vboRender << "              glDisableClientState(GL_NORMAL_ARRAY);"                                                                            << "\n";
    out_vboRender << "              glDisableClientState(GL_TEXTURE_COORD_ARRAY);"                                                                     << "\n\n";

    out_vboRender << "              glUseProgramObjectARB(0);"                                                                                         << "\n\n";
//////////////////////////////////////////////////////_______RENDER_______///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////_______RENDER_______///////////////////////////////////////////////////////////
    //---------------------------------------------
////////////////////////////////////////////////////_______VERTEX_SHADER______//////////////////////////////////////////////////////
////////////////////////////////////////////////////_______VERTEX_SHADER______//////////////////////////////////////////////////////
    ofstream out_vertexShader("smokeSphereSmall/smokeSphereSmall.vert");

    out_vertexShader << "              uniform float counter;"                                                                                         << "\n\n";

    out_vertexShader << "              varying vec4 position;"                                                                                         << "\n\n";

    out_vertexShader << "              varying vec3 lightDir1;"                                                                                         << "\n\n";

    out_vertexShader << "              varying float attenuation;"                                                                                         << "\n\n";

    out_vertexShader << "              uniform float textureDisplacement_X;"                                                                                         << "\n\n";
    out_vertexShader << "              uniform float textureDisplacement_Y;"                                                                                         << "\n\n";
    out_vertexShader << "              uniform float offset_X;"                                                                                         << "\n\n";
    out_vertexShader << "              uniform float offset_Y;"                                                                                         << "\n\n";

    out_vertexShader << "              void main( void )"                                                                                         << "\n\n";
    out_vertexShader << "              {"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_TexCoord[0]    = gl_MultiTexCoord0;"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_TexCoord[1]    = gl_MultiTexCoord0;"                                                                                         << "\n\n";

    out_vertexShader << "              //////////////----------------------------    "                                                                                         << "\n\n";

    out_vertexShader << "                  gl_TexCoord[1].x *= 0.2;//____________?_________0.2 FOR 2 METER TILES"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_TexCoord[1].y *= 0.2;"                                                                                         << "\n\n";

    out_vertexShader << "                  gl_TexCoord[1].x -= offset_X - .01;"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_TexCoord[1].y -= offset_Y - .01;    "                                                                                         << "\n\n";

    out_vertexShader << "                  gl_TexCoord[1].x -= textureDisplacement_X;"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_TexCoord[1].y -= textureDisplacement_Y;   "                                                                                         << "\n\n";
    out_vertexShader << "              //////////////----------------------------  "                                                                                         << "\n\n";

    out_vertexShader << "                  position         = gl_ModelViewProjectionMatrix * gl_Vertex;"                                                                                         << "\n\n";
    out_vertexShader << "                  gl_Position      = position;"                                                                                         << "\n\n";

    out_vertexShader << "                  lightDir1        =  normalize(gl_LightSource[0].position.xyz - position.xyz);"                                                                                         << "\n\n";
    out_vertexShader << "                  attenuation      =  1.00 / (gl_LightSource[0].quadraticAttenuation);"                                                                                         << "\n\n";
    out_vertexShader << "              }"                                                                                         << "\n\n";
////////////////////////////////////////////////////_______VERTEX_SHADER______//////////////////////////////////////////////////////
////////////////////////////////////////////////////_______VERTEX_SHADER______//////////////////////////////////////////////////////
    //---------------------------------------------
////////////////////////////////////////////////////_____FRAGMENT_SHADER_____//////////////////////////////////////////////////////
////////////////////////////////////////////////////_____FRAGMENT_SHADER_____//////////////////////////////////////////////////////
    ofstream out_fragmentShader("smokeSphereSmall/smokeSphereSmall.frag");

    out_fragmentShader << "uniform float counter;"                                 << "\n\n";

    out_fragmentShader << "varying vec4 position;"                                 << "\n\n";

    out_fragmentShader << "float distance;  "                                 << "\n\n";
    out_fragmentShader << "varying float attenuation;"                                 << "\n\n";

    out_fragmentShader << "vec4 finalcolor;"                                 << "\n\n";


    out_fragmentShader << "vec3 normal;"                                 << "\n\n";
    out_fragmentShader << "varying vec3 lightDir1;"                                 << "\n\n";

    out_fragmentShader << "float NdotL1;"                                 << "\n\n";

    out_fragmentShader << "uniform sampler2D Texture1;"                                 << "\n\n";
    out_fragmentShader << "uniform sampler2D Texture2;"                                 << "\n\n";
    out_fragmentShader << "uniform sampler2D NormalMap;"                                 << "\n\n";
    out_fragmentShader << "uniform sampler2D ShadowMap;"                                 << "\n\n";

    out_fragmentShader << "vec4 shadowTexture;"                                 << "\n\n";

    out_fragmentShader << "vec4 secondTexture;"                                 << "\n\n";



    out_fragmentShader << "void main( void )"                                 << "\n\n";
    out_fragmentShader << "{"                                                 << "\n\n";
    out_fragmentShader << "        //secondTexture                =   texture2D(Texture2,  gl_TexCoord[0].st);//__ADDS_A_SECOND_PRIMARY_TEXTURE_-->>THIS_HAS_THE_EFFECT_OF_BLENDING_VARIOUS_MODEL_COLORS"   << "\n";

    out_fragmentShader << "         shadowTexture                  =   texture2D(ShadowMap,  gl_TexCoord[1].st);"                                 << "\n\n";

    out_fragmentShader << "         //finalcolor                   =   texture2D(Texture1, gl_TexCoord[0].xy)*.5 + secondTexture*.5;//____ADDS_PRIMARY_TEXTURE_AND_SECOND_TEXTURE"                                 << "\n";
    out_fragmentShader << "         finalcolor                     =   texture2D(Texture1, gl_TexCoord[0].xy); "                                 << "\n\n";

    out_fragmentShader << "         vec3 NormalTex                 =   texture2D(NormalMap,  gl_TexCoord[0].st).xyz;"                                 << "\n";
    out_fragmentShader << "         NormalTex                      =  (NormalTex - 0.5) * 2.0;"                                 << "\n";
    out_fragmentShader << "         normal                         =   normalize(NormalTex);"                                 << "\n\n";

    out_fragmentShader << "         NdotL1                         =   dot(normal,lightDir1);"                                 << "\n\n";

    out_fragmentShader << "         if(NdotL1 > 0.0)"                                 << "\n";
    out_fragmentShader << "         {"                                 << "\n";
    out_fragmentShader << "                float specularLight       =   pow(NdotL1, gl_FrontMaterial.shininess);  "                                 << "\n";
    out_fragmentShader << "                finalcolor               +=  (finalcolor * specularLight) * shadowTexture;"                                 << "\n";
    out_fragmentShader << "         }    "                                 << "\n\n";

    out_fragmentShader << "         finalcolor                    *=   attenuation * NdotL1; "                                 << "\n\n";

    out_fragmentShader << "         shadowTexture                  =  (1.0 - shadowTexture) * 0.3; "                                 << "\n\n";

    out_fragmentShader << "         gl_FragColor                   =  (finalcolor - shadowTexture);"                                 << "\n\n";

    out_fragmentShader << "         }"                                 << "\n\n";
////////////////////////////////////////////////////_____FRAGMENT_SHADER_____//////////////////////////////////////////////////////
////////////////////////////////////////////////////_____FRAGMENT_SHADER_____//////////////////////////////////////////////////////
    //---------------------------------------------

    //---------------------------------------------
////////////////////////////////////////////////////_____LOCATION_STRINGS_____//////////////////////////////////////////////////////
////////////////////////////////////////////////////_____LOCATION_STRINGS_____//////////////////////////////////////////////////////
    ofstream out_LOCATION_STRINGS("smokeSphereSmall/_LOCATION_STRINGS.cpp");
    out_LOCATION_STRINGS << "                             #include \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_vboGlobals.cpp\"//vboID = " << "" << vboID <<"\n";
    out_LOCATION_STRINGS << "                             #include \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_vboRender.cpp\"//vboID = " << "" << vboID <<"\n";
    out_LOCATION_STRINGS << "                             #include \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_vboInit.cpp\" //vboID = " << "" << vboID <<"\n";
    out_LOCATION_STRINGS << "                             #include \"_MODEL_FOLDERS_/smokeSphereSmall/smokeSphereSmall_shaderInit.cpp\"//vboID = " << "" << vboID <<"\n";

////////////////////////////////////////////////////_____LOCATION_STRINGS_____//////////////////////////////////////////////////////
////////////////////////////////////////////////////_____LOCATION_STRINGS_____//////////////////////////////////////////////////////
}
Exemple #29
0
int CGraphics::InitAll() {
	GLuint PixelFormat; //Contiene el formato de pixel

	static PIXELFORMATDESCRIPTOR pfd= //Contiene la informacion del formato del pixel
	{
		sizeof(PIXELFORMATDESCRIPTOR), //Tamaño de este descriptor
			1,
			PFD_DRAW_TO_WINDOW | //Formato que soporte Windows
			PFD_SUPPORT_OPENGL | //Formato que soporte OpenGL
			PFD_DOUBLEBUFFER, //Soporta doble buffering
			PFD_TYPE_RGBA, //Peticion de un formato RGBA
			16, // Selecciona el color de la profundidad
			0, 0, 0, 0, 0, 0, //Bits de Color Ignorado
			0, // No Alpha Buffer
			0, // Shift Bit Ignorado
			0, // Buffer de no acumulacion
			0, 0, 0, 0, //Bits de acumulacion ignorados
			16, //16bit Z Buffer (Buffer de profundidad)
			0, //No Stencil Buffer
			0, //No Auxiliary Buffer
			PFD_MAIN_PLANE, //Capa principal de dibujo
			0, //Reservado
			0,0,0 //Mascaras de capa ignoradas
	};

	if (!(hDC=GetDC(GetHWND()))) { //Se obtuvo un contexto de dispositivo?
		MessageBox(NULL, L"It couldn't get window Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {//Windows encontro un formato de pixel similar?
		MessageBox(NULL, L"Non suitable pixel format found", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {//Se pudo iniciar el formato de pixel?
		MessageBox(NULL, L"It couldn't set pixel format", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!(hRC=wglCreateContext(hDC))) {//Conseguimos el contexto para renderear?
		MessageBox(NULL, L"It was not possible to create GL Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!wglMakeCurrent(hDC,hRC)) {//Intento de activar el contexto de rendering
		MessageBox(NULL, L"It was not possible to set current GL Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	GLfloat blanco[]= {1.0f,1.0f,1.0f,1.0f};
	//GLfloat LightPosition[]={220.0f,-200.0f,220.0f,1.0f};


	glEnable(GL_LINE_SMOOTH);
	glEnable (GL_LIGHTING);
	glEnable (GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	
	// Buffer de profundidad 
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST); //Habilida la prueba de profundidad
	
	glDepthFunc(GL_LEQUAL); // Tipo de prueba

	glEnable(GL_NORMALIZE);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Mejora la perspectiva

	glClearColor(1.0f, 1.0f, 1.0f, 0); //Pone el color del fondo a gris	

	glLightfv(GL_LIGHT0, GL_DIFFUSE, blanco);
	glEnable (GL_LIGHT0);

	Size();

	return 0;
}
Exemple #30
0
void WMO::draw(int doodadset, const Vec3D &ofs, const float rot, bool boundingbox, bool groupboxes, bool /*highlight*/) const
{
	if (gWorld && gWorld->drawfog)
		glEnable(GL_FOG);
	else
		glDisable(GL_FOG);

	for (unsigned int i = 0; i<nGroups; ++i)
	{
		groups[i].draw(ofs, rot, false);

		if (gWorld->drawdoodads)
		{
			groups[i].drawDoodads(doodadset, ofs, rot);
		}

		groups[i].drawLiquid();
	}

	if (boundingbox)
	{
		glDisable(GL_LIGHTING);

		glDisable(GL_COLOR_MATERIAL);
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for (unsigned int i = 0; i < nGroups; ++i)
			DrawABox(groups[i].BoundingBoxMin, groups[i].BoundingBoxMax, Vec4D(1.0f, 1.0f, 1.0f, 1.0f), 1.0f);

		DrawABox(Vec3D(extents[0].x, extents[0].z, -extents[0].y), Vec3D(extents[1].x, extents[1].z, -extents[1].y), Vec4D(1.0f, 0.0f, 0.0f, 1.0f), 2.0f);

		/*glColor4fv( Vec4D( 1.0f, 0.0f, 0.0f, 1.0f ) );
		glBegin( GL_LINES );
		glVertex3f( 0.0f, 0.0f, 0.0f );
		glVertex3f( this->header.BoundingBoxMax.x + header.BoundingBoxMax.x / 5.0f, 0.0f, 0.0f );
		glEnd();

		glColor4fv( Vec4D( 0.0f, 1.0f, 0.0f, 1.0f ) );
		glBegin( GL_LINES );
		glVertex3f( 0.0f, 0.0f, 0.0f );
		glVertex3f( 0.0f, header.BoundingBoxMax.z + header.BoundingBoxMax.z / 5.0f, 0.0f );
		glEnd();

		glColor4fv( Vec4D( 0.0f, 0.0f, 1.0f, 1.0f ) );
		glBegin( GL_LINES );
		glVertex3f( 0.0f, 0.0f, 0.0f );
		glVertex3f( 0.0f, 0.0f, header.BoundingBoxMax.y + header.BoundingBoxMax.y / 5.0f );
		glEnd();*/

		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);

		glEnable(GL_LIGHTING);

	}

	/*  {
	// draw boundingboxe and axis
	// Turn light off and highlight the following
	glDisable(GL_LIGHTING);
	glDisable(GL_COLOR_MATERIAL);
	glActiveTexture(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE1);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable (GL_LINE_SMOOTH);
	glLineWidth(1.0);
	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);

	glColor4f( 1, 1, 1, 1 );

	glLineWidth(1.0);
	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
	for (int i=0; i<nGroups; ++i)
	{
	WMOGroup &header = groups[i];
	/// Bounding box
	glColor4f( 1, 1, 1, 1 );
	glBegin( GL_LINE_STRIP );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMax.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMin.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMin.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMin.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMax.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMax.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMax.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMax.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMin.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMin.y, header.BoundingBoxMin.z );
	glEnd();

	glBegin( GL_LINES );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMin.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMin.y, header.BoundingBoxMax.z );
	glEnd();
	glBegin( GL_LINES );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMax.y, header.BoundingBoxMin.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMin.y, header.BoundingBoxMin.z );
	glEnd();
	glBegin( GL_LINES );
	glVertex3f( header.BoundingBoxMin.x, header.BoundingBoxMax.y, header.BoundingBoxMax.z );
	glVertex3f( header.BoundingBoxMax.x, header.BoundingBoxMax.y, header.BoundingBoxMax.z );
	glEnd();

	// draw axis
	glColor4fv( Vec4D( 1, 0, 0, 1 ) );
	glBegin( GL_LINES );
	glVertex3f( 0, 0, 0 );
	glVertex3f( header.BoundingBoxMax.x + 6, 0, 0 );
	glEnd();


	glColor4fv( Vec4D( 0, 1, 0, 1 ) );
	glBegin( GL_LINES );
	glVertex3f( 0, 0, 0 );
	glVertex3f( 0, header.BoundingBoxMax.y + 6, 0 );
	glEnd();

	glColor4fv( Vec4D( 0, 0, 1, 1 ) );
	glBegin( GL_LINES );
	glVertex3f( 0, 0, 0 );
	glVertex3f( 0, 0, header.BoundingBoxMax.x + 6 );
	glEnd();



	}
	// Back to normal light rendering
	glActiveTexture(GL_TEXTURE1);
	glDisable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHTING);
	} // end bounding  boxes.*/

	if (false && groupboxes)
	{
		//WIP STEFF
		// draw group boundingboxes
		// Turn light off and highlight the following
		glDisable(GL_LIGHTING);
		glDisable(GL_COLOR_MATERIAL);
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_LINE_SMOOTH);
		glLineWidth(1.0);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

		glColor4f(1, 1, 0, 1);

		glLineWidth(1.0);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		for (unsigned int i = 0; i<nGroups; ++i)
		{
			WMOGroup &header = groups[i];
			glBegin(GL_LINE_STRIP);
			//A
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMax.y, header.VertexBoxMin.z);
			//C
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMin.y, header.VertexBoxMin.z);
			//D
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMin.y, header.VertexBoxMin.z);
			//G
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMin.y, header.VertexBoxMax.z);
			//H
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMax.y, header.VertexBoxMax.z);
			//B
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMax.y, header.VertexBoxMin.z);
			//A
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMax.y, header.VertexBoxMin.z);
			//E
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMax.y, header.VertexBoxMax.z);
			//F
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMin.y, header.VertexBoxMax.z);
			//C
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMin.y, header.VertexBoxMin.z);
			glEnd();

			glBegin(GL_LINES);
			// F G
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMin.y, header.VertexBoxMax.z);
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMin.y, header.VertexBoxMax.z);
			glEnd();
			glBegin(GL_LINES);
			// B D
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMax.y, header.VertexBoxMin.z);
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMin.y, header.VertexBoxMin.z);
			glEnd();
			glBegin(GL_LINES);
			// E H
			glVertex3f(header.VertexBoxMin.x, header.VertexBoxMax.y, header.VertexBoxMax.z);
			glVertex3f(header.VertexBoxMax.x, header.VertexBoxMax.y, header.VertexBoxMax.z);
			glEnd();
		}
		// Back to normal light rendering
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_LIGHTING);
	} // end drow groupe boxes.





	/*
	// draw portal relations
	glBegin(GL_LINES);
	for (size_t i=0; i<prs.size(); ++i) {
	WMOPR &pr = prs[i];
	WMOPV &pv = pvs[pr.portal];
	if (pr.dir>0) glColor4f(1,0,0,1);
	else glColor4f(0,0,1,1);
	Vec3D pc = (pv.a+pv.b+pv.c+pv.d)*0.25f;
	Vec3D gc = (groups[pr.group].b1 + groups[pr.group].b2)*0.5f;
	glVertex3fv(pc);
	glVertex3fv(gc);
	}
	glEnd();
	glColor4f(1,1,1,1);
	// draw portals
	for (int i=0; i<nP; ++i) {
	glBegin(GL_LINE_STRIP);
	glVertex3fv(pvs[i].d);
	glVertex3fv(pvs[i].c);
	glVertex3fv(pvs[i].b);
	glVertex3fv(pvs[i].a);
	glEnd();
	}
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHTING);
	*/
}