コード例 #1
0
ファイル: splat.c プロジェクト: nikarul/splatgl
int Splat_Prepare(SDL_Window *userWindow, int userViewportWidth, int userViewportHeight) {
  int width, height;
  window = userWindow;
  viewportWidth = userViewportWidth;
  viewportHeight = userViewportHeight;
  SDL_GetWindowSize(userWindow, &width, &height);

  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);
  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);
  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);
  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 4);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

  window_glcontext = SDL_GL_CreateContext(window);
  if (!window_glcontext) {
    Splat_SetError("OpenGL context creation failed.  Check glGetError() and/or SDL_GetError() for more information.");
    Splat_Finish();
    return -1;
  }

  // Our shading model--Flat
  glShadeModel(GL_FLAT);

  // Default the clear color to black.
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

  // Setup our viewport.
  glViewport(0, 0, viewportWidth, viewportHeight);

  // Change to the projection matrix and set up our ortho view
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, width, 0, height);

  // Set up modelview for 2D integer coordinates
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0.375f, height + 0.375f, 0.0f);
  glScalef(1.0f, -1.0f, 0.001f); // Make the positive Z-axis point "out" from the view (e.g images at depth 4 will be higher than those at depth 0), and swap the Y axis

  /* Deactivate the system cursor */
  SDL_ShowCursor(SDL_DISABLE);

  glDisable(GL_DITHER);

  /* Create the frame buffer for rendering to texture*/
  glGenFramebuffers(1, &framebuffer);

  glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

  /* Set up the texture to which we're going to render */
  glGenTextures(1, &frameTexture);
  glBindTexture(GL_TEXTURE_2D, frameTexture);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, viewportWidth, viewportHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  /* Configure the framebuffer texture */
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, frameTexture, 0);
  GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
  glDrawBuffers(1, DrawBuffers);

  GLenum err = glGetError();
  if (err != GL_NO_ERROR) {
    Splat_SetError("OpenGL error occurred during initialization");
    Splat_Finish();
    return -1;
  }

  return 0;
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: 88er/tutorials
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// Give OpenGL our position,	then view,		then up vector
	gluLookAt(		0, 1.5f, 8,		0, 0.5f, 0,			0, 1, 0);
	
	// We want the model to rotate around the axis so we give it a rotation
	// value, then increase/decrease it. You can rotate right of left with the arrow keys.

	glRotatef(g_RotateX, 0, 1.0f, 0);						// Rotate the object around the Y-Axis
	g_RotateX += g_RotationSpeed;							// Increase the speed of rotation

	// I am going to attempt to explain what is going on below up here as not to clutter the 
	// code below.  We have a model that has a certain amount of objects and textures.  We want 
	// to go through each object in the model, bind it's texture map to it, then render it.
	// To render the current object, we go through all of it's faces (Polygons).  
	// What is a face you ask?  A face is just (in this case) a triangle of the object.
	// For instance, a cube has 12 faces because each side has 2 triangles.
	// You might be thinking.  Well, if there are 12 faces in a cube, that makes
	// 36 vertices that we needed to read in for that object.  Not really true.  Because
	// a lot of the vertices are the same, since they share sides, they only need to save
	// 8 vertices, and ignore the duplicates.  Then, you have an array of all the
	// unique vertices in that object.  No 2 vertices will be the same.  This cuts down
	// on memory.  Then, another array is saved, which is the index numbers for each face,
	// which index in to that array of vertices.  That might sound silly, but it is better
	// than saving tons of duplicate vertices.  The same thing happens for UV coordinates.
	// You don't save duplicate UV coordinates, you just save the unique ones, then an array
	// that index's into them.  This might be confusing, but most 3D files use this format.
	// This loop below will stay the same for most file formats that you load, so all you need
	// to change is the loading code.  You don't need to change this loop (Except for animation).

	// Since we know how many objects our model has, go through each of them.
	for(int i = 0; i < g_3DModel.numOfObjects; i++)
	{
		// Make sure we have valid objects just in case. (size() is in the vector class)
		if(g_3DModel.pObject.size() <= 0) break;

		// Get the current object that we are displaying
		t3DObject *pObject = &g_3DModel.pObject[i];
			
		// Check to see if this object has a texture map, if so bind the texture to it.
		if(pObject->bHasTexture) {

			// Turn on texture mapping and turn off color
			glEnable(GL_TEXTURE_2D);

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

			// Bind the texture map to the object by it's materialID
			glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
		} else {

			// Turn off texture mapping and turn on color
			glDisable(GL_TEXTURE_2D);

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

		// This determines if we are in wireframe or normal mode
		glBegin(g_ViewMode);					// Begin drawing with our selected mode (triangles or lines)

			// Go through all of the faces (polygons) of the object and draw them
			for(int j = 0; j < pObject->numOfFaces; j++)
			{
				// Go through each corner of the triangle and draw it.
				for(int whichVertex = 0; whichVertex < 3; whichVertex++)
				{
					// Get the index for each point of the face
					int index = pObject->pFaces[j].vertIndex[whichVertex];
			
					// Give OpenGL the normal for this vertex.
					glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
				
					// If the object has a texture associated with it, give it a texture coordinate.
					if(pObject->bHasTexture) {

						// Make sure there was a UVW map applied to the object or else it won't have tex coords.
						if(pObject->pTexVerts) {
							glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
						}
					} else {

						// Make sure there is a valid material/color assigned to this object.
						// You should always at least assign a material color to an object, 
						// but just in case we want to check the size of the material list.
						// if the size is at least one, and the material ID != -1,
						// then we have a valid material.
						if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) 
						{
							// Get and set the color that the object is, since it must not have a texture
							BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;

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

					// Pass in the current vertex of the object (Corner of current face)
					glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
				}
			}

		glEnd();								// End the drawing
	}


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
}
コード例 #3
0
void ofxSosoRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist) {
       
    
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
    
	float viewW = ofGetViewportWidth();
	float viewH = ofGetViewportHeight();
    
	float eyeX = viewW / 2;
	float eyeY = viewH / 2;
	float halfFov = PI * fov / 360;
	float theTan = tanf(halfFov);
	float dist = eyeY / theTan;
	float aspect = (float) viewW / viewH;
    
	if(nearDist == 0) nearDist = dist / 10.0f;
	if(farDist == 0) farDist = dist * 10.0f;
    
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fov, aspect, nearDist, farDist);
    
	//glMatrixMode(GL_MODELVIEW);       //from ofGLRenderer
	//glLoadIdentity();                 //from ofGLRenderer
	//gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0);  //from ofGLRenderer
    
    gluLookAt(0, 0, dist, 0, 0, 0, 0, 1, 0);    
    glMatrixMode(GL_MODELVIEW);      
	glLoadIdentity();                
    
	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	if(ofDoesHWOrientation()){
		if(vFlip){
			glScalef(1, -1, 1);
			glTranslatef(0, -height, 0);
		}
	}else{
		if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation();
		switch(orientation) {
			case OF_ORIENTATION_180:
				glRotatef(-180, 0, 0, 1);
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(-width, 0, 0);
				}else{
					glTranslatef(-width, -height, 0);
				}
                
				break;
                
			case OF_ORIENTATION_90_RIGHT:
				glRotatef(-90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;
                
			case OF_ORIENTATION_90_LEFT:
				glRotatef(90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
					glTranslatef(-width, -height, 0);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(-width, 0, 0);
				}
				break;
                
			case OF_ORIENTATION_DEFAULT:
			default:
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;
		}
	}
    
}
コード例 #4
0
ファイル: imgui_impl_sdl.cpp プロジェクト: xiedidan/SdlOsc
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
{
    // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
    ImGuiIO& io = ImGui::GetIO();
    int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
    int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
    if (fb_width == 0 || fb_height == 0)
        return;
    draw_data->ScaleClipRects(io.DisplayFramebufferScale);

    // We are using the OpenGL fixed pipeline to make the example code simpler to read!
    // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
    GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
    glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_SCISSOR_TEST);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnable(GL_TEXTURE_2D);
    //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context

    // Setup viewport, orthographic projection matrix
    glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    // Render command lists
    #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front();
        const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos)));
        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv)));
        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));

        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
                glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
                glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer);
            }
            idx_buffer += pcmd->ElemCount;
        }
    }
    #undef OFFSETOF

    // Restore modified state
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture);
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glPopAttrib();
    glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
}
コード例 #5
0
ファイル: ApplicationOverlay.cpp プロジェクト: dimentox/hifi
// Renders the overlays either to a texture or to the screen
void ApplicationOverlay::renderOverlay(bool renderToTexture) {
    PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()");
    Application* application = Application::getInstance();
    Overlays& overlays = application->getOverlays();
    GLCanvas* glWidget = application->getGLWidget();
    MyAvatar* myAvatar = application->getAvatar();
    
    _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize());
    _textureAspectRatio = (float)application->getGLWidget()->getDeviceWidth() / (float)application->getGLWidget()->getDeviceHeight();

    //Handle fading and deactivation/activation of UI
    if (Menu::getInstance()->isOptionChecked(MenuOption::UserInterface)) {
        _alpha += FADE_SPEED;
        if (_alpha > 1.0f) {
            _alpha = 1.0f;
        }
    } else {
        _alpha -= FADE_SPEED;
        if (_alpha <= 0.0f) {
            _alpha = 0.0f;
        }
    }

    // Render 2D overlay
    glMatrixMode(GL_PROJECTION);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (renderToTexture) {
        _overlays.buildFramebufferObject();
        _overlays.bind();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
    
    glPushMatrix(); {
        glLoadIdentity();
        gluOrtho2D(0, glWidget->width(), glWidget->height(), 0);
        
        renderAudioMeter();
        
        if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) {
            myAvatar->renderHeadMouse(glWidget->width(), glWidget->height());
        }
        
        renderStatsAndLogs();
        
        // give external parties a change to hook in
        emit application->renderingOverlay();
        
        overlays.render2D();
        
        renderPointers();
        
        renderDomainConnectionStatusBorder();
    } glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);

    if (renderToTexture) {
        _overlays.release();
    }
}
コード例 #6
0
ファイル: atlantis.c プロジェクト: davehorner/XScreenSaverWin
static void
Init(ModeInfo *mi)
{
	atlantisstruct *ap = &atlantis[MI_SCREEN(mi)];

	static const float ambient[]        = {0.1, 0.1, 0.1, 1.0};
	static const float diffuse[]        = {1.0, 1.0, 1.0, 1.0};
	static const float position[]       = {0.0, 1.0, 0.0, 0.0};
	static const float mat_shininess[]  = {90.0};
	static const float mat_specular[]   = {0.8, 0.8, 0.8, 1.0};
	static const float mat_diffuse[]    = {0.46, 0.66, 0.795, 1.0};
	static const float mat_ambient[]    = {0.0, 0.1, 0.2, 1.0};
	static const float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0};
	static const float lmodel_localviewer[] = {0.0};

	float        fblue = 0.0, fgreen;

	glFrontFace(GL_CCW);

        if (ap->wire)
          {
            glDisable(GL_DEPTH_TEST);
            glDisable(GL_CULL_FACE);
            glDisable(GL_LIGHTING);
            glDisable(GL_NORMALIZE);
          }
        else
          {
            glDepthFunc(GL_LEQUAL);
            glEnable(GL_DEPTH_TEST);
            glEnable(GL_CULL_FACE);
            glEnable(GL_NORMALIZE);
            glShadeModel(GL_SMOOTH);

            glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
            glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
            glLightfv(GL_LIGHT0, GL_POSITION, position);
            glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
            glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);

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

        if (ap->wire || !do_texture)
          {
            glDisable(GL_TEXTURE_2D);
          }
        else
          {
            GLfloat s_plane[] = { 1, 0, 0, 0 };
            GLfloat t_plane[] = { 0, 0, 1, 0 };
            GLfloat scale = 0.0005;

            if (!ap->texture)
              parse_image_data (mi);

            clear_gl_error();
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                         ap->texture->width, ap->texture->height, 0,
                         GL_RGBA, GL_UNSIGNED_BYTE,
                         ap->texture->data);
            check_gl_error("texture");

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

            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

            glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
            glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
            glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
            glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);

# ifndef HAVE_JWZGLES
            glEnable(GL_TEXTURE_GEN_S);
            glEnable(GL_TEXTURE_GEN_T);
# endif
            glEnable(GL_TEXTURE_2D);

            glMatrixMode(GL_TEXTURE);
            glLoadIdentity();
            glScalef(scale, scale, 1);
            glMatrixMode(GL_MODELVIEW);
          }

	InitFishs(ap);

	/* Add a little randomness */
	fblue = ((float) (NRAND(30)) / 100.0) + 0.70;
	fgreen = fblue * 0.56;
	glClearColor(0.0, fgreen, fblue, 1.0);
}
コード例 #7
0
ファイル: scene_resurt.cpp プロジェクト: gentlescreams/-
void scene_resurt_draw() {
	//画面分割の初期化
	glViewport(0, 0, width, height);


	/*塗られたパネルの枚数を%で保持*/
	float p = (float)panel_count_player / (float)(FIELD_SIZE*FIELD_SIZE) * 100.0f;
	int pp = p;

	char str[256];
	sprintf(str, "%d %%", pp);
	glMatrixMode(GL_PROJECTION);//GLenum mode
	glLoadIdentity();//射影行列の初期化
	glMatrixMode(GL_MODELVIEW);//GLenum mode	カメラの設定
	glLoadIdentity();//初期化
	setColor(TEAM_PLAYER_SHIP);
	glTranslatef(-.7, .5, 0);//x,y,z
	glScalef(0.00075, 0.00075, 0.00075);
	drawStroke("PLAYER1 TEAM:");
	glLoadIdentity();//初期化
	glTranslatef(.15, .5, 0);//x,y,z
	glScalef(0.00075, 0.00075, 0.00075);
	drawStroke(str);


	p = (float)panel_count_enemy / (float)(FIELD_SIZE*FIELD_SIZE) * 100.0f;
	pp = p;
	sprintf(str, "%d %%", pp);
	glLoadIdentity();//初期化
	setColor(TEAM_ENEMY_SHIP);
	glTranslatef(-.7, 0, 0);//x,y,z
	glScalef(0.00075, 0.00075, 0.00075);
	drawStroke("PLAYER2 TEAM:");
	glLoadIdentity();
	glTranslatef(.15, 0, 0);//x,y,z
	glScalef(0.00075, 0.00075, 0.00075);
	drawStroke(str);

	//プレイヤー2がプレイヤー1より塗った数が多かったら
	if (panel_count_enemy>panel_count_player)
	{
		glLoadIdentity();//初期化
		setColor(TEAM_ENEMY_SHIP);
		glTranslatef(0, -0.7, 0);//x,y,z
		glScalef(0.00075, 0.00075, 0.00075);
		drawStroke("PLAYER2 WIN!!!!");

	}//プレイヤー1がプレイヤー2より塗った数が多かったら
	else if (panel_count_player>panel_count_enemy)
	{
		glLoadIdentity();//初期化
		setColor(TEAM_PLAYER_SHIP);
		glTranslatef(0, -0.7, 0);//x,y,z
		glScalef(0.00075, 0.00075, 0.00075);
		drawStroke("PLAYER1 WIN!!!!");
	}

	glLoadIdentity();//初期化
	glColor3f(0, 1, 1);
	glTranslatef(0, -0.8, 0);//x,y,z
	glScalef(0.0005, 0.00055, 0.0005);
	drawStroke("push ENTER / BUTTON B");


}
コード例 #8
0
ファイル: widget.cpp プロジェクト: yidimu/3DFlightChess
void board::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -24.0);
    glRotatef(rotationX, 1.0, 0.0, 0.0);
    glRotatef(rotationY, 0.0, 1.0, 0.0);
    glRotatef(rotationZ, 0.0, 0.0, 1.0);
//------------------------------------------
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    bindTexture(QImage(":/image/modified.png"));
    glBegin(GL_QUADS);
          // Up face (y = 1.0f)
          qglColor(Qt::white);
          glTexCoord2f(0.0, 0.0);glVertex3f( 10.0f,  10.0f, 1.0f);
          glTexCoord2f(1.0, 0.0);glVertex3f(-10.0f,  10.0f, 1.0f);
          glTexCoord2f(1.0, 1.0);glVertex3f(-10.0f, -10.0f, 1.0f);
          glTexCoord2f(0.0, 1.0);glVertex3f( 10.0f, -10.0f, 1.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
          // Bottom face (y = 1.0f)
          qglColor(Qt::white);
          glVertex3f( 10.0f, -10.0f, -1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
          glVertex3f(-10.0f,  10.0f, -1.0f);
          glVertex3f( 10.0f,  10.0f, -1.0f);

          // Front face  (z = 1.0f)
          qglColor(QColor(200,76,70));
          glVertex3f( 10.0f, -10.0f,  1.0f);
          glVertex3f( 0.0f, -10.0f,  1.0f);
          glVertex3f( 0.0f, -10.0f, -1.0f);
          glVertex3f( 10.0f, -10.0f, -1.0f);
          qglColor(QColor(244,188,88));
          glVertex3f( 0.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
          glVertex3f( 0.0f, -10.0f, -1.0f);

          // Back face (z = -1.0f)
          qglColor(QColor(35,148,147));
          glVertex3f( 10.0f, 10.0f, -1.0f);
          glVertex3f( 0.0f, 10.0f, -1.0f);
          glVertex3f( 0.0f, 10.0f,  1.0f);
          glVertex3f( 10.0f, 10.0f,  1.0f);
          qglColor(QColor(163,189,110));
          glVertex3f( 0.0f, 10.0f, -1.0f);
          glVertex3f(-10.0f, 10.0f, -1.0f);
          glVertex3f(-10.0f, 10.0f,  1.0f);
          glVertex3f( 0.0f, 10.0f,  1.0f);

          // Right face (x = -1.0f)
          qglColor(QColor(35,148,147));
          glVertex3f(10.0f,  10.0f,  1.0f);
          glVertex3f(10.0f,  0.0f,  1.0f);
          glVertex3f(10.0f,  0.0f, -1.0f);
          glVertex3f(10.0f,  10.0f, -1.0f);
          qglColor(QColor(200,76,70));
          glVertex3f(10.0f,  0.0f,  1.0f);
          glVertex3f(10.0f, -10.0f,  1.0f);
          glVertex3f(10.0f, -10.0f, -1.0f);
          glVertex3f(10.0f,  0.0f, -1.0f);

          // Left face (x = 1.0f)
          qglColor(QColor(163,189,110));
          glVertex3f(-10.0f,  0.0f,  1.0f);
          glVertex3f(-10.0f,  10.0f,  1.0f);
          glVertex3f(-10.0f,  10.0f, -1.0f);
          glVertex3f(-10.0f,  0.0f, -1.0f);
          qglColor(QColor(244,188,88));
          glVertex3f(-10.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f,  0.0f,  1.0f);
          glVertex3f(-10.0f,  0.0f, -1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
       glEnd();  // End of drawing color-cube

}
コード例 #9
0
ファイル: water.c プロジェクト: xtmacbook/SGI
void init(char *filename) {
    GLfloat cloud_color[4] = { 1.f, 1.f, 1.f, 0.f, };
    GLfloat fog_color[4], fog_density = 0.05f, density, far_cull;
    unsigned *image;
    int width, height, components;
    if (filename) {
	image = read_texture(filename, &width, &height, &components);
	if (image == NULL) {
	    fprintf(stderr, "Error: Can't load image file \"%s\".\n",
		    filename);
	    exit(EXIT_FAILURE);
	} else {
	    printf("%d x %d image loaded\n", width, height);
	}
#if 0
	if (components != 3) {
	    printf("must be an rgb image\n");
	    exit(EXIT_FAILURE);
	}
#endif
	if (components < 3) rgb = 0;
    } else {
	int i, j;
	unsigned char *img;
	components = 4; width = height = 512;
	image = (unsigned *) malloc(width*height*sizeof(unsigned));
	img = (unsigned char *)image;
	for (j = 0; j < height; j++)
	    for (i = 0; i < width; i++) {
		int w2 = width/2, h2 = height/2;
		if (i & 32)
		    img[4*(i+j*width)+0] = 0xff;
		else
		    img[4*(i+j*width)+1] = 0xff;
		if (j&32)
		    img[4*(i+j*width)+2] = 0xff;
		if ((i-w2)*(i-w2) + (j-h2)*(j-h2) > 64*64 &&
		    (i-w2)*(i-w2) + (j-h2)*(j-h2) < 300*300) img[4*(i+j*width)+3] = 0xff;
	    }

    }
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, cloud_color);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexImage2D(GL_TEXTURE_2D, 0, components, width,
                 height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 image);
    glEnable(GL_TEXTURE_2D);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.,1.,.1,far_cull = 10.);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.,0.,-5.5);

    density = 1.- expf(-5.5 * fog_density * fog_density *
			      far_cull * far_cull);

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
    density = MAX(MIN(density, 1.), 0.);

    fog_color[0] = .23 + density *.57;
    fog_color[1] = .35 + density *.45;
    fog_color[2] = .78 + density *.22;

    glClearColor(fog_color[0], fog_color[1], fog_color[2], 1.f);

    glFogi(GL_FOG_MODE, GL_EXP2);
    glFogf(GL_FOG_DENSITY, fog_density);
    glFogfv(GL_FOG_COLOR, fog_color);
    if (fog_density > 0)
	glEnable(GL_FOG);
    glLineWidth(2.0f);
    glEnable(GL_LINE_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
コード例 #10
0
ファイル: logo.c プロジェクト: Distrotech/gtkglext
static gboolean
expose_event (GtkWidget      *widget,
	      GdkEventExpose *event,
	      gpointer        data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

  float d_quat[4];
  float m[4][4];

  if (animate)
    {

      if (counter == rot_count)
	{
	  if (rot_mode[++mode].axis == NULL)
	    mode = 0;
	  counter = 0;
	}

      axis_to_quat (rot_mode[mode].axis,
		    rot_mode[mode].sign * G_PI_2 / rot_count,
		    d_quat);
      add_quats (d_quat, logo_quat, logo_quat);

      counter++;

    }

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    return FALSE;

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glLoadIdentity ();

  /* View transformation. */
  glTranslatef (0.0, 0.0, -30.0);
  glScalef (view_scale, view_scale, view_scale);
  build_rotmatrix (m, view_quat);
  glMultMatrixf (&m[0][0]);

  /* Logo model. */
  glPushMatrix ();
    build_rotmatrix (m, logo_quat);
    glMultMatrixf (&m[0][0]);

    glRotatef (90.0, 1.0, 0.0, 0.0);
    glCallList (LOGO_CUBE);
    glCallList (LOGO_G_FORWARD);
    glCallList (LOGO_G_BACKWARD);
    glCallList (LOGO_T_FORWARD);
    glCallList (LOGO_T_BACKWARD);
    glCallList (LOGO_K_FORWARD);
    glCallList (LOGO_K_BACKWARD);
  glPopMatrix ();

  /* Swap buffers. */
  if (gdk_gl_drawable_is_double_buffered (gldrawable))
    gdk_gl_drawable_swap_buffers (gldrawable);
  else
    glFlush ();

  gdk_gl_drawable_gl_end (gldrawable);
  /*** OpenGL END ***/

  return TRUE;
}
コード例 #11
0
ファイル: tr_flares.c プロジェクト: Sixthly/Unvanquished
/*
==================
RB_RenderFlares

Because flares are simulating an occular effect, they should be drawn after
everything (all views) in the entire frame has been drawn.

Because of the way portals use the depth buffer to mark off areas, the
needed information would be lost after each view, so we are forced to draw
flares after each view.

The resulting artifact is that flares in mirrors or portals don't dim properly
when occluded by something in the main view, and portal flares that should
extend past the portal edge will be overwritten.
==================
*/
void RB_RenderFlares( void )
{
	flare_t  *f;
	flare_t  **prev;
	qboolean draw;

	if ( !r_flares->integer )
	{
		return;
	}

	// (SA) turned light flares back on.  must evaluate problem id had with this
	RB_AddDlightFlares();
	RB_AddCoronaFlares();

	// perform z buffer readback on each flare in this view
	draw = qfalse;
	prev = &r_activeFlares;

	while ( ( f = *prev ) != NULL )
	{
		// throw out any flares that weren't added last frame
		if ( f->addedFrame < backEnd.viewParms.frameCount - 1 )
		{
			*prev = f->next;
			f->next = r_inactiveFlares;
			r_inactiveFlares = f;
			continue;
		}

		// don't draw any here that aren't from this scene / portal
		f->drawIntensity = 0;

		if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum && f->inPortal == backEnd.viewParms.isPortal )
		{
			RB_TestFlare( f );

			if ( f->drawIntensity )
			{
				draw = qtrue;
			}
			else
			{
				// this flare has completely faded out, so remove it from the chain
				*prev = f->next;
				f->next = r_inactiveFlares;
				r_inactiveFlares = f;
				continue;
			}
		}

		prev = &f->next;
	}

	if ( !draw )
	{
		return; // none visible
	}

	if ( backEnd.viewParms.isPortal )
	{
		glDisable( GL_CLIP_PLANE0 );
	}

	glPushMatrix();
	glLoadIdentity();
	glMatrixMode( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();
	glOrtho( backEnd.viewParms.viewportX, backEnd.viewParms.viewportX + backEnd.viewParms.viewportWidth,
	         backEnd.viewParms.viewportY, backEnd.viewParms.viewportY + backEnd.viewParms.viewportHeight, -99999, 99999 );

	for ( f = r_activeFlares; f; f = f->next )
	{
		if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum && f->inPortal == backEnd.viewParms.isPortal && f->drawIntensity )
		{
			RB_RenderFlare( f );
		}
	}

	glPopMatrix();
	glMatrixMode( GL_MODELVIEW );
	glPopMatrix();
}
コード例 #12
0
ファイル: glutobj.c プロジェクト: ultimatedbz/tooncutter
void HelpDisplay(GLint ww, GLint wh)
{
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glColor3f(1.0f, 1.0f, 1.0f);


    /*  switch to projection mode */
    glMatrixMode(GL_PROJECTION);
    /*  save previous matrix which contains the  */
    /* settings for the perspective projection */
    glPushMatrix();
    /*  reset matrix */
    glLoadIdentity();
    /*  set a 2D orthographic projection */
    gluOrtho2D(0, ww, 0, wh);
    /*  invert the y axis, down is positive */
    glScalef(1, -1, 1);
    /*  mover the origin from the bottom left corner */
    /*  to the upper left corner */
    glTranslatef(0, -wh, 0);
    glMatrixMode(GL_MODELVIEW);


    glPushMatrix();
    glLoadIdentity();
    linestart = 10;

    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font, "Help Menu");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font, "---------");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "H/h = Toggle Help Menu");
    if (!full_screen)
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       "TAB = Activate Full Screen");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "Esc = Exits Program");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "R/r = Reset Position");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "C/c = Toggle Axis");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "W/w = Toggle Wireframe");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "D/d = Toggle Double Sided Polygons");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "S/s = Toggle Smooth Shading");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "M/m = Toggle Materials");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "T/t = Toggle Textures");
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "B/b = Toggle Auto Rotate");
    /* HelpRenderBitmapString(30,linestart+=linespace,(void *)Help_Font, "L/l = Toggle Line Smoothing");    */
#ifdef AVL
    HelpRenderBitmapString(30, linestart +=
			   linespace, Help_Font,
			   "F/f = Flip Textures");
#endif

    if (stereo) {
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       "Stereo Variables");
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       "----------------");
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       "</, = Decrease Eye Separation");
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       ">/. = Increase Eye Separation");
	HelpRenderBitmapString(30, linestart +=
			       linespace, Help_Font,
			       "+/- = Increase/Decrease Focus Distance");
    }

    glPopMatrix();

    /*  set the current matrix to GL_PROJECTION */
    glMatrixMode(GL_PROJECTION);
    /*  restore previous settings */
    glPopMatrix();
    /*  get back to GL_MODELVIEW matrix */
    glMatrixMode(GL_MODELVIEW);

    if (lighting)
	glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
}
コード例 #13
0
ファイル: glutobj.c プロジェクト: ultimatedbz/tooncutter
void Keyboard(unsigned char key, int x, int y)
{

    switch (key) {
    case 'h':
    case 'H':{
	    show_help = !show_help;
	    break;
	}
    case 'r':
    case 'R':{
	    int i;
	    /* Resetting Scene */
	    for (i = 0; i < 16; i++) {
		if (i == 0 || i == 5 || i == 10 || i == 15) {
		    _matrix[i] = 1;
		} else {
		    _matrix[i] = 0;
		}
	    }
	    prev_z = 0;
	    glLoadIdentity();
	    glMultMatrixd(_matrix);
	    getMatrix();
	    break;
	}
    case 'a':
    case 'A':{
	    show_axis = !show_axis;
	    break;
	}
    case 'b':
    case 'B':
	{
	    benchmark = !benchmark;
	    if (benchmark)
		glutIdleFunc(AutoSpin);
	    else
		glutIdleFunc(NULL);
	    break;
	}
    case 'x':
    case 'X':
	{
	    xrotate = !xrotate;
	    break;
	}
    case 'y':
    case 'Y':
	{
	    yrotate = !yrotate;
	    break;
	}
    case 'z':
    case 'Z':
	{
	    zrotate = !zrotate;
	    break;
	}

    case 'l':
    case 'L':
	lighting = !lighting;
	break;
#ifdef SMOOTH_HINT
    case 'l':
    case 'L':{
	    smooth_hint = !smooth_hint;
	    if (smooth_hint) {
		glEnable(GL_LINE_SMOOTH);
		/* glEnable (GL_POLYGON_SMOOTH); */
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		/* glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); */
	    } else {
		glDisable(GL_LINE_SMOOTH);
		/* glDisable (GL_POLYGON_SMOOTH); */
	    }
	    break;
	}
#endif				/* 0 */
    case 'w':
    case 'W':{
	    wireframe = !wireframe;
	    break;
	}
    case 'd':
    case 'D':{
	    two_sided = !two_sided;
	    break;
	}
    case 's':
    case 'S':{
	    smooth = !smooth;
	    break;
	}
    case 'm':
    case 'M':{
	    material = !material;
	    if (!material && textured)
		textured = 0;
	    break;
	}
    case 't':
    case 'T':{
	    textured = !textured;
	    if (!material && textured)
		material = 1;
	    break;
	}
#ifdef AVL
    case 'f':
    case 'F':{
	    glmFlipModelTextures(pmodel);
	    break;
	}
#endif
    case ',':
    case '<':{
	    EyeSep -= 0.025;
	    break;
	}
    case '.':
    case '>':{
	    EyeSep += 0.025;
	    break;
	}
    case '+':
    case '=':
	{
	    FocusZ -= 0.25;
	    break;
	}
    case '-':
    case '_':
	{
	    FocusZ += 0.25;
	    break;
	}
    case 9:
	{
	    if (!full_screen) {
		glutFullScreen();
		full_screen = 1;
	    }

	    break;
	}
    case 27:
	exit(0);
	break;
    default:{
	    break;
	}			/* flush all other input                                 */
    }
    glutPostRedisplay();	/* redisplay afterword */
}
コード例 #14
0
ファイル: glutobj.c プロジェクト: ultimatedbz/tooncutter
void Motion(int x, int y)
{
    bool changed = false;

    const int dx = x - _mouseX;
    const int dy = y - _mouseY;

    int viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);

    if (dx == 0 && dy == 0)
	return;

    if (_mouseMiddle || (_mouseLeft && _mouseRight)) {
	/* double s = exp((double)dy*0.01); */
	/* glScalef(s,s,s); */
	/* if(abs(prev_z) <= 1.0) */

	glLoadIdentity();
	glTranslatef(0, 0, dy * 0.01);
	glMultMatrixd(_matrix);



	changed = true;
    } else if (_mouseLeft) {
	double ax, ay, az;
	double bx, by, bz;
	double angle;

	ax = dy;
	ay = dx;
	az = 0.0;
	angle = vlen(ax, ay, az) / (double) (viewport[2] + 1) * 180.0;

	/* Use inverse matrix to determine local axis of rotation */

	bx = _matrixI[0] * ax + _matrixI[4] * ay + _matrixI[8] * az;
	by = _matrixI[1] * ax + _matrixI[5] * ay + _matrixI[9] * az;
	bz = _matrixI[2] * ax + _matrixI[6] * ay + _matrixI[10] * az;

	glRotatef(angle, bx, by, bz);

	changed = true;
    } else if (_mouseRight) {
	double px, py, pz;

	pos(&px, &py, &pz, x, y, viewport);

	glLoadIdentity();
	glTranslatef(px - _dragPosX, py - _dragPosY, pz - _dragPosZ);
	glMultMatrixd(_matrix);

	_dragPosX = px;
	_dragPosY = py;
	_dragPosZ = pz;

	changed = true;
    }

    _mouseX = x;
    _mouseY = y;

    if (changed) {
	getMatrix();
	glutPostRedisplay();
    }
}
コード例 #15
0
ファイル: render.c プロジェクト: kz04px/Bot_Project
void render_viewer(void* a)
{
  char String[256];
  char Temp[128];
  EnableOpenGL(viewer_display.hWnd, &viewer_display.hDC, &viewer_display.hRC);
  glClearColor(0.0, 0.0, 0.0, 0.0); // Black

  while(!viewer_display.quit)
  {
    if(viewer_display.display)
    {
      glViewport(0, 0, viewer_display.w, viewer_display.h);
      glClear(GL_COLOR_BUFFER_BIT);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      // draw viewing area
      if(viewer_display.world->selected >= 0)
      {
        glOrtho(-1.0/viewer_display.view_zoom, 1.0/viewer_display.view_zoom,
            -viewer_display.r/viewer_display.view_zoom, viewer_display.r/viewer_display.view_zoom,
            -1, 1);
        glTranslatef(-viewer_display.world->bots[viewer_display.world->selected].x, -viewer_display.world->bots[viewer_display.world->selected].y, 1.0);

        draw_Background(viewer_display.world);
        draw_pellets(viewer_display.world);
        draw_bots(viewer_display.world);
        glPopMatrix();

        static int count = 0;
        if(viewer_display.display_statistics && count%30 == 0)
        {
          int i;
          // display inputs
          sprintf(String, " Brain inputs:\r\n");
          for(i = 0; i < viewer_display.world->bots[viewer_display.world->selected].nn.layer_sizes[0]; ++i)
          {
            sprintf(Temp, "  %i: %.4g\r\n", i, viewer_display.world->bots[viewer_display.world->selected].nn.input[0][i]);
            strcat(String, Temp);
          }
          // display outputs
          sprintf(Temp, " Brain outputs:\r\n");
          strcat(String, Temp);
          for(i = 0; i < viewer_display.world->bots[viewer_display.world->selected].nn.layer_sizes[2]; ++i)
          {
            sprintf(Temp, "  %i: %.4g\r\n", i, viewer_display.world->bots[viewer_display.world->selected].nn.output[2][i]);
            strcat(String, Temp);
          }
          /*
          sprintf(String, " s_bot: %i\r\n", viewer_display.world->selected);
          sprintf(Temp, " age: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].age);
          strcat(String, Temp);
          sprintf(Temp, " energy: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].energy);
          strcat(String, Temp);
          sprintf(Temp, " dead: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].dead);
          strcat(String, Temp);

          // position & rotation
          sprintf(Temp, " x: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].x);
          strcat(String, Temp);
          sprintf(Temp, " y: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].y);
          strcat(String, Temp);
          sprintf(Temp, " r: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].r);
          strcat(String, Temp);

          // eyes
          sprintf(Temp, " eyes: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].num_eyes);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_blue);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_blue);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_blue);
          strcat(String, Temp);

          // Body colour
          sprintf(Temp, " Colour:\r\n");
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].red);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].green);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].blue);
          strcat(String, Temp);
          */

          SetWindowText(viewer_display.hstatistics, String);
        }
        count++;
      }
      SwapBuffers(viewer_display.hDC);
    }
    Sleep(20);
  }
  DisableOpenGL(viewer_display.hWnd, viewer_display.hDC, viewer_display.hRC);
}
コード例 #16
0
ファイル: hello.c プロジェクト: flyfy1/LanguageLearn
void init(void){
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
コード例 #17
0
ファイル: GameCore.cpp プロジェクト: chuaigm/collection
//////////////////////////////////////////////////////////////////////////
// 游戏结束
void CGameCore::GameOver( DWORD inc )
{

	//////////////////////////////////////////////////////////////////////////
	// 单人模式
	if (1 == g_MenuStateMain)
	{
		// 计算得分
		TTscore = timeFlash*100+300.0*excellentNum;

		// 记录高分
		switch(g_MenuStateSub)
		{
		case 1:		// 常规游戏
			if (timeFlash > HIGHtime[g_MenuStateSub])
			{
				HIGHtime[g_MenuStateSub] = timeFlash;
			}
			if (excellentNum > HIGHexce[g_MenuStateSub])
			{
				HIGHexce[g_MenuStateSub] = excellentNum;
			}
			if (TTscore > HIGHscore[g_MenuStateSub])
			{
				HIGHscore[g_MenuStateSub] = TTscore;
			}
			break;
		case 2:		// 高速模式
			if (timeFlash > HIGHtime[g_MenuStateSub])
			{
				HIGHtime[g_MenuStateSub] = timeFlash;
			}
			if (excellentNum > HIGHexce[g_MenuStateSub])
			{
				HIGHexce[g_MenuStateSub] = excellentNum;
			}
			if (TTscore > HIGHscore[g_MenuStateSub])
			{
				HIGHscore[g_MenuStateSub] = TTscore;
			}
			break;
		case 3:		// 多弹模式
			if (timeFlash > HIGHtime[g_MenuStateSub])
			{
				HIGHtime[g_MenuStateSub] = timeFlash;
			}
			if (excellentNum > HIGHexce[g_MenuStateSub])
			{
				HIGHexce[g_MenuStateSub] = excellentNum;
			}
			if (TTscore > HIGHscore[g_MenuStateSub])
			{
				HIGHscore[g_MenuStateSub] = TTscore;
			}
			break;
		}

		glColor3f(1,1,1);
		// 画出游戏模式
		g_myModel.TextureSquareTGA(0,5,0,6,2,g_MenuStateSub+5);
		// 按回车开始游戏
		g_myModel.TextureSquareTGA(0,1.5,0,9,1,20);
		// 时间
		g_myModel.TextureSquareTGA(-2.2,-1.5,0,1.3,0.7,21);
		// 绝妙
		g_myModel.TextureSquareTGA(0.5,-1.5,0,1.3,0.7,22);
		// 得分
		g_myModel.TextureSquareTGA(3.0,-1.5,0,1.3,0.7,23);
		// 本次
		g_myModel.TextureSquareTGA(-4.5,-2.65,0,1.3,0.7,24);

		if (g_MenuStateSub != 4 && g_MenuStateSub != 5)
		{
			// 最高
			g_myModel.TextureSquareTGA(-4.5,-3.9,0,1.3,0.7,26);
		}

		glMatrixMode(GL_PROJECTION);	

		glPushMatrix();								
		glLoadIdentity();						
		glOrtho(0,g_Width,0,g_Height,-1,1);				// 设置为正投影
		glMatrixMode(GL_MODELVIEW);						

		glColor3f(0.0,1.0,0.0);
		// 当前时间
		g_myModel.glPrint(g_Width*300/800, g_Height*190/600,"%.2f",timeFlash);
		// 当前绝妙
		g_myModel.glPrint(g_Width*410/800, g_Height*190/600,"%d",excellentNum);
		// 当前总分
		g_myModel.glPrint(g_Width*490/800, g_Height*190/600,"%d",TTscore);
		// 低难度模式没有记录
		if (g_MenuStateSub != 4 && g_MenuStateSub != 5)
		{
			// 最高时间
			g_myModel.glPrint(g_Width*300/800, g_Height*140/600,"%.2f",HIGHtime[g_MenuStateSub]);
			// 最高绝妙
			g_myModel.glPrint(g_Width*410/800, g_Height*140/600,"%d",HIGHexce[g_MenuStateSub]);
			// 最高总分
			g_myModel.glPrint(g_Width*490/800, g_Height*140/600,"%d",HIGHscore[g_MenuStateSub]);
		}

		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	//////////////////////////////////////////////////////////////////////////
	// 双人游戏
	if (2 == g_MenuStateMain)
	{
		// 画出游戏模式
		g_myModel.TextureSquareTGA(0,6,0,6,2,g_MenuStateSub+10);
		// 按回车开始游戏
		g_myModel.TextureSquareTGA(0,-2.5,0,8,0.7,20);
		// 时间
		g_myModel.TextureSquareTGA(-0.5,-4.5,0,1.3,0.7,21);
		// 绝妙 玩家1
		g_myModel.TextureSquareTGA(-6,-3.5,0,1.3,0.7,22);
		// 绝妙 玩家2
		g_myModel.TextureSquareTGA(6,-3.5,0,1.3,0.7,22);

		switch(win)
		{
		case 0:
			// 平局
			g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 29);
			g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 29);
			break;
		case 1:
			// 玩家1 胜
			g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 28);
			g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 27);
			break;
		case 2:
			// 玩家2 胜
			g_myModel.TextureSquareTGA(-6, 2, 0, 5.5, 5.5, 27);
			g_myModel.TextureSquareTGA( 6, 2, 0, 5.5, 5.5, 28);
			break;
		}
	}
	

	// 开始游戏
	if ( KEY_UP(13) || KEY_UP(32) )
	{
		gameOver = false;
		InitGame();
	}
	// 返回上级菜单
	if (KEY_UP(27))
	{
		g_GameState = 1;
		initGame = false;
	}
}
コード例 #18
0
void runintro()
{
	char temp[60];

	int a;
	switch(titlestage)
	{
	case 0:
		songintro.Init("voice.mp3");
		songintro.PlaySong();
		titlestage++;
	break;
	case 1:
		if(textcount<255)
			textcount++;
		
		glDisable(GL_TEXTURE_2D);
		
		glLoadIdentity();
		glTranslated(0,0,8);

		glClearColor((float)textcount/255,(float)textcount/255,(float)textcount/255,0.5f);
		glColor3f(255-(float)textcount/255,255-(float)textcount/255,255-(float)textcount/255);
				
		sprintf(temp, "First, there was nothing");
		glRasterPos2d(490-(strlen(temp)*10)/2,374);
		b1.glPrint(temp);

		a=songintro.GetPosition();

		if(a>=235000)
		{
			glClearColor(1.0f,1.0f,1.0f,0.5f);
			titlestage++;
		}

		glEnable(GL_TEXTURE_2D);

	break;
	case 2:
		glBindTexture(GL_TEXTURE_2D, textures[PONO_ANI_1].texID);
		
		glLoadIdentity();
		glTranslated(512,ponoy,8);
		if(ponoy<500)
			ponoy+=5;
		else
			titlestage++;

		glRotatef(730-(float)ponoy+50,0.0f,0.0f,1.0f);

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,0.99f); glVertex3d(-64,-64, 0);
			glTexCoord2f(0.99f,0.99f); glVertex3d( 64,-64, 0);
			glTexCoord2f(0.99f,0.0f); glVertex3d( 64, 64, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
		glEnd();
	break;
	case 3:
		glBindTexture(GL_TEXTURE_2D, textures[PONO_ANI_1].texID);
		
		glLoadIdentity();
		glTranslated(1000-ponoy,500,8);
		if(ponoy<780)
			ponoy+=5;
		else
		{
			titlestage++;
			substage=0;
			jpjy=950;
			ponox=1000-ponoy;
		}

		glRotatef(730-(float)ponoy+50,0.0f,0.0f,1.0f);

		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,0.99f); glVertex3d(-64,-64, 0);
			glTexCoord2f(0.99f,0.99f); glVertex3d( 64,-64, 0);
			glTexCoord2f(0.99f,0.0f); glVertex3d( 64, 64, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
		glEnd();
	break;
	case 4:
		switch(substage)
		{
		case 0:
			if(jpjy>460)
				jpjy-=3;
			else
			{
				substage++;
				shot.LoadSong("shot.mp3");
				shot.PlaySong();
				shotx=850;
				ponoy=0;
			}
			glBindTexture(GL_TEXTURE_2D, textures[PONO_ANI_1].texID);
			
			glLoadIdentity();
			glTranslated(ponox,500,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d(-64,-64, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d( 64,-64, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d( 64, 64, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
			glEnd();

			glBindTexture(GL_TEXTURE_2D, textures[JACK_JUMPING].texID);
			
			glLoadIdentity();
			glTranslated(850,jpjy,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d( 100,-100, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d(-100,-100, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d(-100, 100, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d( 100, 100, 0);
			glEnd();
		break;
		case 1:

			if(shotx>430)
			{
				ponox+=2;
				shotx-=5;
				if(ponox%3==0)
					ponoy=1;
				else
					ponoy=0;
			}
			else
			{
				substage++;
				shot.LoadSong("ponohit.mp3");
				shot.PlaySong();
			}

			glBindTexture(GL_TEXTURE_2D, textures[14+(ponoy)].texID);
			
			glLoadIdentity();
			glTranslated(ponox,500,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d( 64,-64, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d(-64,-64, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d(-64, 64, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d( 64, 64, 0);
			glEnd();

			glBindTexture(GL_TEXTURE_2D, textures[JACK].texID);
			
			glLoadIdentity();
			glTranslated(850,460,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d( 100,-100, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d(-100,-100, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d(-100, 100, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d( 100, 100, 0);
			glEnd();

			glBindTexture(GL_TEXTURE_2D, textures[BULLET_1].texID);
			
			glLoadIdentity();
			glTranslated(shotx,460,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d( 30,-15, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d(-30,-15, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d(-30, 15, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d( 30, 15, 0);
			glEnd();
		break;
		case 2:
			if(jpjy>-100)
				jpjy-=4;
			else
			{
				titlestage++;
				songintro.LoadSong("trill.mp3");
				substage=0;
			}

			if(jpjy>360)
			{
				glBindTexture(GL_TEXTURE_2D, textures[POW].texID);
				
				glLoadIdentity();
				glTranslated(ponox,500,8);
				
				glBegin(GL_QUADS);
					glTexCoord2f(0.0f,0.99f); glVertex3d(-64,-64, 0);
					glTexCoord2f(0.99f,0.99f); glVertex3d( 64,-64, 0);
					glTexCoord2f(0.99f,0.0f); glVertex3d( 64, 64, 0);
					glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
				glEnd();
			}

			glBindTexture(GL_TEXTURE_2D, textures[JACK_JUMPING].texID);
			
			glLoadIdentity();
			glTranslated(850,jpjy,8);
			
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.99f); glVertex3d( 100,-100, 0);
				glTexCoord2f(0.99f,0.99f); glVertex3d(-100,-100, 0);
				glTexCoord2f(0.99f,0.0f); glVertex3d(-100, 100, 0);
				glTexCoord2f(0.0f,0.0f); glVertex3d( 100, 100, 0);
			glEnd();
		break;

		}
	break;
	case 5:
		if(titlesize<1000)
		{
			titlesize+=titlevel;
			titlevel+=0.01f;
		}
		else
		{
			titlestage++;
			BGMusic.Init("theme.mp3");
			BGMusic.PlaySong();
			BGMusic.Repeat(2);
			shot.LoadSong("beep.mp3");
			ms=0;

			xpos=xpos2=xpos3=xpos1=0;
			character.xtile=0;
		}

		if(titlesize>=10 && titlesize<=13)
			songintro.PlaySong();
		
		glBindTexture(GL_TEXTURE_2D, textures[TITLE].texID);
		
		glLoadIdentity();									// Reset The Current Modelview Matrix
		
		glTranslated(512,384,2);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-titlesize,-titlesize*0.75f, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( titlesize,-titlesize*0.75f, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( titlesize, titlesize*0.75f, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-titlesize, titlesize*0.75f, 0);
		glEnd();
	break;
	case 6:

		m1.testmovement();
		DrawGLScene();

		xpos+=bounce*3;
		xpos1+=bounce*3;
		xpos2+=bounce*2;
		xpos3+=bounce;
		
		if(xpos1<-512)
		{
			character.xtile++;
			xpos1=512;
		}
		if(xpos1>512)
		{
			character.xtile--;
			xpos1=-512;
		}
		
		if(character.xtile<0)
			character.xtile=0;
		
		if(xpos3<-512)
			xpos3=512;
		if(xpos3>512)
			xpos3=-512;
		
		if(xpos2<-512)
			xpos2=512;
		if(xpos2>512)
			xpos2=-512;

		if(character.xtile>=11 && bounce==-1)
			bounce=1;

		if(character.xtile<0 && bounce==1)
			bounce=-1;

		glDisable(GL_TEXTURE_2D);

		glLoadIdentity();
		glTranslated(0,0,8);
		
		glColor3f(1.0,0.0f,0.0f);
		
		sprintf(temp, "JetPack Jack");
		glRasterPos2d(490-(strlen(temp)*10)/2,20);
		b1.glPrint(temp);

		sprintf(temp, "©2003 IVGDA");
		glRasterPos2d(490-(strlen(temp)*10)/2,700);
		b1.glPrint(temp);

		sprintf(temp, "JetPack Jack was created by Jeff Verkoeyen and Josh Rodasti");
		glRasterPos2d(490-(strlen(temp)*10)/2,730);
		b1.glPrint(temp);

		if(substage==0)
		{
			if(ms==0)
				glColor3f(0.0f,1.0f,0.0f);
			
			sprintf(temp, "Start Playing");
			glRasterPos2d(490-(strlen(temp)*10)/2,200);
			b1.glPrint(temp);
			
			glColor3f(1.0,0.0f,0.0f);
			
			if(ms==1)
				glColor3f(0.0f,1.0f,0.0f);
			
			sprintf(temp, "Options");
			glRasterPos2d(490-(strlen(temp)*10)/2,230);
			b1.glPrint(temp);
			
			glColor3f(1.0,0.0f,0.0f);
			
			if(ms==2)
				glColor3f(0.0f,1.0f,0.0f);
			
			sprintf(temp, "Mutagens");
			glRasterPos2d(490-(strlen(temp)*10)/2,260);
			b1.glPrint(temp);
			
			glColor3f(1.0,0.0f,0.0f);	
			
			if(ms==3)
				glColor3f(0.0f,1.0f,0.0f);
			
			sprintf(temp, "About");
			glRasterPos2d(490-(strlen(temp)*10)/2,290);
			b1.glPrint(temp);
			
			glColor3f(1.0,0.0f,0.0f);
			
			if(ms==4)
				glColor3f(0.0f,1.0f,0.0f);
			
			sprintf(temp, "Quit");
			glRasterPos2d(490-(strlen(temp)*10)/2,320);
			b1.glPrint(temp);
			
			glColor3f(1.0,0.0f,0.0f);
			
			if(keys[VK_UP])
			{
				ms--;
				keys[VK_UP]=false;
				shot.PlaySong();
			}
			if(keys[VK_DOWN])
			{
				ms++;
				keys[VK_DOWN]=false;
				shot.PlaySong();
			}
			if(ms<0)
				ms=4;
			if(ms>4)
				ms=0;
			
			if(keys[VK_RETURN] && ms==0)
			{
				intro=false;
				initialize();
				glColor3f(1.0f,1.0f,1.0f);
				glClearColor(1.0f,1.0f,1.0f,0.5f);
				xpos=xpos1=xpos2=xpos3=0;
				character.xtile=0;
			}

			if(keys[VK_RETURN] && ms==3)
			{
				substage=1;
				keys[VK_RETURN]=false;
			}
			
			if(keys[VK_RETURN] && ms==4)
				done=true;
			
		}

		if(substage==1)
		{
			glRasterPos2d(10,50);
			b1.glPrint("Jeff: Lead Programmer, has been programming C++ for 6 months, and OpenGL for 3");
			glRasterPos2d(10,80);
			b1.glPrint("months. He has made many games for the computer, in both DOS and OpenGL.  He");
			glRasterPos2d(10,110);
			b1.glPrint("also spent 8th through 9th grade making games on the calculator, and still");
			glRasterPos2d(10,140);
			b1.glPrint("does make an occasional math program.");


			glRasterPos2d(10,180);
			b1.glPrint("Josh: Lead Artist/Musician, enjoys spending all allocated time in his room on");

			glRasterPos2d(10,210);
			b1.glPrint("his computer either making music or playing games. He also frequently gets");

			glRasterPos2d(10,240);
			b1.glPrint("caught in class doodling on his assignments, (JetPack Jack's birth) and");

			glRasterPos2d(10,270);
			b1.glPrint("listening to his own cds.");


			glRasterPos2d(10,310);
			b1.glPrint("IVGDA: at www.ragingflame.150M.com, you can find links and special sneak previews");

			glRasterPos2d(10,340);
			b1.glPrint("to our new ideas, games, and etc. Check out the bios of the IVGDA team members,");

			glRasterPos2d(10,370);
			b1.glPrint("and download tutorials, games, demos, and also find career info.");

			if(keys[VK_RETURN] && ms==3)
			{
				substage=0;
				keys[VK_RETURN]=false;
			}
		}

		glEnable(GL_TEXTURE_2D);
	break;
	}
}
コード例 #19
0
void updateCamera() {

	float m_ele = 0;
	float m_azi=0;

	btVector3 m_cameraPosition(12,20,12);
	btVector3 m_cameraTargetPosition(0,10,0);

	btVector3 m_cameraUp(0,1,0);
	int m_forwardAxis=2;
	btScalar m_cameraDistance = 130;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();


	float m_frustumZNear=1;
	float m_frustumZFar=1000;

	if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0)
		return;

	float aspect;
	btVector3 extents;

	if (m_glutScreenWidth > m_glutScreenHeight) 
	{
		aspect = m_glutScreenWidth / (float)m_glutScreenHeight;
		extents.setValue(aspect * 1.0f, 1.0f,0);
	} else 
	{
		aspect = m_glutScreenHeight / (float)m_glutScreenWidth;
		extents.setValue(1.0f, aspect*1.f,0);
	}


	if (m_ortho)
	{
		// reset matrix
		glLoadIdentity();
		extents *= m_cameraDistance;
		btVector3 lower = m_cameraTargetPosition - extents;
		btVector3 upper = m_cameraTargetPosition + extents;
		glOrtho(lower.getX(), upper.getX(), lower.getY(), upper.getY(),-1000,1000);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
	} else
	{
		if (m_glutScreenWidth > m_glutScreenHeight) 
		{
			glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
		} else 
		{
			glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
		}
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2], 
			m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2], 
			m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
	}

}
コード例 #20
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{

	/*

	**********************************************************
	
	  table of who gets what in JetPack Jack
	  this just maps out which objects are viewed first, etc.

	  CHARACTER			8
	  AMMO METER		7
	  FOREGROUND		6
	  MIDDLEGROUND		4
	  BACKGROUND		2
	  SUN				1

	**********************************************************

	*/

	//		SUN

	glBindTexture(GL_TEXTURE_2D, textures[SUN].texID);

	glLoadIdentity();
		
	glTranslated(900,128,1);

	glRotatef(sunrot,0.0f,0.0f,1.0f);

	sunrot+=0.2f;
		
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3d(-64,-64, 0);
		glTexCoord2f(1.0f,1.0f); glVertex3d( 64,-64, 0);
		glTexCoord2f(1.0f,0.0f); glVertex3d( 64, 64, 0);
		glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
	glEnd();

	//		END SUN


	//		ALL GROUNDS START

	//		BACKGROUND

	glBindTexture(GL_TEXTURE_2D, textures[SKY].texID);

	for(int a=(int)xpos3-2048;a<xpos3+2048;a+=1024)
	{
		
		glLoadIdentity();
		
		glTranslated(a,128,2);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-128, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-128, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 128, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 128, 0);
		glEnd();
		
	}


	//		MIDDLEGROUND

	glBindTexture(GL_TEXTURE_2D, textures[MOUNTAINS].texID);

	for(int a=(int)xpos2-2048;a<xpos2+2048;a+=1024)
	{
		
		glLoadIdentity();
		
		glTranslated(a,475,4);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-200, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-200, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 200, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 200, 0);
		glEnd();
		
	}


	//		FOREGROUND

	for(int a=(int)xpos1-2048;a<xpos1+2048;a+=1024)
	{

		glBindTexture(GL_TEXTURE_2D, textures[GROUND].texID);

		glLoadIdentity();
		
		glTranslated(a,704,6);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-64, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-64, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 64, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 64, 0);
		glEnd();
		
	}

	//		ALL GROUNDS END


	//		AMMO METER

	glBindTexture(GL_TEXTURE_2D, textures[character.currentgun+7].texID);

	glLoadIdentity();
	
	glTranslated(10,30,7);

	for(int a=0;a<character.currentshots;a++)
	{
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(0,-15, 0);
			glTexCoord2f((100-(float)weapons.regen[a])/100,1.0f); glVertex3d( ((100-(float)weapons.regen[a])/100)*40,-15, 0);
			glTexCoord2f((100-(float)weapons.regen[a])/100,0.0f); glVertex3d( ((100-(float)weapons.regen[a])/100)*40, 15, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(0, 15, 0);
		glEnd();

		glTranslated(40,0,0);
		
	}

	//		END AMMO METER


	//		LIFE METER

	glDisable(GL_TEXTURE_2D);

	glLoadIdentity();
	
	glTranslated(10,60,7);

	glBegin(GL_QUADS);
		glVertex3d( 1,  -15, 0);
		glVertex3d( 101,-15, 0);
		glVertex3d( 101, 15, 0);
		glVertex3d( 1,   15, 0);
	glEnd();

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, textures[BAR].texID);

	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3d( 1,					-15, 1);
		glTexCoord2f(1.0f,1.0f); glVertex3d( character.life+1,	-15, 1);
		glTexCoord2f(1.0f,0.0f); glVertex3d( character.life+1,	 15, 1);
		glTexCoord2f(0.0f,0.0f); glVertex3d( 1,					 15, 1);
	glEnd();

	glPolygonMode(GL_BACK,GL_LINE);
	glPolygonMode(GL_FRONT,GL_LINE);

	glBegin(GL_QUADS);
		glColor3f(0.0f,0.0f,0.0f);
		glVertex3d( 0,  -16, 0);
		glVertex3d( 102,-16, 0);
		glVertex3d( 102, 16, 0);
		glVertex3d( 0,   16, 0);
	glEnd();

	glPolygonMode(GL_BACK,GL_FILL);
	glPolygonMode(GL_FRONT,GL_FILL);

	glColor3f(1.0f,1.0f,1.0f);

/*
	glDisable(GL_TEXTURE_2D);

	glLoadIdentity();
	glTranslated(0,0,8);
	glColor3f(1.0,0.0f,0.0f);
	glRasterPos2d(0,30);
	b1.glPrint("rightpress %d",rightpress);
	glColor3f(1.0,1.0f,1.0f);

	glEnable(GL_TEXTURE_2D);
*/
	return TRUE;										// Keep Going
}
コード例 #21
0
void TransIcelandicExpress::redraw( void ) {	

	static tex_init = 0;	

	
	if (!tex_init) {		

		ilutRenderer( ILUT_OPENGL );

		ilGenImages( 1, &ImageName );

		ilBindImage( ImageName );
		glEnable( GL_TEXTURE_2D );
		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
		if (!ilLoadImage( "ludum48.png" )) {
			printf("Loading image failed\n");
		}

		
		gl_tex_id = ilutGLBindTexImage();
		ilutGLTexImage( 0 );

		tex_init = 1;
	} 

	glBindTexture (GL_TEXTURE_2D, gl_tex_id );

	glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	//glEnable( GL_CULL_FACE );
	glEnable( GL_DEPTH_TEST );

	// 3d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 60.0, 800.0/600.0, 0.05, 100.0 );



	gluLookAt(	player->pos[0]+cameraPos[0], 
				player->pos[1]+cameraPos[1]+c_PlayerHeight, 
				player->pos[2]+cameraPos[2],

				player->pos[0], 
				player->pos[1]+ c_PlayerHeight, 
				player->pos[2],

				0.0, 1.0, 0.0 );
				

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	// apply some of the camera xform to the light just to make
	// it more shiny
	glPushMatrix();
	float viewHead = atan2( cameraPos[2], cameraPos[0] );	
	glRotated( viewHead * SG_RADIANS_TO_DEGREES, 0.0f, 1.0f, 0.0f );
	setupLights();
	glPopMatrix();

	draw3d();

	// 2d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();	
	gluOrtho2D( 0, 800, 0, 600 ) ;

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_LIGHTING );
	draw2d();

	SDL_GL_SwapBuffers();

}
コード例 #22
0
void drawmenu()
{
	
	glDisable(GL_TEXTURE_2D);
	
	glLoadIdentity();
	glTranslated(0,0,8);
	
	glColor3f(1.0,0.0f,0.0f);

	char temp[50];

	sprintf(temp, "JetPack Jack");
	glRasterPos2d(490-(strlen(temp)*10)/2,100);
	b1.glPrint(temp);

	sprintf(temp, "By Jeff Verkoeyen and Josh Rodasti");
	glRasterPos2d(490-(strlen(temp)*10)/2,550);
	b1.glPrint(temp);

	sprintf(temp, "A Production of IVGDA");
	glRasterPos2d(490-(strlen(temp)*10)/2,590);
	b1.glPrint(temp);

	sprintf(temp, "Is the game running too slow or too fast?");
	glRasterPos2d(490-(strlen(temp)*10)/2,40);
	b1.glPrint(temp);

	sprintf(temp, "Remember to check out the INIT.DAT file to change the game settings");
	glRasterPos2d(490-(strlen(temp)*10)/2,63);
	b1.glPrint(temp);

	glRasterPos2d(10,35);
	b1.glPrint(winname);
	
	if(keys[VK_RETURN] && !rpress)
		rpress=rvar=TRUE;
	if(!keys[VK_RETURN])
		rpress=FALSE;

	if(keys[VK_UP] || keys[VK_DOWN] || rvar)
		shot.PlaySong();
	
	if(menuset==0)
	{
		
		if(keys[VK_UP])
		{
			menuselection--;
			keys[VK_UP]=FALSE;
		}
		if(keys[VK_DOWN])
		{
			menuselection++;
			keys[VK_DOWN]=FALSE;
		}

		if(menuselection==0)
			menuselection=3;

		if(menuselection==4)
			menuselection=1;
		
		glColor3f(0.0,0.0f,1.0f);

		if(menuselection==1)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar)
			{
				menuset=1;
				rvar=FALSE;
			}
		}
		
		sprintf(temp, "Stats");
		glRasterPos2d(490-(strlen(temp)*10)/2,200);
		b1.glPrint(temp);

		glColor3f(0.0,0.0f,1.0f);

		if(menuselection==2)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar)
			{
				menuset=2;
				rvar=FALSE;
				menuselection=1;
			}
		}
		
		sprintf(temp, "Options");
		glRasterPos2d(490-(strlen(temp)*10)/2,250);
		b1.glPrint(temp);

		glColor3f(0.0f,0.0f,1.0f);

		if(menuselection==3)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar)
				done=TRUE;
		}

		sprintf(temp, "Quit");
		glRasterPos2d(490-(strlen(temp)*10)/2,500);
		b1.glPrint(temp);

	}
	else if(menuset==1)
	{

		int accuracy;

		if(character.total!=0)
			accuracy=(int)(float(character.hits)/float(character.total)*100);
		else
			accuracy=0;

		glColor3f(0.0f,0.0f,1.0f);

		sprintf(temp, "Accuracy %d",accuracy);
		strcat(temp,"%%");
		glRasterPos2d(490-(strlen(temp)*10)/2,200);
		b1.glPrint(temp);

		sprintf(temp, "Health %d/100",character.life);
		glRasterPos2d(490-(strlen(temp)*10)/2,250);
		b1.glPrint(temp);

		sprintf(temp, "Max Ammo %d",character.maxshots);
		glRasterPos2d(477-(strlen(temp)*10)/2,300);
		b1.glPrint(temp);
		
		glColor3f(0.0,1.0f,0.0f);

		if(rpress && rvar)
		{
			menuset=0;
			rvar=FALSE;
		}

		sprintf(temp, "Back");
		glRasterPos2d(490-(strlen(temp)*10)/2,500);
		b1.glPrint(temp);
		
	}
	else if(menuset==2)
	{
		
		if(keys[VK_UP])
		{
			menuselection--;
			keys[VK_UP]=FALSE;
			if(res!=oldres || fullres!=oldfullres)
			{
				if(res!=oldres)
					oldres=res;
				if(fullres!=oldfullres)
					oldfullres=fullres;
				b1.KillGLWindow();
				b1.CreateGLWindow(winname,resset[0] [res],resset[1] [res],resset[2] [res],(bool)!fullres);
			}
		}
		if(keys[VK_DOWN])
		{
			menuselection++;
			keys[VK_DOWN]=FALSE;
			if(res!=oldres || fullres!=oldfullres)
			{
				if(res!=oldres)
					oldres=res;
				if(fullres!=oldfullres)
					oldfullres=fullres;
				b1.KillGLWindow();
				b1.CreateGLWindow(winname,resset[0] [res],resset[1] [res],resset[2] [res],(bool)!fullres);
			}
		}

		if(menuselection==0)
			menuselection=3;

		if(menuselection==4)
			menuselection=1;
		
		glColor3f(0.0,0.0f,1.0f);

		if(menuselection==1)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar && res!=oldres)
			{
				rvar=FALSE;
				oldres=res;
				b1.KillGLWindow();
				b1.CreateGLWindow(winname,resset[0] [res],resset[1] [res],resset[2] [res],(bool)!fullres);
			}
			if(keys[VK_RIGHT] && res<5)
			{
				shot.PlaySong();
				res++;
				keys[VK_RIGHT]=FALSE;
			}
			if(keys[VK_LEFT] && res>0)
			{
				shot.PlaySong();
				res--;
				keys[VK_LEFT]=FALSE;
			}
		}
		
		sprintf(temp, "Resolution: %dx%d %d",resset[0] [res],resset[1] [res],resset[2] [res]);
		glRasterPos2d(490-(strlen(temp)*10)/2,200);
		b1.glPrint(temp);
		
		glColor3f(0.0,0.0f,1.0f);

		if(menuselection==2)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar && fullres!=oldfullres)
			{
				rvar=FALSE;
				oldfullres=fullres;
				b1.KillGLWindow();
				b1.CreateGLWindow(winname,resset[0] [res],resset[1] [res],resset[2] [res],(bool)!fullres);
			}
			if(keys[VK_RIGHT] && fullres<1)
			{
				shot.PlaySong();
				fullres++;
				keys[VK_RIGHT]=FALSE;
			}
			if(keys[VK_LEFT] && fullres>0)
			{
				shot.PlaySong();
				fullres--;
				keys[VK_LEFT]=FALSE;
			}
		}
		
		sprintf(temp, "%s",full[fullres]);
		glRasterPos2d(490-(strlen(temp)*10)/2,250);
		b1.glPrint(temp);

		glColor3f(0.0f,0.0f,1.0f);

		if(menuselection==3)
		{
			glColor3f(0.0,1.0f,0.0f);
			if(rpress && rvar)
			{
				menuset=0;
				rvar=FALSE;
				res=oldres;
				fullres=oldfullres;
				menuselection=1;
			}
		}

		sprintf(temp, "Back");
		glRasterPos2d(490-(strlen(temp)*10)/2,500);
		b1.glPrint(temp);

	}

//	glPolygonMode(GL_BACK,GL_LINE);
//	glPolygonMode(GL_FRONT,GL_LINE);

	glColor3f(1.0,1.0f,1.0f);

	glEnable(GL_TEXTURE_2D);

}
コード例 #23
0
void CMiniMap::Draw()
{
	PROFILE("minimap");

	// The terrain isn't actually initialized until the map is loaded, which
	// happens when the game is started, so abort until then.
	if(!(GetGUI() && g_Game && g_Game->IsGameStarted()))
		return;

	CSimulation2* sim = g_Game->GetSimulation2();
	CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
	ENSURE(!cmpRangeManager.null());

	// Set our globals in case they hadn't been set before
	m_Camera      = g_Game->GetView()->GetCamera();
	m_Terrain     = g_Game->GetWorld()->GetTerrain();
	m_Width  = (u32)(m_CachedActualSize.right - m_CachedActualSize.left);
	m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top);
	m_MapSize = m_Terrain->GetVerticesPerSide();
	m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize);
	m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f);

	if(!m_TerrainTexture || g_GameRestarted)
		CreateTextures();


	// only update 2x / second
	// (note: since units only move a few pixels per second on the minimap,
	// we can get away with infrequent updates; this is slow)
	static double last_time;
	const double cur_time = timer_Time();
	if(cur_time - last_time > 0.5)
	{
		last_time = cur_time;

		if(m_TerrainDirty)
			RebuildTerrainTexture();
	}

	const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
	const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top;
	const float z = GetBufferedZ();
	const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize;
	const float angle = GetAngle();

	// Draw the main textured quad
	g_Renderer.BindTexture(0, m_TerrainTexture);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	DrawTexture(texCoordMax, angle, x, y, x2, y2, z);

	/* // TODO: reimplement with new sim system
	// Shade territories by player
	CTerritoryManager* territoryMgr = g_Game->GetWorld()->GetTerritoryManager();
	std::vector<CTerritory*>& territories = territoryMgr->GetTerritories();

	PROFILE_START("minimap territory shade");
	
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for( size_t i=0; i<territories.size(); i++ )
	{
		if( territories[i]->owner->GetPlayerID() == 0 )
			continue;
		std::vector<CVector2D>& boundary = territories[i]->boundary;
		SPlayerColour col = territories[i]->owner->GetColour();
		glColor4f(col.r, col.g, col.b, 0.25f);
		glBegin(GL_POLYGON);
		for( size_t j=0; j<boundary.size(); j++ )
		{
			float fx = boundary[j].x / (m_Terrain->GetTilesPerSide() * CELL_SIZE);
			float fy = boundary[j].y / (m_Terrain->GetTilesPerSide() * CELL_SIZE);
			glVertex3f( x*(1-fx) + x2*fx, y*(1-fy) + y2*fy, z );
		}
		glEnd();
	}
	glDisable(GL_BLEND);

	PROFILE_END("minimap territory shade");

	// Draw territory boundaries
	glEnable(GL_LINE_SMOOTH);
	glLineWidth(1.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f(0.8f, 0.8f, 0.8f, 0.8f);
	for( size_t i=0; i<territories.size(); i++ )
	{
		std::vector<CVector2D>& boundary = territories[i]->boundary;
		glBegin(GL_LINE_LOOP);
		for( size_t j=0; j<boundary.size(); j++ )
		{
			float fx = boundary[j].x / (m_Terrain->GetTilesPerSide() * CELL_SIZE);
			float fy = boundary[j].y / (m_Terrain->GetTilesPerSide() * CELL_SIZE);
			glVertex3f( x*(1-fx) + x2*fx, y*(1-fy) + y2*fy, z );
		}
		glEnd();
	}
	glLineWidth(1.0f);
	glDisable(GL_LINE_SMOOTH);
	glDisable(GL_BLEND);
	*/

	// Draw the LOS quad in black, using alpha values from the LOS texture
	CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture();
	losTexture.BindTexture(0);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor3f(0.0f, 0.0f, 0.0f);

	glMatrixMode(GL_TEXTURE);
	glLoadMatrixf(losTexture.GetMinimapTextureMatrix());
	glMatrixMode(GL_MODELVIEW);

	DrawTexture(1.0f, angle, x, y, x2, y2, z);

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glDisable(GL_BLEND);

	// Set up the matrix for drawing points and lines
	glPushMatrix();
	glTranslatef(x, y, z);
	// Rotate around the center of the map
	glTranslatef((x2-x)/2.f, (y2-y)/2.f, 0.f);
	// Scale square maps to fit in circular minimap area
	float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f);
	glScalef(unitScale, unitScale, 1.f);
	glRotatef(angle * 180.f/M_PI, 0.f, 0.f, 1.f);
	glTranslatef(-(x2-x)/2.f, -(y2-y)/2.f, 0.f);

	PROFILE_START("minimap units");

	// Don't enable GL_POINT_SMOOTH because it's far too slow
	// (~70msec/frame on a GF4 rendering a thousand points)
	glPointSize(3.f);

	float sx = (float)m_Width / ((m_MapSize - 1) * CELL_SIZE);
	float sy = (float)m_Height / ((m_MapSize - 1) * CELL_SIZE);

	CSimulation2::InterfaceList ents = sim->GetEntitiesWithInterface(IID_Minimap);

	std::vector<MinimapUnitVertex> vertexArray;
	vertexArray.reserve(ents.size());

	for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
	{
		MinimapUnitVertex v;
		ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
		entity_pos_t posX, posZ;
		if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
		{
			ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetPlayerID());
			if (vis != ICmpRangeManager::VIS_HIDDEN)
			{
				v.a = 255;
				v.x = posX.ToFloat()*sx;
				v.y = -posZ.ToFloat()*sy;
				vertexArray.push_back(v);
			}
		}
	}

	if (!vertexArray.empty())
	{
		glInterleavedArrays(GL_C4UB_V2F, sizeof(MinimapUnitVertex), &vertexArray[0]);
		glDrawArrays(GL_POINTS, 0, (GLsizei)vertexArray.size());

		glDisableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);
	}

	PROFILE_END("minimap units");

	DrawViewRect();

	glPopMatrix();

	// Reset everything back to normal
	glPointSize(1.0f);
	glEnable(GL_TEXTURE_2D);
}
コード例 #24
0
ファイル: ors_opengl.cpp プロジェクト: ipa-nhg/kukadu
/// GL routine to draw a ors::KinematicWorld
void ors::KinematicWorld::glDraw() {
  uint i=0;
  ors::Transformation f;
  double GLmatrix[16];

  glPushMatrix();

  //bodies
  if(orsDrawBodies) for(Shape *s: shapes) {
    glDrawShape(s);
    i++;
    if(orsDrawLimit && i>=orsDrawLimit) break;
  }

  //joints
  if(orsDrawJoints) for(Joint *e: joints) {
    //set name (for OpenGL selection)
    glPushName((e->index <<2) | 2);

    double s=e->A.pos.length()+e->B.pos.length(); //some scale
    s*=.25;

    //from body to joint
    f=e->from->X;
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glColor(1, 1, 0);
    //glDrawSphere(.1*s);
    glBegin(GL_LINES);
    glVertex3f(0, 0, 0);
    glVertex3f(e->A.pos.x, e->A.pos.y, e->A.pos.z);
    glEnd();

    //joint frame A
    f.appendTransformation(e->A);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawAxes(s);
    glColor(1, 0, 0);
    glRotatef(90, 0, 1, 0);  glDrawCylinder(.05*s, .3*s);  glRotatef(-90, 0, 1, 0);

    //joint frame B
    f.appendTransformation(e->Q);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawAxes(s);

    //from joint to body
    glColor(1, 0, 1);
    glBegin(GL_LINES);
    glVertex3f(0, 0, 0);
    glVertex3f(e->B.pos.x, e->B.pos.y, e->B.pos.z);
    glEnd();
    glTranslatef(e->B.pos.x, e->B.pos.y, e->B.pos.z);
    //glDrawSphere(.1*s);

    glPopName();
    i++;
    if(orsDrawLimit && i>=orsDrawLimit) break;
  }

  //proxies
  if(orsDrawProxies) for(Proxy *proxy: proxies) {
    glLoadIdentity();
    if(!proxy->colorCode) glColor(.75,.75,.75);
    else glColor(proxy->colorCode);
    glBegin(GL_LINES);
    glVertex3dv(proxy->posA.p());
    glVertex3dv(proxy->posB.p());
    glEnd();
    ors::Transformation f;
    f.pos=proxy->posA;
    f.rot.setDiff(ors::Vector(0, 0, 1), proxy->posA-proxy->posB);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDisable(GL_CULL_FACE);
    glDrawDisk(.02);
    glEnable(GL_CULL_FACE);

    f.pos=proxy->posB;
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawDisk(.02);
  }

  glPopMatrix();
}
コード例 #25
0
ファイル: ApplicationOverlay.cpp プロジェクト: dimentox/hifi
// Draws the FBO texture for 3DTV.
void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float aspectRatio, float fov) {
    if (_alpha == 0.0f) {
        return;
    }
    
    Application* application = Application::getInstance();
    
    MyAvatar* myAvatar = application->getAvatar();
    const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
    
    glActiveTexture(GL_TEXTURE0);
    
    glEnable(GL_BLEND);
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
    _overlays.bindTexture();
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    
    glMatrixMode(GL_MODELVIEW);
    
    glPushMatrix();
    glLoadIdentity();
    // Transform to world space
    glm::quat rotation = whichCamera.getRotation();
    glm::vec3 axis2 = glm::axis(rotation);
    glRotatef(-glm::degrees(glm::angle(rotation)), axis2.x, axis2.y, axis2.z);
    glTranslatef(viewMatrixTranslation.x, viewMatrixTranslation.y, viewMatrixTranslation.z);
    
    // Translate to the front of the camera
    glm::vec3 pos = whichCamera.getPosition();
    glm::quat rot = myAvatar->getOrientation();
    glm::vec3 axis = glm::axis(rot);
    
    glTranslatef(pos.x, pos.y, pos.z);
    glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);
    
    glColor4f(1.0f, 1.0f, 1.0f, _alpha);
    
    //Render
    const GLfloat distance = 1.0f;
    
    const GLfloat halfQuadHeight = distance * tan(fov);
    const GLfloat halfQuadWidth = halfQuadHeight * aspectRatio;
    const GLfloat quadWidth = halfQuadWidth * 2.0f;
    const GLfloat quadHeight = halfQuadHeight * 2.0f;
    
    GLfloat x = -halfQuadWidth;
    GLfloat y = -halfQuadHeight;
    glDisable(GL_DEPTH_TEST);
    
    glBegin(GL_QUADS);
    
    glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + quadHeight, -distance);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(x + quadWidth, y + quadHeight, -distance);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(x + quadWidth, y, -distance);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, -distance);
    
    glEnd();
    
    if (_crosshairTexture == 0) {
        _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png"));
    }
    
    //draw the mouse pointer
    glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
    
    const float reticleSize = 40.0f / application->getGLWidget()->width() * quadWidth;
    x -= reticleSize / 2.0f;
    y += reticleSize / 2.0f;
    const float mouseX = (application->getMouseX() / (float)application->getGLWidget()->width()) * quadWidth;
    const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->height())) * quadHeight;
    
    glBegin(GL_QUADS);
    
    glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
    
    glTexCoord2d(0.0f, 0.0f); glVertex3f(x + mouseX, y + mouseY, -distance);
    glTexCoord2d(1.0f, 0.0f); glVertex3f(x + mouseX + reticleSize, y + mouseY, -distance);
    glTexCoord2d(1.0f, 1.0f); glVertex3f(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance);
    glTexCoord2d(0.0f, 1.0f); glVertex3f(x + mouseX, y + mouseY - reticleSize, -distance);
    
    glEnd();
    
    glEnable(GL_DEPTH_TEST);
    
    glPopMatrix();
    
    glDepthMask(GL_TRUE);
    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);
    
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
    glEnable(GL_LIGHTING);
    
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
コード例 #26
0
ファイル: main.c プロジェクト: weimingtom/ffmpeg_win32_ndk
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glTranslatef(0.0f, 0.0f, 0.0f);
	
	if (1)
	{
		if (textureContainsData) {
			glDeleteTextures(1, &g_TextureArray[g_ID]);
		}
		
		glGenTextures(1, &g_TextureArray[g_ID]);
		glBindTexture(GL_TEXTURE_2D, g_TextureArray[g_ID]);
		
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		//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_MAG_FILTER,GL_LINEAR);
		
		//glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, frame->w, frame->h, 0,
		//			  texture_format, GL_UNSIGNED_BYTE, frame->pixels);
			
			
		if (0)
		{	
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 
				g_TextureWidth, g_TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 
				texture_data);
		}
		else
		{
			//FIXME: multi thread here, screen will be null (not timer thread)
			pthread_mutex_lock(screen_mutex);
			if (screen != NULL)
			{
				SDLMOD_LockSurface(screen);
				//dumpBMPRaw("image1_out.bmp", screen->pixels, screen->w, screen->h);
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 
					screen->w, screen->h, 0, GL_RGB, GL_UNSIGNED_BYTE, 
					screen->pixels);
				SDLMOD_UnlockSurface(screen);
			}
			pthread_mutex_unlock(screen_mutex);
		}
		
		textureContainsData = 1;
	}
	else
	{
		glBindTexture(GL_TEXTURE_2D, g_TextureArray[0]);
	}
	
	glScalef(1.0f, -1.0f, 1.0f);
	
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(1.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
	glEnd();

	glutSwapBuffers();
}
コード例 #27
0
void GLUTSimLightController::draw() {
  int w = glutGet(GLUT_WINDOW_WIDTH);
  int h = glutGet(GLUT_WINDOW_HEIGHT);
  float light_position[4] = {0.0, 0.0, -1.0, 0.0};

  glViewport(0, 0, w, h);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(35, (double) w/h, 0.1, 100.0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glClearColor(0, 0, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glTranslatef(0, 0, -3);

  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_POINT_SMOOTH);

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glEnable(GL_LIGHT0);
  glEnable(GL_NORMALIZE);

  struct Light {
    float radius;
    float color[3];
    float position[2];
  } lights[4] = {
    { .2, {  0, 0,.8 }, { -.5, -.5 } },
    { .2, { .8, 0, 0 }, {  .5, -.5 } },
    { .2, {  0,.8, 0 }, {  .5,  .5 } },
    { .2, { .9,.9,.9 }, { -.5,  .5 } },
  };
  for (unsigned i = 0; i != 4; ++i) {
    Light &l = lights[i];

    if (lights_enabled[i]) {
      glColor3fv(l.color);
      draw_circle_filled(l.position[0], l.position[1], l.radius);
    }
  }

  // Draw the beat monitor.
  const double beat_monitor_dim_time = .05;
  double elapsed = get_elapsed_time_in_seconds();
  if (elapsed - last_beat_time <= beat_monitor_dim_time) {
    double v = 1 - (elapsed - last_beat_time) / beat_monitor_dim_time;
    glColor3f(v, v, v);
    glRectf(-.9, -.9, -.7, -.8);
  }

  // Draw the 2D overlays.
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, w, 0, h, -1, 1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  const int textHeight = 15;
  char buffer[256];
  int y = 0;
  sprintf(buffer, "Time: %.4fs\n", elapsed);
  glColor3f(1, 1, 1);
  glutDrawString(10, 10 + textHeight*y++, buffer);

  if (true) {
    num_frames++;
    double fps = num_frames / elapsed;
    sprintf(buffer, "FPS: %.4fs\n", fps);
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    double bpm = light_manager->GetRecentBPM();
    sprintf(buffer, "BPM: %.4fs\n", bpm);
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    sprintf(buffer, "Program: %s\n", light_manager->GetProgramName().c_str());
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    sprintf(buffer, "Strobe Enabled: %s\n",
            light_manager->GetStrobeEnabled() ? "yes" : "no");
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  glFlush();

  glutSwapBuffers();
}
コード例 #28
0
ファイル: render.c プロジェクト: kz04px/Bot_Project
void render_main(void* a)
{
  char String[256];
  char Temp[128];
  EnableOpenGL(main_display.hWnd, &main_display.hDC, &main_display.hRC);
  glClearColor(0.0, 0.0, 0.0, 0.0); // Black
  glViewport(0, 0, main_display.w, main_display.h);

  while(!main_display.quit)
  {
    glViewport(0, 0, main_display.w, main_display.h);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glOrtho(-1.0/main_display.view_zoom, 1.0/main_display.view_zoom,
        -main_display.r/main_display.view_zoom, main_display.r/main_display.view_zoom,
        -1, 1);
    glTranslatef(-main_display.view_X, -main_display.view_Y, 1.0);

    draw_Background(main_display.world);
    draw_pellets(main_display.world);
    draw_bots(main_display.world);
    draw_edge_bots(viewer_display.world);

    SwapBuffers(main_display.hDC);

    static int count = 0;
    if(main_display.display_statistics && count%30 == 0)
    {
      sprintf(String, " Generation: %i\r\n", main_display.world->generation);
      sprintf(Temp, " Frame: %i\r\n", main_display.world->frame);
      strcat(String, Temp);
      sprintf(Temp, " World width: %i\r\n", main_display.world->width);
      strcat(String, Temp);
      sprintf(Temp, " World height: %i\r\n", main_display.world->height);
      strcat(String, Temp);
      sprintf(Temp, " Average fitness: %i\r\n\r\n", main_display.world->average_fitness);
      strcat(String, Temp);

      sprintf(Temp, " Bots: %i\r\n", main_display.world->num_bots);
      strcat(String, Temp);
      sprintf(Temp, " Most bots: %i\r\n", main_display.world->bots_most);
      strcat(String, Temp);
      sprintf(Temp, " Max bots: %i\r\n", main_display.world->max_bots);
      strcat(String, Temp);
      sprintf(Temp, " Bots added: %i\r\n", main_display.world->bots_added);
      strcat(String, Temp);
      sprintf(Temp, " Bots removed: %i\r\n\r\n", main_display.world->bots_removed);
      strcat(String, Temp);

      sprintf(Temp, " Pellets: %i\r\n", main_display.world->num_pellets);
      strcat(String, Temp);
      sprintf(Temp, " Max pellets: %i\r\n", main_display.world->max_pellets);
      strcat(String, Temp);
      SetWindowText(main_display.hstatistics, String);
    }
    count++;
    Sleep(20);
  }
  DisableOpenGL(main_display.hWnd, main_display.hDC, main_display.hRC);
}
コード例 #29
0
ファイル: GHOST_Test.cpp プロジェクト: mik0001/Blender
static void View(GHOST_IWindow* window, bool stereo, int eye = 0)
{
	window->activateDrawingContext();
	GHOST_Rect bnds;
	int noOfScanlines = 0, lowerScanline = 0;
	int verticalBlankingInterval = 32;  // hard coded for testing purposes, display device dependant
	float left, right, bottom, top;
	float nearplane, farplane, zeroPlane, distance;
	float eyeSeparation = 0.62f;
	window->getClientBounds(bnds);

	// viewport
	if(stereo)
	{
		if(nVidiaWindows)
		{ 
			// handled by nVidia driver so act as normal (explicitly put here since
			// it -is- stereo)
			glViewport(0, 0, bnds.getWidth(), bnds.getHeight());
		}
		else
		{  // generic cross platform above-below stereo
			noOfScanlines = (bnds.getHeight() - verticalBlankingInterval) / 2;
			switch(eye)
			{
				case LEFT_EYE:
					// upper half of window
					lowerScanline = bnds.getHeight() - noOfScanlines;
					break;
				case RIGHT_EYE:
					// lower half of window
					lowerScanline = 0;
					break;
			}
		}
	}
	else
	{
		noOfScanlines = bnds.getHeight();
		lowerScanline = 0;
	}

	glViewport(0, lowerScanline, bnds.getWidth(), noOfScanlines);

	// projection
	left = -6.0;
	right = 6.0;
	bottom = -4.8f;
	top = 4.8f;
	nearplane = 5.0;
	farplane = 60.0;

	if(stereo)
	{
		zeroPlane = 0.0;
		distance = 14.5;
		switch(eye)
		{
			case LEFT_EYE:
				StereoProjection(left, right, bottom, top, nearplane, farplane, zeroPlane, distance, -eyeSeparation / 2.0);
				break;
			case RIGHT_EYE:
				StereoProjection(left, right, bottom, top, nearplane, farplane, zeroPlane, distance, eyeSeparation / 2.0);
				break;
		}
	}
	else
	{
//		left = -w;
//		right = w;
//		bottom = -h;
//		top = h;
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glFrustum(left, right, bottom, top, 5.0, 60.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslatef(0.0, 0.0, -40.0);

	}

	glClearColor(.2f,0.0f,0.0f,0.0f);
}
コード例 #30
0
void GLWidget::SetCamera(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble atX, GLdouble atY, GLdouble atZ)
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eyeX, eyeY, eyeZ,	atX, atY, atZ, 0.0, 1.0, 0.0);
}