void moEffectCubeMap::Draw( moTempo* tempogral,moEffectState* parentstate) { PreDraw( tempogral,parentstate); glEnable(GL_DEPTH_TEST); // Disables Depth Testing glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPushMatrix(); // Store The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix //gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0); gluPerspective(45,1.33f,0.0f,3.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glPushMatrix(); // Store The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix glTranslatef( m_Config[moR(CUBEMAP_TRANSLATEX)].GetData()->Fun()->Eval(state.tempo.ang), m_Config[moR(CUBEMAP_TRANSLATEY)].GetData()->Fun()->Eval(state.tempo.ang), m_Config[moR(CUBEMAP_TRANSLATEZ)].GetData()->Fun()->Eval(state.tempo.ang)); glRotatef( m_Config[moR(CUBEMAP_ROTATEX)].GetData()->Fun()->Eval(state.tempo.ang), 1.0, 0.0, 0.0 ); glRotatef( m_Config[moR(CUBEMAP_ROTATEY)].GetData()->Fun()->Eval(state.tempo.ang), 0.0, 1.0, 0.0 ); glRotatef( m_Config[moR(CUBEMAP_ROTATEZ)].GetData()->Fun()->Eval(state.tempo.ang), 0.0, 0.0, 1.0 ); glScalef( m_Config[moR(CUBEMAP_SCALEX)].GetData()->Fun()->Eval(state.tempo.ang), m_Config[moR(CUBEMAP_SCALEY)].GetData()->Fun()->Eval(state.tempo.ang), m_Config[moR(CUBEMAP_SCALEZ)].GetData()->Fun()->Eval(state.tempo.ang)); glColor4f( m_Config[moR(CUBEMAP_COLOR)][MO_SELECTED][MO_RED].Fun()->Eval(state.tempo.ang) * state.tintr, m_Config[moR(CUBEMAP_COLOR)][MO_SELECTED][MO_GREEN].Fun()->Eval(state.tempo.ang) * state.tintg, m_Config[moR(CUBEMAP_COLOR)][MO_SELECTED][MO_BLUE].Fun()->Eval(state.tempo.ang) * state.tintb, m_Config[moR(CUBEMAP_COLOR)][MO_SELECTED][MO_ALPHA].Fun()->Eval(state.tempo.ang) * m_Config[moR(CUBEMAP_ALPHA)].GetData()->Fun()->Eval(state.tempo.ang) * state.alpha); moTexture* pImageLeft = (moTexture*) m_Config[moR(CUBEMAP_TEXTURELEFT)].GetData()->Pointer(); moTexture* pImageRight = (moTexture*) m_Config[moR(CUBEMAP_TEXTURERIGHT)].GetData()->Pointer(); moTexture* pImageFront = (moTexture*) m_Config[moR(CUBEMAP_TEXTUREFRONT)].GetData()->Pointer(); moTexture* pImageBack = (moTexture*) m_Config[moR(CUBEMAP_TEXTUREBACK)].GetData()->Pointer(); moTexture* pImageTop = (moTexture*) m_Config[moR(CUBEMAP_TEXTURETOP)].GetData()->Pointer(); moTexture* pImageBottom = (moTexture*) m_Config[moR(CUBEMAP_TEXTUREBOTTOM)].GetData()->Pointer(); //front glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTUREFRONT)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(pImageFront->GetMaxCoordS(),0); glVertex3f(-1,-1,-1); glTexCoord2f(0,0); glVertex3f(1,-1,-1); glTexCoord2f(0,pImageFront->GetMaxCoordT()); glVertex3f(1,1,-1); glTexCoord2f(pImageFront->GetMaxCoordS(),pImageFront->GetMaxCoordT()); glVertex3f(-1,1,-1); glEnd(); //up glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTURETOP)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(pImageTop->GetMaxCoordS(),0); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(1,1,-1); glTexCoord2f(0,pImageTop->GetMaxCoordT()); glVertex3f(1,1,1); glTexCoord2f(pImageTop->GetMaxCoordS(),pImageTop->GetMaxCoordT()); glVertex3f(-1,1,1); glEnd(); //left glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTURELEFT)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(pImageLeft->GetMaxCoordS(),pImageLeft->GetMaxCoordT()); glVertex3f(-1,1,1); glTexCoord2f(0,pImageLeft->GetMaxCoordT()); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(-1,-1,-1); glTexCoord2f(pImageLeft->GetMaxCoordS(),0); glVertex3f(-1,-1,1); glEnd(); //right glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTURERIGHT)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(0,pImageRight->GetMaxCoordT()); glVertex3f(1,1,1); glTexCoord2f(pImageRight->GetMaxCoordS(),pImageRight->GetMaxCoordT()); glVertex3f(1,1,-1); glTexCoord2f(pImageRight->GetMaxCoordS(),0); glVertex3f(1,-1,-1); glTexCoord2f(0,0); glVertex3f(1,-1,1); glEnd(); //down glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTUREBOTTOM)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(pImageBottom->GetMaxCoordS(),pImageBottom->GetMaxCoordT()); glVertex3f(-1,-1,-1); glTexCoord2f(0,pImageBottom->GetMaxCoordT()); glVertex3f(1,-1,-1); glTexCoord2f(0,0); glVertex3f(1,-1,1); glTexCoord2f(pImageBottom->GetMaxCoordS(),0); glVertex3f(-1,-1,1); glEnd(); //back glBindTexture( GL_TEXTURE_2D, m_Config[moR(CUBEMAP_TEXTUREBACK)].GetData()->GetGLId(&state.tempo, 1, NULL ) ); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-1,-1,1); glTexCoord2f(pImageBack->GetMaxCoordS(),0); glVertex3f(1,-1,1); glTexCoord2f(pImageBack->GetMaxCoordS(),pImageBack->GetMaxCoordT()); glVertex3f(1,1,1); glTexCoord2f(0,pImageBack->GetMaxCoordT()); glVertex3f(-1,1,1); glEnd(); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glPopMatrix(); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPopMatrix(); // Restore The Old Projection Matrix }
void RenderScene() { // This is the last function that we need explaining for this tutorial. // We have done all the shadow mapping work above this, but we still haven't // gone over actually rendering the depth values of the light's view to a // texture. Let's go over each line and see how this is done. It's simple. // Since our light is moving every frame we will need to update the light's // matrices. We really only need to update the modelview matrix every frame, // but we do the projection matrix too just to make it a simple function call. // If your light never moves, you only need to call this function once. StoreLightMatrices(); // Clear the screen and depth buffer so we can render from the light's view glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Since our texture map that will store the depth values is a different size // than our normal viewport, we need to change the viewport to make it the same // size as our texture. glViewport(0, 0, (int)SHADOW_WIDTH, (int)SHADOW_HEIGHT); // Now we just need to set the matrices for the light before we render. // We switch to projection mode and input our light's projection matrix. glMatrixMode(GL_PROJECTION); // Push on a matrix to make sure we can restore to the old matrix easily glPushMatrix(); // Set the current projection matrix to our light's projection matrix glLoadMatrixf(g_mProjection); // Load modelview mode to set our light's modelview matrix glMatrixMode(GL_MODELVIEW); // Load the light's modelview matrix before we render to a texture glLoadMatrixf(g_mModelView); // Since we don't care about color when rendering the depth values to // the shadow-map texture, we disable color writing to increase speed. glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // This special function fixes artifacts that lead to small errors when // calculating the shadow map. You will need to adjust the scale depending // on your scene, but I chose the scale 8.0 for mine. NVIDIA suggests 1.1 // or higher. The 4.0 should stay fairly the same. glPolygonOffset(8.0f, 4.0f); // This turns of the polygon offset functionality to fix artifacts. // Comment this out and run the program to see what artifacts I mean. glEnable(GL_POLYGON_OFFSET_FILL); // Render the world according to the light's view RenderWorld(); // Now that the world is rendered, save the depth values to a texture glBindTexture(GL_TEXTURE_2D, g_Texture[SHADOW_ID]); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, (int)SHADOW_WIDTH, (int)SHADOW_HEIGHT); // We can turn color writing back on since we already stored the depth values glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Turn off polygon offsetting glDisable(GL_POLYGON_OFFSET_FILL); // Restore our normal viewport size to our screen width and height glViewport(0, 0, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT); // Go back to the projection mode and restore the original matrix glMatrixMode(GL_PROJECTION); // Restore the original projection matrix glPopMatrix(); // Go back to modelview model to start drawing like normal glMatrixMode(GL_MODELVIEW); // Clear the color and depth bits and start over from the camera's view glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); g_Camera.Look(); // Render the world and apply the shadow map texture to it ApplyShadowMap(); // The rest of the code below just draws and moves the light. You don't need it. GLUquadricObj *pObj = gluNewQuadric(); // Get a Quadric off the stack gluQuadricDrawStyle(pObj, GLU_FILL); // Draw the sphere normally // Draw the light at the light's position glColor4f(1.0f, 1.0f, 0.0f, 1.0f); glTranslatef(g_LightPosition[0], g_LightPosition[1], g_LightPosition[2]); gluSphere(pObj, 0.05f, 25, 25); gluDeleteQuadric(pObj); // Free the Quadric SwapBuffers(g_hDC); // Swap the backbuffers to the foreground // If the light position goes out of the screen to the left, reset the direction and position. if(g_LightPosition[0] < -2.0f) { g_Direction = g_Direction * -1; g_LightPosition[0] = -2.0f; } // If the light position goes out of the screen to the right, reset the direction and position. if(g_LightPosition[0] > 2.0f) { g_Direction = g_Direction * -1; g_LightPosition[0] = 2.0f; } // Each frame we move the light by the current direction, then update the light with GL. g_LightPosition[0] += g_Direction; glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition ); }
/* ================= R_DrawAliasModel ================= */ void R_DrawAliasModel (entity_t *e) { int i; int lnum; vec3_t dist; float add; model_t *clmodel; vec3_t mins, maxs; aliashdr_t *paliashdr; float an; int anim; clmodel = currententity->model; VectorAdd (currententity->origin, clmodel->mins, mins); VectorAdd (currententity->origin, clmodel->maxs, maxs); if (R_CullBox (mins, maxs)) return; VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); // // get lighting information // ambientlight = shadelight = R_LightPoint (currententity->origin); // allways give the gun some light if (e == &cl.viewent && ambientlight < 24) ambientlight = shadelight = 24; for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++) { if (cl_dlights[lnum].die >= cl.time) { VectorSubtract (currententity->origin, cl_dlights[lnum].origin, dist); add = cl_dlights[lnum].radius - Length(dist); if (add > 0) { ambientlight += add; //ZOID models should be affected by dlights as well shadelight += add; } } } // clamp lighting so it doesn't overbright as much if (ambientlight > 128) ambientlight = 128; if (ambientlight + shadelight > 192) shadelight = 192 - ambientlight; // ZOID: never allow players to go totally black i = currententity - cl_entities; if (i >= 1 && i<=cl.maxclients /* && !strcmp (currententity->model->name, "progs/player.mdl") */) if (ambientlight < 8) ambientlight = shadelight = 8; // HACK HACK HACK -- no fullbright colors, so make torches full light if (!Q_strcmp (clmodel->name, "progs/flame2.mdl") || !Q_strcmp (clmodel->name, "progs/flame.mdl") ) ambientlight = shadelight = 256; shadedots = r_avertexnormal_dots[((int)(e->angles[1] * (SHADEDOT_QUANT / 360.0))) & (SHADEDOT_QUANT - 1)]; shadelight = shadelight / 200.0; an = e->angles[1]/180*M_PI; shadevector[0] = cos(-an); shadevector[1] = sin(-an); shadevector[2] = 1; VectorNormalize (shadevector); // // locate the proper data // paliashdr = (aliashdr_t *)Mod_Extradata (currententity->model); c_alias_polys += paliashdr->numtris; // // draw all the triangles // GL_DisableMultitexture(); glPushMatrix (); R_RotateForEntity (e); if (!Q_strcmp (clmodel->name, "progs/eyes.mdl") && gl_doubleeyes.value) { glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2] - (22 + 8)); // double size of eyes, since they are really hard to see in gl glScalef (paliashdr->scale[0]*2, paliashdr->scale[1]*2, paliashdr->scale[2]*2); } else { glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]); glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]); } anim = (int)(cl.time*10) & 3; GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]); // we can't dynamically colormap textures, so they are cached // seperately for the players. Heads are just uncolored. if (currententity->colormap != vid.colormap && !gl_nocolors.value) { i = currententity - cl_entities; if (i >= 1 && i<=cl.maxclients /* && !Q_strcmp (currententity->model->name, "progs/player.mdl") */) GL_Bind(playertextures - 1 + i); } if (gl_smoothmodels.value) glShadeModel (GL_SMOOTH); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (gl_affinemodels.value) glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); R_SetupAliasFrame (currententity->frame, paliashdr); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glShadeModel (GL_FLAT); if (gl_affinemodels.value) glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glPopMatrix (); if (r_shadows.value) { glPushMatrix (); R_RotateForEntity (e); glDisable (GL_TEXTURE_2D); glEnable (GL_BLEND); glColor4f (0,0,0,0.5); GL_DrawAliasShadow (paliashdr, lastposenum); glEnable (GL_TEXTURE_2D); glDisable (GL_BLEND); glColor4f (1,1,1,1); glPopMatrix (); } }
void Circle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); if (alpha == 0.0) { return; // do nothing if our alpha is 0, we're not visible } // Create the circle in the coordinates origin float outerRadius = getOuterRadius(); float innerRadius = getInnerRadius(); // only used in solid case float startAt = getStartAt(); float endAt = getEndAt(); bool geometryChanged = (startAt != _lastStartAt || endAt != _lastEndAt || innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius); const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; //const int slices = 15; xColor color = getColor(); const float MAX_COLOR = 255.0f; glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); glm::vec3 position = getPosition(); glm::vec3 center = getCenter(); glm::vec2 dimensions = getDimensions(); glm::quat rotation = getRotation(); float glowLevel = getGlowLevel(); Glower* glower = NULL; if (glowLevel > 0.0f) { glower = new Glower(glowLevel); } glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, 1.0f); glLineWidth(_lineWidth); auto geometryCache = DependencyManager::get<GeometryCache>(); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { if (_quadVerticesID == GeometryCache::UNKNOWN_ID) { _quadVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << firstInnerPoint << firstOuterPoint; while (angle < endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << thisOuterPoint << thisInnerPoint; angle += SLICE_ANGLE; } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << lastOuterPoint << lastInnerPoint; geometryCache->updateVertices(_quadVerticesID, points); } geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); } else { if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { _lineVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << firstPoint; while (angle < endAt) { angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << thisPoint; if (getIsDashedLine()) { angle += SLICE_ANGLE / 2.0f; // short gap angleInRadians = glm::radians(angle); glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << dashStartPoint; } } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << lastPoint; geometryCache->updateVertices(_lineVerticesID, points); } if (getIsDashedLine()) { geometryCache->renderVertices(GL_LINES, _lineVerticesID); } else { geometryCache->renderVertices(GL_LINE_STRIP, _lineVerticesID); } } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _majorTicksVerticesID = geometryCache->allocateID(); } if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _minorTicksVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> majorPoints; QVector<glm::vec2> minorPoints; // draw our major tick marks if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { float tickMarkAngle = getMajorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMajorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); majorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } // draw our minor tick marks if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { float tickMarkAngle = getMinorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMinorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); minorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } geometryCache->updateVertices(_majorTicksVerticesID, majorPoints); geometryCache->updateVertices(_minorTicksVerticesID, minorPoints); } xColor majorColor = getMajorTickMarksColor(); glColor4f(majorColor.red / MAX_COLOR, majorColor.green / MAX_COLOR, majorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID); xColor minorColor = getMinorTickMarksColor(); glColor4f(minorColor.red / MAX_COLOR, minorColor.green / MAX_COLOR, minorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID); } glPopMatrix(); glPopMatrix(); if (geometryChanged) { _lastStartAt = startAt; _lastEndAt = endAt; _lastInnerRadius = innerRadius; _lastOuterRadius = outerRadius; } if (glower) { delete glower; } }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen and Depth Buffer glLoadIdentity(); glTranslatef(0.0f,0.0f,-10.0f); keyOperations(); // glRotatef(initialy, 0.0f, 1.0f, 0.0f); gluLookAt(initialx,1,initialz, initialx-sin(rotY),1,initialz-cos(rotY), 0,1,0); // glTranslatef(0.0f, 0.0f, initialz); glPushMatrix(); glTranslatef(6,-2.00,5); /* * drawing the enclosing box */ glColor3f(0.5f, 0.8f, 0.5f); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); for (int i = -100.0; i < 250.0f; i+=25.0f) { for (int j = -100.0f; j < 100.0f; j+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(j,-0.0001f, i+25.0f); glTexCoord2f(0.0, 1.0); glVertex3f(j,-0.0001f,i); glTexCoord2f(1.0, 1.0); glVertex3f(j+25.0f,-0.0001f,i); glTexCoord2f(1.0, 0.0); glVertex3f(j+25.0f,-0.0001f, i+25.0f); } } glEnd(); glColor3f(0.75f, 0.75f, 0.75f); glBindTexture(GL_TEXTURE_2D, texture[2]); // DrawEnclosingSphere(300, 10, 10); glBegin(GL_QUADS); for (int i = -100.0; i < 250.0f; i+=25.0f) { for (int j = -100.0f; j < 100.0f; j+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(j,25.0f, i+25.0f); glTexCoord2f(0.0, 1.0); glVertex3f(j,25.0f,i); glTexCoord2f(1.0, 1.0); glVertex3f(j+25.0f,25.0f,i); glTexCoord2f(1.0, 0.0); glVertex3f(j+25.0f,25.0f, i+25.0f); } } glEnd(); glColor3f(1.0f, 1.0f, 1.0f); // glBindTexture(GL_TEXTURE_2D, texture[3]); // DrawEnclosingSphere(300, 10, 10); glBegin(GL_QUADS); for (int i = -100.0f; i < 100.0f; i+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(i, 0.0f, -100.0f); glTexCoord2f(1.0, 0.0); glVertex3f(i + 25.0f, 0.0f, -100.0f); glTexCoord2f(1.0, 1.0); glVertex3f(i + 25.0f, 25.0f, -100.0f); glTexCoord2f(0.0, 1.0); glVertex3f(i, 25.0f, -100.0f); } for (int i = -100.0f; i < 100.0f; i+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(i, 0.0f, 250.0f); glTexCoord2f(1.0, 0.0); glVertex3f(i + 25.0f, 0.0f, 250.0f); glTexCoord2f(1.0, 1.0); glVertex3f(i + 25.0f, 25.0f, 250.0f); glTexCoord2f(0.0, 1.0); glVertex3f(i, 25.0f, 250.0f); } for (int i = -100.0f; i < 250.0f; i+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(-100.0f, 0.0f,i); glTexCoord2f(1.0, 0.0); glVertex3f(-100.0f, 0.0f,i+25.0f); glTexCoord2f(1.0, 1.0); glVertex3f(-100.0f, 25.0f,i+25.0f); glTexCoord2f(0.0, 1.0); glVertex3f(-100.0f, 25.0f,i); } for (int i = -100.0f; i < 250.0f; i+=25.0f) { glTexCoord2f(0.0, 0.0); glVertex3f(100.0f, 0.0f,i); glTexCoord2f(1.0, 0.0); glVertex3f(100.0f, 0.0f,i+25.0f); glTexCoord2f(1.0, 1.0); glVertex3f(100.0f, 25.0f,i+25.0f); glTexCoord2f(0.0, 1.0); glVertex3f(100.0f, 25.0f,i); } glEnd(); /* * drawing the track */ glColor3f(3.0f,3.0f,3.0f); glBindTexture(GL_TEXTURE_2D, texture[0]); if (currTrack.id == 2) { glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f( -69.6982f, 0.0000f, 146.3044f); glTexCoord2f(1.0, 0.0); glVertex3f( -44.6982f, 0.0000f, 146.3044f); glTexCoord2f(1.0, 1.0); glVertex3f( -44.6982f, 0.0000f, -3.6956f); glTexCoord2f(0.0, 1.0); glVertex3f( -69.6982f, 0.0000f, -3.6956f); glTexCoord2f(0.0, 0.0); glVertex3f( -69.6982f, 0.0000f, -3.6956f); glTexCoord2f(1.0, 0.0); glVertex3f( -44.6982f, 0.0000f, -3.6956f); glTexCoord2f(1.0, 1.0); glVertex3f( -41.5202f, 0.0000f, -20.8055f); glTexCoord2f(0.0, 1.0); glVertex3f( -65.0125f, 0.0000f, -29.3560f); glTexCoord2f(0.0, 0.0); glVertex3f( -65.0125f, 0.0000f, -29.3560f); glTexCoord2f(1.0, 0.0); glVertex3f( -41.5202f, 0.0000f, -20.8055f); glTexCoord2f(1.0, 1.0); glVertex3f( -32.8378f, 0.0000f, -35.8439f); glTexCoord2f(0.0, 1.0); glVertex3f( -51.9889f, 0.0000f, -51.9136f); glTexCoord2f(0.0, 0.0); glVertex3f( -51.9889f, 0.0000f, -51.9136f); glTexCoord2f(1.0, 0.0); glVertex3f( -32.8378f, 0.0000f, -35.8439f); glTexCoord2f(1.0, 1.0); glVertex3f( -19.5355f, 0.0000f, -47.0058f); glTexCoord2f(0.0, 1.0); glVertex3f( -32.0355f, 0.0000f, -68.6564f); glTexCoord2f(0.0, 0.0); glVertex3f( -32.0355f, 0.0000f, -68.6564f); glTexCoord2f(1.0, 0.0); glVertex3f( -19.5355f, 0.0000f, -47.0058f); glTexCoord2f(1.0, 1.0); glVertex3f( -3.2180f, 0.0000f, -52.9449f); glTexCoord2f(0.0, 1.0); glVertex3f( -7.5592f, 0.0000f, -77.5651f); glTexCoord2f(0.0, 0.0); glVertex3f( -7.5592f, 0.0000f, -77.5651f); glTexCoord2f(1.0, 0.0); glVertex3f( -3.2180f, 0.0000f, -52.9449f); glTexCoord2f(1.0, 1.0); glVertex3f( 14.1469f, 0.0000f, -52.9449f); glTexCoord2f(0.0, 1.0); glVertex3f( 18.4881f, 0.0000f, -77.5651f); glTexCoord2f(0.0, 0.0); glVertex3f( 18.4881f, 0.0000f, -77.5651f); glTexCoord2f(1.0, 0.0); glVertex3f( 14.1469f, 0.0000f, -52.9449f); glTexCoord2f(1.0, 1.0); glVertex3f( 30.4644f, 0.0000f, -47.0058f); glTexCoord2f(0.0, 1.0); glVertex3f( 42.9644f, 0.0000f, -68.6564f); glTexCoord2f(0.0, 0.0); glVertex3f( 42.9644f, 0.0000f, -68.6564f); glTexCoord2f(1.0, 0.0); glVertex3f( 30.4644f, 0.0000f, -47.0058f); glTexCoord2f(1.0, 1.0); glVertex3f( 43.7667f, 0.0000f, -35.8439f); glTexCoord2f(0.0, 1.0); glVertex3f( 62.9178f, 0.0000f, -51.9136f); glTexCoord2f(0.0, 0.0); glVertex3f( 62.9178f, 0.0000f, -51.9136f); glTexCoord2f(1.0, 0.0); glVertex3f( 43.7667f, 0.0000f, -35.8439f); glTexCoord2f(1.0, 1.0); glVertex3f( 52.4491f, 0.0000f, -20.8055f); glTexCoord2f(0.0, 1.0); glVertex3f( 75.9414f, 0.0000f, -29.3560f); glTexCoord2f(0.0, 0.0); glVertex3f( 75.9414f, 0.0000f, -29.3560f); glTexCoord2f(1.0, 0.0); glVertex3f( 52.4491f, 0.0000f, -20.8055f); glTexCoord2f(1.0, 1.0); glVertex3f( 55.4644f, 0.0000f, -3.7045f); glTexCoord2f(0.0, 1.0); glVertex3f( 80.4644f, 0.0000f, -3.7045f); glTexCoord2f(0.0, 0.0); glVertex3f( 80.4644f, 0.0000f, -3.7045f); glTexCoord2f(1.0, 0.0); glVertex3f( 55.4644f, 0.0000f, -3.7045f); glTexCoord2f(1.0, 1.0); glVertex3f( 55.4316f, 0.0000f, 146.3044f); glTexCoord2f(0.0, 1.0); glVertex3f( 80.4316f, 0.0000f, 146.3044f); glTexCoord2f(0.0, 0.0); glVertex3f( 80.4316f, 0.0000f, 146.3044f); glTexCoord2f(1.0, 0.0); glVertex3f( 55.4316f, 0.0000f, 146.3044f); glTexCoord2f(1.0, 1.0); glVertex3f( 52.4491f, 0.0000f, 163.3138f); glTexCoord2f(0.0, 1.0); glVertex3f( 75.9414f, 0.0000f, 171.8643f); glTexCoord2f(0.0, 0.0); glVertex3f( 75.9414f, 0.0000f, 171.8643f); glTexCoord2f(1.0, 0.0); glVertex3f( 52.4491f, 0.0000f, 163.3138f); glTexCoord2f(1.0, 1.0); glVertex3f( 43.7667f, 0.0000f, 178.3522f); glTexCoord2f(0.0, 1.0); glVertex3f( 62.9178f, 0.0000f, 194.4219f); glTexCoord2f(0.0, 0.0); glVertex3f( 62.9178f, 0.0000f, 194.4219f); glTexCoord2f(1.0, 0.0); glVertex3f( 43.7667f, 0.0000f, 178.3522f); glTexCoord2f(1.0, 1.0); glVertex3f( 30.4644f, 0.0000f, 189.5141f); glTexCoord2f(0.0, 1.0); glVertex3f( 42.9644f, 0.0000f, 211.1647f); glTexCoord2f(0.0, 0.0); glVertex3f( 42.9644f, 0.0000f, 211.1647f); glTexCoord2f(1.0, 0.0); glVertex3f( 30.4644f, 0.0000f, 189.5141f); glTexCoord2f(1.0, 1.0); glVertex3f( 14.1468f, 0.0000f, 195.4532f); glTexCoord2f(0.0, 1.0); glVertex3f( 18.4880f, 0.0000f, 220.0734f); glTexCoord2f(0.0, 0.0); glVertex3f( 18.4880f, 0.0000f, 220.0734f); glTexCoord2f(1.0, 0.0); glVertex3f( 14.1468f, 0.0000f, 195.4532f); glTexCoord2f(1.0, 1.0); glVertex3f( -3.2180f, 0.0000f, 195.4532f); glTexCoord2f(0.0, 1.0); glVertex3f( -7.5592f, 0.0000f, 220.0734f); glTexCoord2f(0.0, 0.0); glVertex3f( -7.5592f, 0.0000f, 220.0734f); glTexCoord2f(1.0, 0.0); glVertex3f( -3.2180f, 0.0000f, 195.4532f); glTexCoord2f(1.0, 1.0); glVertex3f( -19.5356f, 0.0000f, 189.5141f); glTexCoord2f(0.0, 1.0); glVertex3f( -32.0356f, 0.0000f, 211.1647f); glTexCoord2f(0.0, 0.0); glVertex3f( -32.0356f, 0.0000f, 211.1647f); glTexCoord2f(1.0, 0.0); glVertex3f( -19.5356f, 0.0000f, 189.5141f); glTexCoord2f(1.0, 1.0); glVertex3f( -32.8378f, 0.0000f, 178.3522f); glTexCoord2f(0.0, 1.0); glVertex3f( -51.9889f, 0.0000f, 194.4219f); glTexCoord2f(0.0, 0.0); glVertex3f( -51.9889f, 0.0000f, 194.4219f); glTexCoord2f(1.0, 0.0); glVertex3f( -32.8378f, 0.0000f, 178.3522f); glTexCoord2f(1.0, 1.0); glVertex3f( -41.5202f, 0.0000f, 163.3138f); glTexCoord2f(0.0, 1.0); glVertex3f( -65.0125f, 0.0000f, 171.8643f); glTexCoord2f(0.0, 0.0); glVertex3f( -65.0125f, 0.0000f, 171.8643f); glTexCoord2f(1.0, 0.0); glVertex3f( -41.5202f, 0.0000f, 163.3138f); glTexCoord2f(1.0, 1.0); glVertex3f( -44.6982f, 0.0000f, 146.3044f); glTexCoord2f(0.0, 1.0); glVertex3f( -69.6982f, 0.0000f, 146.3044f); glEnd(); } else if (currTrack.id == 3) { glTranslatef(-40.0f, 0.0f, 100.0f); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f( 0.2048f, 0.0000f, 16.3703f); glTexCoord2f(0.0, 1.0); glVertex3f( 0.2048f, 0.0000f, 86.3703f); glTexCoord2f(1.0, 1.0); glVertex3f( 25.2048f, 0.0000f, 86.3703f); glTexCoord2f(1.0, 0.0); glVertex3f( 25.2048f, 0.0000f, 16.3703f); glTexCoord2f(0.0, 0.0); glVertex3f( 29.8147f, 0.0000f, -53.3839f); glTexCoord2f(0.0, 1.0); glVertex3f( 0.2048f, 0.0000f, 16.3703f); glTexCoord2f(1.0, 1.0); glVertex3f( 25.2048f, 0.0000f, 16.3703f); glTexCoord2f(1.0, 0.0); glVertex3f( 54.8147f, 0.0000f, -53.3839f); glTexCoord2f(0.0, 0.0); glVertex3f( 29.8148f, 0.0000f, -123.4015f); glTexCoord2f(0.0, 1.0); glVertex3f( 29.8147f, 0.0000f, -53.3839f); glTexCoord2f(1.0, 1.0); glVertex3f( 54.8147f, 0.0000f, -53.3839f); glTexCoord2f(1.0, 0.0); glVertex3f( 54.8148f, 0.0000f, -123.4015f); glTexCoord2f(0.0, 0.0); glVertex3f( -4.2518f, 0.0000f, -193.4343f); glTexCoord2f(0.0, 1.0); glVertex3f( 29.8148f, 0.0000f, -123.4015f); glTexCoord2f(1.0, 1.0); glVertex3f( 54.8148f, 0.0000f, -123.4015f); glTexCoord2f(1.0, 0.0); glVertex3f( 20.7482f, 0.0000f, -193.4343f); glEnd(); } else { currTrack.id++; } /* * Loading the object - car */ glTranslatef(initialx-sin(rotY),1,initialz-cos(rotY)); glColor3f(1.0,0.23,0.27); glScalef(0.6,0.6,0.6); glRotatef(rotY, 0.0f, 1.0f, 0.0f); glCallList(ObjList); glRotatef(rotY, 0.0f, -1.0f, 0.0f); // glColor4f(0.0f, 0.0f, 0.0f, 0.0f); // glTranslatef(-(initialx-sin(rotY)),0,-(initialz-cos(rotY))); glPopMatrix(); /* * Trying to do some HUD here */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, win.width, win.height, 0.0, -1.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(0.0, 0.0); glVertex2f(win.width, 0.0); glVertex2f(win.width, 100.0); glVertex2f(0.0, 100.0); glEnd(); /* * Trying to write some stuff inside the HUD created. */ // char* myCharString = "Yo babes"; // glutStrokeCharacter(GLUT_STROKE_ROMAN, 1/*myCharString*/); char quote[80]; glScalef(0.4, 0.4, 0.5); glTranslatef(0.0f,150.0f, 0.0f); glRotatef(180, 1.0, 0.0, 0.0); sprintf(quote, "Speed = %.0f Turn Angle=%.0f", -50*speed, turn); int lenghOfQuote = (int)strlen(quote); glPushMatrix(); // glTranslatef(-(lenghOfQuote*37), -(l*200), 0.0); for (int i = 0; i < lenghOfQuote; i++) { glColor4f(0.0f, 0.0f, 0.0f, 1.0f); // glColor3f((UpwardsScrollVelocity/10)+300+(l*10),(UpwardsScrollVelocity/10)+300+(l*10),0.0); glutStrokeCharacter(GLUT_STROKE_ROMAN, quote[i]); } glPopMatrix(); //Make sure we can render in 3d again glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glutSwapBuffers(); }
/*! To set a valid raster position outside the viewport, first set a valid raster position inside the viewport, then call glBitmap with NULL as the bitmap parameter and with xmove and ymove set to the offsets of the new raster position. This technique is useful when panning an image around the viewport. (see http://www.opengl.org/sdk/docs/man/xhtml/glBitmap.xml and http://www.opengl.org/sdk/docs/man/xhtml/glDrawPixels.xml) */ void ImageView::GLDraw() { #ifdef USE_OPEN_GL_WINDOW if (!valid()) GLViewSetup(); #else gl_start(); #endif // Invert image //glPixelZoom(1.0f, -1.0f); glPixelZoom((float) m_scaling, (float) -m_scaling); // Set image origin glRasterPos2i(0, h()); // Check that the raster position is valid GLboolean rasVal; glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &rasVal); if (!rasVal) { ShowError("Invalid raster position. No image will be shown"); } // If image is scaled down, the view needs to be fully erased //if (m_zoom < 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); m_mutex.Lock(); if (m_curByteImage.is_contiguous() && m_curByteImage.size() > 0) glDrawPixels(m_curByteImage.ni(), m_curByteImage.nj(), GL_LUMINANCE, GL_UNSIGNED_BYTE, m_curByteImage.top_left_ptr()); else if (m_curRGBImage.is_contiguous()) glDrawPixels(m_curRGBImage.ni(), m_curRGBImage.nj(), GL_RGB, GL_UNSIGNED_BYTE, m_curRGBImage.top_left_ptr()); else glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_mutex.Release(); // Call the current vision system component (if there is one) // to draw over the current image if (m_pPainter) { glPushMatrix(); glTranslated(m_offset.x, m_offset.y + h(), 0); glScaled(m_zoom, -m_zoom, 1); glColor4f(0, 0, 0, 1.0); m_pPainter->DrawWithMutex(m_painterInfo); glPopMatrix(); } #ifdef USE_OPEN_GL_WINDOW glFlush(); #else gl_finish(); #endif }
//WinMain -- Main Window int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; msg.message = WM_CREATE; WNDCLASS wc; wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = "chockngt"; RegisterClass (&wc); // Create the window //mainWnd = CreateWindow (szAppName,szAppName,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,1024,600,0,0,hInstance,0); mainWnd = CreateWindow("chockngt","chockngt",WS_POPUP|WS_VISIBLE|WS_MAXIMIZE,0,0,0,0,0,0,hInstance,0); glInit(); ShowWindow(mainWnd,SW_SHOW); UpdateWindow(mainWnd); // Initialize Swarm positions and stuff initSwarm(); long startTime = timeGetTime(); long lastTime = 0; // start music playback BASS_Init(-1,44100,0,mainWnd,NULL); mp3Str=BASS_StreamCreateFile(FALSE,"GT_muc.mp3",0,0,0); BASS_ChannelPlay(mp3Str, TRUE); BASS_Start(); float fCurTime; GetAsyncKeyState(VK_ESCAPE); do { SetCursor(FALSE); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!IsDialogMessage(mainWnd, &msg)) { TranslateMessage (&msg); DispatchMessage (&msg); } } if (msg.message == WM_QUIT) break; // early exit on quit // update timer long curTime = timeGetTime() - startTime; fCurTime = (float)curTime * 0.001f; long deltaTime = curTime - lastTime; float fDeltaTime = (float) deltaTime * 0.001f; lastTime = curTime; // render wglMakeCurrent(mainDC, mainRC); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); // draw background //drawQuad(-1.0f, 1.0f, -1.0f, 1.0f, 0.4f, 1.0f, 1.0f); glEnable(GL_DEPTH_TEST); // Distance to the center object // TODO: Hitchcock-effect by means of gluPerspective! float cameraDist = 20.0f; float cameraComeTime = 150.0f; if (fCurTime > cameraComeTime) { cameraDist = 3.0f + 17.0f / (1.0f + 0.1f * ((fCurTime - cameraComeTime) * (fCurTime - cameraComeTime))); } // set up matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); // TODO aspect //gluPerspective(25.0, 1.8, 0.1, 100.0); gluPerspective(500.0f / cameraDist, 1.8, 0.1, 100.0); //gluPerspective(25.0, 1.8, 1.1, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //gluLookAt(0.0, 0.0, -cameraDist, // 0.0, 0.0, 0.0, // 0.0, 1.0, 0.0); gluLookAt(1., 0.5, -cameraDist, 1., 0.5, 0.0, 0.0, 1.0, 0.0); // lighting: float ambient[4] = {0.3f, 0.23f, 0.2f, 1.0f}; //float diffuse[4] = {1.8f, 1.7f, 0.8f, 1.0f}; float diffuse[4] = {0.9f, 0.85f, 0.4f, 1.0f}; float diffuse2[4] = {0.45f, 0.475f, 0.2f, 1.0f}; //float diffuse2[4] = {0.0f, 0.0f, 0.0f, 1.0f}; float specular[4] = {1.0f, 1.0f, 1.0f, 1.0f}; float lightDir[4] = {0.7f, 0.0f, 0.7f, 0.0f}; float allOnes[4] = {1.0f, 1.0f, 1.0f, 1.0f}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_POSITION, lightDir); //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, allOnes); //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, allOnes); //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, allOnes); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); float metaAmount = 1.0f; int signedDistanceID = 1; // sphere if (fCurTime > 61.0f) signedDistanceID = 2; // metaballs //signedDistanceID = 0; // nothing int pathID = 0; // 8 moveTo points if (fCurTime > 80.0f) { pathID = 1; // 4 lines signedDistanceID = 0; // Nothing if (fCurTime > 130.0f) { pathID = 0; // 4 move to points signedDistanceID = 2; // metaballs } } // In reversed field if (fCurTime > 170.0f) { pathID = 0; signedDistanceID = 2; if (fCurTime > 190.0f) { pathID = 1; signedDistanceID = 0; } if (fCurTime > 210.0f) { pathID = 1; signedDistanceID = 2; } if (fCurTime > 217.0f) { pathID = 0; signedDistanceID = 1; } } // generate destiations float overshoot = 0.0f; if (fCurTime > 19.f) { float relTime = fCurTime - 19.f; overshoot = 2.0f * sin(relTime*0.17f) * (-cos(relTime * 0.75f) + 1.0f); } if (fCurTime > 200.0f) { float relTime = (fCurTime - 200.0f); overshoot /= relTime * relTime + 1.0f; } updateSwarmDestinations(pathID, fDeltaTime, overshoot); // update direction of the Triangles updateSwarmWithSignedDistance(signedDistanceID, fDeltaTime, metaAmount); // move all triangles moveSwarm(fDeltaTime); // Set how many triangles to render for each path int numTrisRender1 = (curTime - 11300) / 8; int numTrisRender2 = (curTime - 3300) / 2; numTrisRender1 = numTrisRender1 > NUM_TRIANGLES ? NUM_TRIANGLES : numTrisRender1; numTrisRender1 = numTrisRender1 < 0 ? 0 : numTrisRender1; numTrisRender2 = numTrisRender2 > NUM_TRIANGLES ? NUM_TRIANGLES : numTrisRender2; numTrisRender2 = numTrisRender2 < 0 ? 0 : numTrisRender2; float triBrightness = fCurTime / 30.0f + 0.2f; if (triBrightness > 1.0f) triBrightness = 1.0f; // render tris glBegin(GL_TRIANGLES); for (int i = 0; i < numTrisRender1; i++) { //glNormal3f(0.3f, 0.5f, 0.2f); float right[3]; right[0] = tris.direction[i][1] * tris.normal[i][2] - tris.direction[i][2] * tris.normal[i][1]; right[1] = tris.direction[i][2] * tris.normal[i][0] - tris.direction[i][0] * tris.normal[i][2]; right[2] = tris.direction[i][0] * tris.normal[i][1] - tris.direction[i][1] * tris.normal[i][0]; glNormal3fv(tris.normal[i]); glVertex3f(tris.position[i][0] + 0.2f * tris.direction[i][0], tris.position[i][1] + 0.2f * tris.direction[i][1], tris.position[i][2] + 0.2f * tris.direction[i][2]); glVertex3f(tris.position[i][0] + 0.2f * right[0], tris.position[i][1] + 0.2f * right[1], tris.position[i][2] + 0.2f * right[2]); glVertex3f(tris.position[i][0] - 0.2f * right[0], tris.position[i][1] - 0.2f * right[0], tris.position[i][2] - 0.2f * right[0]); } glEnd(); glDepthMask(FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glDisable(GL_LIGHTING); float beating = 1.0f - 0.25f * fabsf((float)sin(fCurTime*4.652f)); glBegin(GL_TRIANGLES); for (int i = 0; i < numTrisRender2; i++) { const float colorA[3] = {0.3f, 0.5f, 1.0f}; const float colorB[3] = {1.0f, 0.8f, 0.3f}; const float colorC[3] = {2.0f, 0.4f, 0.1f}; float color[3]; float colorT = fCurTime * 0.01f; if (colorT > 1.0f) colorT = 1.0f; for (int c = 0; c < 3; c++) { color[c] = colorA[c] * (1.0f - colorT) + colorT * colorB[c]; } if (fCurTime > 100.0f) { colorT = (fCurTime - 100.0f) * 0.1f - ((i*i*17)%63) * 0.1f; if (colorT < 0.0f) colorT = 0.0f; if (colorT > 1.0f) colorT = 1.0f; for (int c = 0; c < 3; c++) { color[c] = colorB[c] * (1.0f - colorT) + colorT * colorC[c]; } } // Some color noise for (int c = 0; c < 3; c++) { float n = ((((i*i+13)*(c*c+7)+(i*(c+1))) % 100) - 50) * 0.0025f; color[c] += n; } //glNormal3f(0.3f, 0.5f, 0.2f); glColor4f(color[0], color[1], color[2], beating * 0.1f * triBrightness); float right[3]; right[0] = tris.direction[i][1] * tris.normal[i][2] - tris.direction[i][2] * tris.normal[i][1]; right[1] = tris.direction[i][2] * tris.normal[i][0] - tris.direction[i][0] * tris.normal[i][2]; right[2] = tris.direction[i][0] * tris.normal[i][1] - tris.direction[i][1] * tris.normal[i][0]; glNormal3fv(tris.normal[i]); glVertex3f(tris.position[i][0] + 0.6f * tris.direction[i][0], tris.position[i][1] + 0.6f * tris.direction[i][1], tris.position[i][2] + 0.6f * tris.direction[i][2] - 0.1f); glVertex3f(tris.position[i][0] + 0.6f * right[0] - 0.2f * tris.direction[i][0], tris.position[i][1] + 0.6f * right[1] - 0.2f * tris.direction[i][1], tris.position[i][2] + 0.6f * right[2] - 0.2f * tris.direction[i][2] - 0.001f); glVertex3f(tris.position[i][0] - 0.6f * right[0] - 0.2f * tris.direction[i][0], tris.position[i][1] - 0.6f * right[0] - 0.2f * tris.direction[i][1], tris.position[i][2] - 0.6f * right[0] - 0.2f * tris.direction[i][2] - 0.001f); } glEnd(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); glBegin(GL_TRIANGLES); if (fCurTime > 219.0f) { float alpha = (fCurTime - 219.0f) * 0.5f; alpha = alpha > 1.0f ? 1.0f : alpha; glColor4f(0.0f, 0.0f, 0.0f, alpha); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glVertex3f(-180.0f, 180.0f, 1.0f); glVertex3f(180.0f, 0.0f, 1.0f); glVertex3f(-180.0f, -180.0f, 1.0f); } glEnd(); glDepthMask(TRUE); // draw credits if (fCurTime > 221.0f) { float alpha = (fCurTime - 221.0f) * 1.0f; alpha = alpha > 1.0f ? 1.0f : alpha; drawQuad(-1.3f, 0.7f, -0.1f, 0.4f, 0.0f, 0.175f, alpha); drawQuad(-0.7f, 1.3f, -0.5f, 0.0f, 0.175f, 0.35f, alpha); } glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); //glColor3ub(200, 100, 50); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // swap buffers wglSwapLayerBuffers(mainDC, WGL_SWAP_MAIN_PLANE); //Sleep(5); } while (msg.message != WM_QUIT && fCurTime < 230.0f && !GetAsyncKeyState(VK_ESCAPE)); // music uninit BASS_ChannelStop(mp3Str); BASS_StreamFree(mp3Str); BASS_Free(); glUnInit(); return msg.wParam; }
void GLStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { CHECK_FOR_ERROR; glPushAttrib(GL_COLOR_BUFFER_BIT); Stroke::MediumType strokeType = iStrokeRep->getMediumType(); // int averageTextureAlpha=0.5; //default value // if (strokeType==OIL_STROKE) // averageTextureAlpha=0.75; // if (strokeType>=NO_BLEND_STROKE) // averageTextureAlpha=1.0; // if (strokeType<0) // { // renderNoTexture(iStrokeRep); // return; // } int i; glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); // glDisable(GL_BLEND); if(strokeType==Stroke::DRY_MEDIUM) { glBlendEquation(GL_MIN); //changed this from GL_MAX in order to work for a black background image instead of white } else if(strokeType==Stroke::OPAQUE_MEDIUM || strokeType==Stroke::DRY_MEDIUM) { glBlendEquation(GL_FUNC_ADD); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_REVERSE_SUBTRACT); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else { glBlendEquation(GL_FUNC_ADD); // glBlendFunc(GL_SRC_ALPHA, GL_ONE); // glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_SUBTRACT); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE); // printf("using opaque\n"); } // glBlendFunc(GL_ONE, GL_ZERO); // glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); //glDisable(GL_BLEND); // glDisable(GL_TEXTURE_1D); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //first texture, basically the only one for lighter strokes glBindTexture(GL_TEXTURE_2D, iStrokeRep->getTextureId()); //glBindTexture(GL_TEXTURE_2D, _textureManager.getPaperTextureIndex()); // TODO: READ BACK PIXEL TRANSFER, PIXEL MAP, MATRICES, ETC. /* // loop over transfer functions and print out glIsEnabled() GLenum funcs[] = { GL_TEXTURE_1D, GL_INDEX_LOGIC_OP, GL_COLOR_LOGIC_OP, GL_COLOR_MATERIAL, GL_COLOR_SUM, GL_COLOR_TABLE, GL_CONVOLUTION_1D, GL_CONVOLUTION_2D, GL_INDEX_LOGIC_OP, GL_MAP1_COLOR_4, GL_MAP1_INDEX, GL_MAP1_TEXTURE_COORD_1, GL_MAP1_TEXTURE_COORD_2, GL_MAP1_TEXTURE_COORD_3, GL_MAP1_TEXTURE_COORD_4, GL_MAP2_INDEX, GL_POST_COLOR_MATRIX_COLOR_TABLE, GL_POST_CONVOLUTION_COLOR_TABLE, GL_SEPARABLE_2D }; for(int i =0; i<17;i++) printf("[(%d) %0X: %s]\n", i, funcs[i], (glIsEnabled(funcs[i]) ? "ENABLED" : "disabled")); GLfloat cmat[16]; glGetFloatv(GL_COLOR_MATRIX, cmat); printf("color matrix: %f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f\n", cmat[0], cmat[1], cmat[2], cmat[3], cmat[4],cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], cmat[12], cmat[13], cmat[14], cmat[15]);*/ // static bool printed = false; // if (!printed) //{ // printf("first point:(%f, %f) ",svRep->point2d()[0], svRep->point2d()[1]); /* printf("glstrokerenderer: (outputWidth = %d, outputHeight = %d)\n", outputWidth, outputHeight); double matrix[16]; glGetDoublev(GL_MODELVIEW_MATRIX, matrix); printf("Modelview= [%f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f]'\n", matrix[0], matrix[1], matrix[2], matrix[3],matrix[4],matrix[5],matrix[6],matrix[7],matrix[8],matrix[9], matrix[10],matrix[11],matrix[12],matrix[13],matrix[14],matrix[15]); glGetDoublev(GL_PROJECTION_MATRIX, matrix); printf("Projection= [%f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f]'\n", matrix[0], matrix[1], matrix[2], matrix[3],matrix[4],matrix[5],matrix[6],matrix[7],matrix[8],matrix[9], matrix[10],matrix[11],matrix[12],matrix[13],matrix[14],matrix[15]); double viewp[4]; glGetDoublev(GL_VIEWPORT, viewp); printf("GL1: Viewport = [%f %f %f %f]\n", viewp[0], viewp[1], viewp[2], viewp[3]); */ // printed = true; // } /* glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glColor4f(1,.5,.2,.5); glBegin(GL_TRIANGLES); glVertex2f(0,0); glVertex2f(100,50); glVertex2f(50,100); glEnd(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); */ // glViewport(0,0,outputWidth, outputHeight); vector<Strip*>& strips = iStrokeRep->getStrips(); for(vector<Strip*>::iterator s=strips.begin(), send=strips.end(); s!=send; ++s){ Strip::vertex_container& vertices = (*s)->vertices(); glBegin(GL_TRIANGLE_STRIP); for(Strip::vertex_container::iterator v=vertices.begin(), vend=vertices.end(); v!=vend; ++v){ StrokeVertexRep * svRep = (*v); Vec3r color = svRep->color(); real alpha = svRep->alpha(); glColor4f(complementColor(color[0]), complementColor(color[1]), complementColor(color[2]), alpha); // glColor4f(1,0,0,1); static bool printed2 = false; /* if (!printed2) { printf("first point: (%f, %f)\n", svRep->point2d()[0], svRep->point2d()[1]); printed2 =true; } */ glTexCoord2f(svRep->texCoord()[0],svRep->texCoord()[1] ); glVertex2f(svRep->point2d()[0], svRep->point2d()[1]); } glEnd(); } // if (strokeType>=NO_BLEND_STROKE) return; // //return; // // //second texture, the complement, for stronger strokes // glBindTexture(GL_TEXTURE_2D, _textureManager.getTextureIndex(2*strokeType+1)); // glBegin(GL_TRIANGLE_STRIP); // for(i=0; i<_sizeStrip; i++) // { // glColor4f(complementColor(_color[i][0]), // complementColor(_color[i][1]), // complementColor(_color[i][2]), _alpha[i]); // glTexCoord2f(_texCoord[i][0],_texCoord[i][1] ); // glVertex2f(_vertex[i][0], _vertex[i][1]); // } // glEnd(); /* double viewp[4]; glGetDoublev(GL_VIEWPORT, viewp); printf("GL2: Viewport = [%f %f %f %f]\n", viewp[0], viewp[1], viewp[2], viewp[3]); */ glPopAttrib(); CHECK_FOR_ERROR; }
//-------------------------------------------------------------- void testApp::draw(){ glPushMatrix(); glTranslatef(ofGetWidth()/2, 0, 0); glRotatef(currentRot, 0, 1, 0); ofSetColor(255); glEnable(GL_DEPTH_TEST); glPointSize(pointSize); if(useTexture) image.getTextureReference().bind(); // new in OF006 if(useSprite) { glEnable(GL_POINT_SPRITE); glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); } switch(drawMode) { case kModeVA: glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, pos); glColorPointer(4, GL_FLOAT, 0, col); glDrawArrays(GL_POINTS, 0, numParticles); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); break; case kModeVBO: glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0]); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 3 * sizeof(float), pos); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1]); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 4 * sizeof(float), col); glColorPointer(4, GL_FLOAT, 0, 0); glDrawArrays(GL_POINTS, 0, numParticles); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); break; case kModeNormal: default: glBegin(GL_POINTS); for(int i=0; i<numParticles; i++) { glColor4f(col[i][0], col[i][1], col[i][2], col[i][3]); glVertex3f(pos[i][0], pos[i][1], pos[i][2]); } glEnd(); } if(useTexture) image.getTextureReference().unbind(); // new in OF006 if(useSprite) { glDisable(GL_POINT_SPRITE); } glDisable(GL_DEPTH_TEST); glPopMatrix(); // black rectangle for text ofSetColor(0); ofRect(0, 0, 200, 200); ofSetColor(255); ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate(), 2) + "\n" + "numParticles: " + ofToString(numParticles) + "\n" + "immediate mode (1): " + (drawMode == kModeNormal ? "X" : "") + "\n" + "useVA (2): " + (drawMode == kModeVA ? "X" : "") + "\n" + "useVBO (3): " + (drawMode == kModeVBO ? "X" : "") + "\n" + "useTexture (t): " + (useTexture ? "X" : "") + "\n" + "useSprite (s): " + (useSprite ? "X" : "") + "\n" + "vsync (v): " + (vsync ? "X" : "") + "\n" + "pointSize []: " + ofToString(pointSize) , 20, 20); }
// ---------------------------------------------------------- // display() Callback function // ---------------------------------------------------------- void display(){ // Clear screen and Z-buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Reset transformations glLoadIdentity(); glRotatef( rotate_x, 1.0, 0.0, 0.0 ); glRotatef( rotate_y, 0.0, 1.0, 0.0 ); // side - BACK glBegin(GL_POLYGON); glColor4f( 1.0, 1.0, 1.0, 1.0); glVertex3f( 0.5, -0.5, 0.5 ); glVertex3f( 0.5, 0.5, 0.5 ); glVertex3f( -0.5, 0.5, 0.5 ); glVertex3f( -0.5, -0.5, 0.5 ); glEnd(); // side - LEFT glBegin(GL_POLYGON); glColor4f( 0.85, 0.85, 0.85, 0.75 ); glVertex3f( -0.5, -0.5, 0.5 ); glVertex3f( -0.5, 0.5, 0.5 ); glVertex3f( -0.5, 0.5, -0.5 ); glVertex3f( -0.5, -0.5, -0.5 ); glEnd(); // side - BOTTOM glBegin(GL_POLYGON); glColor4f( 0.75, 0.75, 0.75, 1.0 ); glVertex3f( 0.5, -0.5, -0.5 ); glVertex3f( 0.5, -0.5, 0.5 ); glVertex3f( -0.5, -0.5, 0.5 ); glVertex3f( -0.5, -0.5, -0.5 ); glEnd(); //Sample Curevs in the coordinates SampleCurves(); //lable units to the axis lables_slot(); lable_curve_Occurrence(); glBegin(GL_POLYGON); glColor4f( 0.8, 0.8, 0.8, 0.25 ); glVertex3f( -0.25, -0.5, 0.5 ); glVertex3f( -0.25, 0.5, 0.5 ); glVertex3f( -0.25, 0.5, -0.5 ); glVertex3f( -0.25, -0.5, -0.5 ); glEnd(); glBegin(GL_POLYGON); glColor4f( 0.8, 0.8, 0.8, 0.25 ); glVertex3f( 0, -0.5, 0.5 ); glVertex3f( 0, 0.5, 0.5 ); glVertex3f( 0, 0.5, -0.5 ); glVertex3f( 0, -0.5, -0.5 ); glEnd(); glBegin(GL_POLYGON); glColor4f( 0.8, 0.8, 0.8, 0.25 ); glVertex3f( 0.25, -0.5, 0.5 ); glVertex3f( 0.25, 0.5, 0.5 ); glVertex3f( 0.25, 0.5, -0.5 ); glVertex3f( 0.25, -0.5, -0.5 ); glEnd(); glBegin(GL_POLYGON); glColor4f( 0.8, 0.8, 0.8, 0.25 ); glVertex3f( 0.5, -0.5, 0.5 ); glVertex3f( 0.5, 0.5, 0.5 ); glVertex3f( 0.5, 0.5, -0.5 ); glVertex3f( 0.5, -0.5, -0.5 ); glEnd(); glBegin(GL_LINES); glColor3f (0.1, 0.1, 0.1); glVertex3f( 0, 0.5, -0.5 ); glVertex3f( 0, -0.5, -0.5 ); glEnd(); glBegin(GL_LINES); glVertex3f( -0.5, -0.5, -0.5 ); glVertex3f( -0.5, 0.5, -0.5 ); glEnd(); glBegin(GL_LINES); glVertex3f( 0.5, -0.5, -0.5 ); glVertex3f( 0.5, 0.5, -0.5 ); glEnd(); glBegin(GL_LINES); glVertex3f( -0.25, -0.5, -0.5 ); glVertex3f( -0.25, 0.5, -0.5 ); glEnd(); glBegin(GL_LINES); glColor3f (0.1, 0.1, 0.1); glVertex3f( 0.25, 0.5, -0.5 ); glVertex3f( 0.25, -0.5, -0.5 ); glEnd(); glFlush(); glutSwapBuffers(); }
void display(UGWindow uwin) { int i; glClear (GL_COLOR_BUFFER_BIT); /* select white for all lines */ glColor4f (1.0, 1.0, 1.0, 1.0); /* in 1st row, 3 lines, each with a different stipple */ //glEnable (GL_LINE_STIPPLE); //glLineStipple (1, 0x0101); /* dotted */ glColor4f(1., 0., 0., 1.); drawOneLine (50.0, 125.0, 150.0, 125.0); //glLineStipple (1, 0x00FF); /* dashed */ glColor4f(0., 1., 0., 1.); drawOneLine (150.0, 125.0, 250.0, 125.0); //glLineStipple (1, 0x1C47); /* dash/dot/dash */ glColor4f(0., 0., 1., 1.); drawOneLine (250.0, 125.0, 350.0, 125.0); glColor4f(1., 1., 1., 1.); /* in 2nd row, 3 wide lines, each with different stipple */ glLineWidth (5.0); //glLineStipple (1, 0x0101); /* dotted */ drawOneLine (50.0, 100.0, 150.0, 100.0); //glLineStipple (1, 0x00FF); /* dashed */ glColor4f(1., 1., 0., 1.); drawOneLine (150.0, 100.0, 250.0, 100.0); //glLineStipple (1, 0x1C47); /* dash/dot/dash */ glColor4f(0., 1., 1., 1.); drawOneLine (250.0, 100.0, 350.0, 100.0); glLineWidth (1.0); glColor4f(1., 0., 1., 1.); /* in 3rd row, 6 lines, with dash/dot/dash stipple */ /* as part of a single connected line strip */ //glLineStipple (1, 0x1C47); /* dash/dot/dash */ #if 0 glBegin (GL_LINE_STRIP); for (i = 0; i < 7; i++) glVertex2f (50.0 + ((GLfloat) i * 50.0), 75.0); glEnd (); #else { GLfloat v[14]; for (i = 0; i < 7; i++) { v[2*i] = 50.0 + ((GLfloat) i * 50.0); v[2*i+1] = 75.0; } glVertexPointer(2, GL_FLOAT, 0, v); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_LINE_STRIP, 0, 7); } #endif glColor4f(1., 1., 1., 1.); /* in 4th row, 6 independent lines with same stipple */ for (i = 0; i < 6; i++) { drawOneLine (50.0 + ((GLfloat) i * 50.0), 50.0, 50.0 + ((GLfloat)(i+1) * 50.0), 50.0); } glColor4f(.8, .8, .8, 1.); /* in 5th row, 1 line, with dash/dot/dash stipple */ /* and a stipple repeat factor of 5 */ //glLineStipple (5, 0x1C47); /* dash/dot/dash */ drawOneLine (50.0, 25.0, 350.0, 25.0); //glDisable (GL_LINE_STIPPLE); glFlush (); ugSwapBuffers(uwin); }
void glColor(ColorARGB color) { glColor4f(color.GetRed()/255.0f, color.GetGreen()/255.0f, color.GetBlue()/255.0f, color.GetAlpha()/255.0f); }
/* Draw given image buffer on a screen using GLSL for display transform */ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter, ColorManagedViewSettings *view_settings, ColorManagedDisplaySettings *display_settings, float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y) { bool force_fallback = false; bool need_fallback = true; /* Early out */ if (ibuf->rect == NULL && ibuf->rect_float == NULL) return; /* Single channel images could not be transformed using GLSL yet */ force_fallback |= ibuf->channels == 1; /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); /* Try to draw buffer using GLSL display transform */ if (force_fallback == false) { int ok; if (ibuf->rect_float) { if (ibuf->float_colorspace) { ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, ibuf->float_colorspace, ibuf->dither, true); } else { ok = IMB_colormanagement_setup_glsl_draw(view_settings, display_settings, ibuf->dither, true); } } else { ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, ibuf->rect_colorspace, ibuf->dither, false); } if (ok) { glColor4f(1.0, 1.0, 1.0, 1.0); if (ibuf->rect_float) { int format = 0; if (ibuf->channels == 3) format = GL_RGB; else if (ibuf->channels == 4) format = GL_RGBA; else BLI_assert(!"Incompatible number of channels for GLSL display"); if (format != 0) { glaDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, format, GL_FLOAT, zoomfilter, ibuf->rect_float, clip_min_x, clip_min_y, clip_max_x, clip_max_y); } } else if (ibuf->rect) { /* ibuf->rect is always RGBA */ glaDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, zoomfilter, ibuf->rect, clip_min_x, clip_min_y, clip_max_x, clip_max_y); } IMB_colormanagement_finish_glsl_draw(); need_fallback = false; } } /* In case GLSL failed or not usable, fallback to glaDrawPixelsAuto */ if (need_fallback) { unsigned char *display_buffer; void *cache_handle; display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle); if (display_buffer) { glaDrawPixelsAuto_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, zoomfilter, display_buffer, clip_min_x, clip_min_y, clip_max_x, clip_max_y); } IMB_display_buffer_release(cache_handle); } }
void Cube3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float glowLevel = getGlowLevel(); Glower* glower = NULL; if (glowLevel > 0.0f) { glower = new Glower(glowLevel); } float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); //glDisable(GL_LIGHTING); // TODO: handle registration point?? glm::vec3 position = getPosition(); glm::vec3 center = getCenter(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); if (_isSolid) { if (_borderSize > 0) { // Draw a cube at a larger size behind the main cube, creating // a border effect. // Disable writing to the depth mask so that the "border" cube will not // occlude the main cube. This means the border could be covered by // overlays that are further back and drawn later, but this is good // enough for the use-case. glDepthMask(GL_FALSE); glPushMatrix(); glColor4f(1.0f, 1.0f, 1.0f, alpha); glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize); Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); glPopMatrix(); glDepthMask(GL_TRUE); } glPushMatrix(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glScalef(dimensions.x, dimensions.y, dimensions.z); Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); glPopMatrix(); } else { glLineWidth(_lineWidth); if (getIsDashedLine()) { glm::vec3 halfDimensions = dimensions / 2.0f; glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z); glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z); glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z); glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z); glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z); glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z); glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z); glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z); drawDashedLine(bottomLeftNear, bottomRightNear); drawDashedLine(bottomRightNear, bottomRightFar); drawDashedLine(bottomRightFar, bottomLeftFar); drawDashedLine(bottomLeftFar, bottomLeftNear); drawDashedLine(topLeftNear, topRightNear); drawDashedLine(topRightNear, topRightFar); drawDashedLine(topRightFar, topLeftFar); drawDashedLine(topLeftFar, topLeftNear); drawDashedLine(bottomLeftNear, topLeftNear); drawDashedLine(bottomRightNear, topRightNear); drawDashedLine(bottomLeftFar, topLeftFar); drawDashedLine(bottomRightFar, topRightFar); } else { glScalef(dimensions.x, dimensions.y, dimensions.z); Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f); } } glPopMatrix(); glPopMatrix(); if (glower) { delete glower; } }
void Particle::Render(Camera* camera, unsigned int i, bool drawAxes) { switch( this->_type ) { case BillBoard: break; case VectorAligned: break; case ScreenFacing: default: { Vector3f particleToCamera = camera->GetPosition()-this->_position; this->_depth = particleToCamera.Length(); Vector3f cameraYAxis = camera->GetEulerRotation()*Vector3f(sin(this->_rotation), cos(this->_rotation), 0.0f); Vector3f localX = cameraYAxis.Cross(particleToCamera); Vector3f localY = particleToCamera.Cross(localX); localX.Normalize(); localY.Normalize(); // Set blend mode switch( this->_blendMode ) { case Subtractive: glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE); break; case Additive: glBlendFunc(GL_SRC_ALPHA, GL_ONE); break; case Normal: default: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; } // Evaluate animators float t = 1.0f-this->_life/this->_maxLife; Vector2f size = this->_size->GetValue(t); // Bind texture if( this->_texture ) { glBindTexture(GL_TEXTURE_2D, this->_texture->GetTextureName()); } // Render glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glBegin(GL_QUADS); glColor4f(this->_color.r, this->_color.g, this->_color.b, this->_color.a); // TODO (Viet Nguyen): Get rid of texture coordinate hacks!!!! glTexCoord2f(0.0f, 0.0f); glVertex3fv((float*) (this->_position+(-localX)*size.width+(-localY)*size.height)); glTexCoord2f(1.0f/4.0f/*!!!!*/, 0.0f); glVertex3fv((float*) (this->_position+localX*size.width+(-localY)*size.height)); glTexCoord2f(1.0f/4.0f/*!!!!*/, 1.0f); glVertex3fv((float*) (this->_position+localX*size.width+localY*size.height)); glTexCoord2f(0.0f, 1.0f); glVertex3fv((float*) (this->_position+(-localX)*size.width+localY*size.height)); glEnd(); // Unbind texture if( this->_texture) { glBindTexture(GL_TEXTURE_2D, 0); } if( drawAxes ) { glBegin(GL_LINES); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glVertex3fv((float*)(this->_position)); glVertex3fv((float*)(this->_position+localX*size.width)); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glVertex3fv((float*)(this->_position)); glVertex3fv((float*)(this->_position+localY*size.height)); glEnd(); } } } }
void CBuilderCAI::DrawCommands(void) { if(uh->limitDgun && owner->unitDef->isCommander) { glColor4f(1.0f, 1.0f, 1.0f, 0.6f); glSurfaceCircle(gs->Team(owner->team)->startPos, uh->dgunRadius, 40); } lineDrawer.StartPath(owner->midPos, cmdColors.start); if (owner->selfDCountdown != 0) { lineDrawer.DrawIconAtLastPos(CMD_SELFD); } CCommandQueue::iterator ci; for (ci = commandQue.begin(); ci != commandQue.end(); ++ci) { switch(ci->id) { case CMD_MOVE: { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.move); break; } case CMD_FIGHT:{ const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.fight); break; } case CMD_PATROL: { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.patrol); break; } case CMD_GUARD: { const CUnit* unit = uh->units[int(ci->params[0])]; if((unit != NULL) && isTrackable(unit)) { const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.guard); } break; } case CMD_RESTORE: { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.restore); lineDrawer.Break(endPos, cmdColors.restore); glSurfaceCircle(endPos, ci->params[3], 20); lineDrawer.RestartSameColor(); break; } case CMD_ATTACK: case CMD_DGUN: { if (ci->params.size() == 1) { const CUnit* unit = uh->units[int(ci->params[0])]; if((unit != NULL) && isTrackable(unit)) { const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack); } } else { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack); } break; } case CMD_RECLAIM: case CMD_RESURRECT: { const float* color = (ci->id == CMD_RECLAIM) ? cmdColors.reclaim : cmdColors.resurrect; if (ci->params.size() == 4) { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, color); lineDrawer.Break(endPos, color); glSurfaceCircle(endPos, ci->params[3], 20); lineDrawer.RestartSameColor(); } else { int id = (int)ci->params[0]; if (id >= MAX_UNITS) { CFeatureSet::iterator it = featureHandler->activeFeatures.find(id - MAX_UNITS); if (it != featureHandler->activeFeatures.end()) { const float3 endPos = (*it)->midPos; lineDrawer.DrawLineAndIcon(ci->id, endPos, color); } } else { const CUnit* unit = uh->units[id]; if((unit != NULL) && (unit != owner) && isTrackable(unit)) { const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam); lineDrawer.DrawLineAndIcon(ci->id, endPos, color); } } } break; } case CMD_REPAIR: case CMD_CAPTURE: { const float* color = (ci->id == CMD_REPAIR) ? cmdColors.repair : cmdColors.capture; if (ci->params.size() == 4) { const float3 endPos(ci->params[0], ci->params[1], ci->params[2]); lineDrawer.DrawLineAndIcon(ci->id, endPos, color); lineDrawer.Break(endPos, color); glSurfaceCircle(endPos, ci->params[3], 20); lineDrawer.RestartSameColor(); } else { const CUnit* unit = uh->units[int(ci->params[0])]; if((unit != NULL) && isTrackable(unit)) { const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam); lineDrawer.DrawLineAndIcon(ci->id, endPos, color); } } break; } case CMD_LOAD_ONTO:{ const CUnit* unit = uh->units[int(ci->params[0])]; lineDrawer.DrawLineAndIcon(ci->id, unit->pos, cmdColors.load); break; } case CMD_WAIT:{ DrawWaitIcon(*ci); break; } case CMD_SELFD:{ lineDrawer.DrawIconAtLastPos(ci->id); break; } } if (ci->id < 0) { map<int, string>::const_iterator boi = buildOptions.find(ci->id); if (boi != buildOptions.end()) { BuildInfo bi; bi.def = unitDefHandler->GetUnitByID(-(ci->id)); if (ci->params.size() == 4) { bi.buildFacing = int(ci->params[3]); } bi.pos = float3(ci->params[0], ci->params[1], ci->params[2]); bi.pos = helper->Pos2BuildPos(bi); cursorIcons.AddBuildIcon(ci->id, bi.pos, owner->team, bi.buildFacing); lineDrawer.DrawLine(bi.pos, cmdColors.build); // draw metal extraction range if (bi.def->extractRange > 0) { lineDrawer.Break(bi.pos, cmdColors.build); glColor4fv(cmdColors.rangeExtract); glSurfaceCircle(bi.pos, bi.def->extractRange, 40); lineDrawer.Restart(); } } } } lineDrawer.FinishPath(); }
void drawScene1(){ glTranslatef(0, 0, -ZOOM - 14); glPushMatrix(); glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0); glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0); glRotatef(-autoRotateY / 20.0, 1, 0, 0); glRotatef(-autoRotateX / 20.0, 0, 1, 0); glRotatef(-90, 0, 0, 1); glLineWidth(1); glPointSize(3); float alpha1 = sin(count/180.0 * M_PI) * .5 + .5; float alpha2 = -sin(count/180.0 * M_PI) * .5 + .5; glPushMatrix(); glScalef(2.8, 2.8, 2.8); glColor4f(0.0, 0.0, 0.0, 0.05); drawGeodesicExtrudedTriangles(&mesh[5]); glPopMatrix(); for(int i = 2; i < maxFrequency; i++){ glPushMatrix(); // glScalef(3 + i/50.0, 3 + i/50.0, 3 + i/50.0); glScalef(3, 3, 3); // glColor4f(0.0, 0.0, 0.0, 0.1 + powf(12 - i,2)/1000.0); glColor4f(0.0, 0.0, 0.0, 0.07); if(i == 3 || i == 6 || i == 9 || i == 12) glColor4f(0.0, 0.0, 0.0, 0.16); // drawGeodesicPoints(&geodesicV[i]); glLineWidth(1); drawGeodesicLines(&geodesicV[i]); // drawGeodesicFaces(&geodesicV[i]); glLineWidth(1); glColor4f(0.0, 0.0, 0.66, 0.15); drawGeodesicVertexNormalLines(&normalsV[i]); glColor4f(0.0, 0.66, 0.0, 0.15); drawGeodesicLineNormalLines(&normalsV[i]); glColor4f(0.66, 0.0, 0.0, 0.15); drawGeodesicFaceNormalLines(&normalsV[i]); glPopMatrix(); } glLineWidth(1); glCullFace(GL_BACK); glColor4f(1.0, 1.0, 1.0, 1.0); glPushMatrix(); glScalef(2.95, 2.95, 2.95); drawPlatonicSolidFaces(3); glPopMatrix(); glCullFace(GL_FRONT); glColor4f(0.0, 0.0, 0.0, 0.1); glPushMatrix(); glScalef(3.9, 3.9, 3.9); drawPlatonicSolidLines(4); glPopMatrix(); glLineWidth(8); glColor4f(0.0, 0.0, 0.0, 0.04); glPushMatrix(); glScalef(3, 3, 3); drawPlatonicSolidLines(3); glPopMatrix(); glLineWidth(4); glColor4f(0.0, 0.0, 0.0, 0.03); glPushMatrix(); glScalef(3.01, 3.01, 3.01); drawPlatonicSolidLines(3); glPopMatrix(); glLineWidth(1); glColor4f(0.0, 0.0, 0.0, 0.02); glPushMatrix(); glScalef(3.02, 3.02, 3.02); drawPlatonicSolidLines(3); glPopMatrix(); glLineWidth(2); glPushMatrix(); glScalef(3, 3, 3); glColor4f(0.0, 0.0, 0.0, 0.3); drawGeodesicVertexNormalLines(&normalsV[2]); glColor4f(0.0, 0.0, 0.0, 0.3); drawGeodesicLineNormalLines(&normalsV[2]); glColor4f(0.0, 0.0, 0.0, 0.3); drawGeodesicFaceNormalLines(&normalsV[2]); glPopMatrix(); glPopMatrix(); }
void CShadowHandler::CreateShadows() { fb.Bind(); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); glDisable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glViewport(0, 0, shadowMapSize, shadowMapSize); // glClearColor(0, 0, 0, 0); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 1, 0, 1, 0, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); const ISkyLight* L = sky->GetLight(); // sun direction is in world-space, invert it sunDirZ = -L->GetLightDir(); sunDirX = (sunDirZ.cross(UpVector)).ANormalize(); sunDirY = (sunDirX.cross(sunDirZ)).ANormalize(); SetShadowMapSizeFactors(); // NOTE: // the xy-scaling factors from CalcMinMaxView do not change linearly // or smoothly with camera movements, creating visible artefacts (eg. // large jumps in shadow resolution) // // therefore, EITHER use "fixed" scaling values such that the entire // map barely fits into the sun's frustum (by pretending it is embedded // in a sphere and taking its diameter), OR variable scaling such that // everything that can be seen by the camera maximally fills the sun's // frustum (choice of projection-style is left to the user and can be // changed at run-time) // // the first option means larger maps will have more blurred/aliased // shadows if the depth buffer is kept at the same size, but no (map) // geometry is ever omitted // // the second option means shadows have higher average resolution, but // become less sharp as the viewing volume increases (through eg.camera // rotations) and geometry can be omitted in some cases // // NOTE: // when DynamicSun is enabled, the orbit is always circular in the xz // plane, instead of elliptical when the map has an aspect-ratio != 1 // const float xyScale = GetShadowProjectionRadius(camera, centerPos, -sunDirZ); const float xScale = xyScale; const float yScale = xyScale; const float zScale = globalRendering->viewRange; shadowMatrix[ 0] = sunDirX.x / xScale; shadowMatrix[ 1] = sunDirY.x / yScale; shadowMatrix[ 2] = sunDirZ.x / zScale; shadowMatrix[ 4] = sunDirX.y / xScale; shadowMatrix[ 5] = sunDirY.y / yScale; shadowMatrix[ 6] = sunDirZ.y / zScale; shadowMatrix[ 8] = sunDirX.z / xScale; shadowMatrix[ 9] = sunDirY.z / yScale; shadowMatrix[10] = sunDirZ.z / zScale; // rotate the target position into sun-space for the translation shadowMatrix[12] = (-sunDirX.dot(centerPos) / xScale); shadowMatrix[13] = (-sunDirY.dot(centerPos) / yScale); shadowMatrix[14] = (-sunDirZ.dot(centerPos) / zScale) + 0.5f; glLoadMatrixf(shadowMatrix.m); // set the shadow-parameter registers // NOTE: so long as any part of Spring rendering still uses // ARB programs at run-time, these lines can not be removed // (all ARB programs share the same environment) glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 16, shadowTexProjCenter.x, shadowTexProjCenter.y, 0.0f, 0.0f); glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 17, shadowTexProjCenter.z, shadowTexProjCenter.z, 0.0f, 0.0f); glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 18, shadowTexProjCenter.w, shadowTexProjCenter.w, 0.0f, 0.0f); if (globalRendering->haveGLSL) { for (int i = 0; i < SHADOWGEN_PROGRAM_LAST; i++) { shadowGenProgs[i]->Enable(); shadowGenProgs[i]->SetUniform4fv(0, &shadowTexProjCenter.x); shadowGenProgs[i]->Disable(); } } if (L->GetLightIntensity() > 0.0f) { // move view into sun-space const float3 oldup = camera->up; camera->right = sunDirX; camera->up = sunDirY; DrawShadowPasses(); camera->up = oldup; } glShadeModel(GL_SMOOTH); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // we do this later to save render context switches (this is one of the slowest opengl operations!) // fb.Unbind(); // glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY); }
void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea, const Rectangle<int>& anchorPosAndTextureSize, const int contextWidth, const int contextHeight) { if (contextWidth <= 0 || contextHeight <= 0) return; JUCE_CHECK_OPENGL_ERROR glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); #if JUCE_USE_OPENGL_SHADERS if (areShadersAvailable()) { struct OverlayShaderProgram : public ReferenceCountedObject { OverlayShaderProgram (OpenGLContext& context) : program (context), builder (program), params (program) {} static const OverlayShaderProgram& select (OpenGLContext& context) { static const char programValueID[] = "juceGLComponentOverlayShader"; OverlayShaderProgram* program = static_cast <OverlayShaderProgram*> (context.getAssociatedObject (programValueID)); if (program == nullptr) { program = new OverlayShaderProgram (context); context.setAssociatedObject (programValueID, program); } program->program.use(); return *program; } struct ProgramBuilder { ProgramBuilder (OpenGLShaderProgram& prog) { prog.addShader ("attribute " JUCE_HIGHP " vec2 position;" "uniform " JUCE_HIGHP " vec2 screenSize;" "varying " JUCE_HIGHP " vec2 pixelPos;" "void main()" "{" "pixelPos = position;" JUCE_HIGHP " vec2 scaled = position / (0.5 * screenSize.xy);" "gl_Position = vec4 (scaled.x - 1.0, 1.0 - scaled.y, 0, 1.0);" "}", GL_VERTEX_SHADER); prog.addShader ("uniform sampler2D imageTexture;" "uniform " JUCE_HIGHP " float textureBounds[4];" "varying " JUCE_HIGHP " vec2 pixelPos;" "void main()" "{" JUCE_HIGHP " vec2 texturePos = (pixelPos - vec2 (textureBounds[0], textureBounds[1]))" "/ vec2 (textureBounds[2], textureBounds[3]);" "gl_FragColor = texture2D (imageTexture, vec2 (texturePos.x, 1.0 - texturePos.y));" "}", GL_FRAGMENT_SHADER); prog.link(); } }; struct Params { Params (OpenGLShaderProgram& prog) : positionAttribute (prog, "position"), screenSize (prog, "screenSize"), imageTexture (prog, "imageTexture"), textureBounds (prog, "textureBounds") {} void set (const float targetWidth, const float targetHeight, const Rectangle<float>& bounds) const { const GLfloat m[] = { bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() }; textureBounds.set (m, 4); imageTexture.set (0); screenSize.set (targetWidth, targetHeight); } OpenGLShaderProgram::Attribute positionAttribute; OpenGLShaderProgram::Uniform screenSize, imageTexture, textureBounds; }; OpenGLShaderProgram program; ProgramBuilder builder; Params params; }; const GLshort left = (GLshort) targetClipArea.getX(); const GLshort top = (GLshort) targetClipArea.getY(); const GLshort right = (GLshort) targetClipArea.getRight(); const GLshort bottom = (GLshort) targetClipArea.getBottom(); const GLshort vertices[] = { left, bottom, right, bottom, left, top, right, top }; const OverlayShaderProgram& program = OverlayShaderProgram::select (*this); program.params.set ((float) contextWidth, (float) contextHeight, anchorPosAndTextureSize.toFloat()); extensions.glVertexAttribPointer (program.params.positionAttribute.attributeID, 2, GL_SHORT, GL_FALSE, 4, vertices); extensions.glEnableVertexAttribArray (program.params.positionAttribute.attributeID); JUCE_CHECK_OPENGL_ERROR glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); extensions.glUseProgram (0); extensions.glDisableVertexAttribArray (program.params.positionAttribute.attributeID); } #if JUCE_USE_OPENGL_FIXED_FUNCTION else #endif #endif #if JUCE_USE_OPENGL_FIXED_FUNCTION { glEnable (GL_SCISSOR_TEST); glScissor (targetClipArea.getX(), contextHeight - targetClipArea.getBottom(), targetClipArea.getWidth(), targetClipArea.getHeight()); JUCE_CHECK_OPENGL_ERROR glColor4f (1.0f, 1.0f, 1.0f, 1.0f); glDisableClientState (GL_COLOR_ARRAY); glDisableClientState (GL_NORMAL_ARRAY); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_TEXTURE_COORD_ARRAY); OpenGLHelpers::prepareFor2D (contextWidth, contextHeight); JUCE_CHECK_OPENGL_ERROR const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f }; glTexCoordPointer (2, GL_FLOAT, 0, textureCoords); const GLshort left = (GLshort) anchorPosAndTextureSize.getX(); const GLshort right = (GLshort) anchorPosAndTextureSize.getRight(); const GLshort top = (GLshort) (contextHeight - anchorPosAndTextureSize.getY()); const GLshort bottom = (GLshort) (contextHeight - anchorPosAndTextureSize.getBottom()); const GLshort vertices[] = { left, bottom, right, bottom, left, top, right, top }; glVertexPointer (2, GL_SHORT, 0, vertices); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); glDisable (GL_SCISSOR_TEST); } #endif JUCE_CHECK_OPENGL_ERROR }
static void setup_legacy_const_attribute (CoglContext *ctx, CoglPipeline *pipeline, CoglAttribute *attribute) { #ifdef COGL_PIPELINE_PROGEND_GLSL if (attribute->name_state->name_id == COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY) { if (ctx->private_feature_flags & COGL_PRIVATE_FEATURE_GL_PROGRAMMABLE) setup_generic_const_attribute (ctx, pipeline, attribute); } else #endif { float vector[4] = { 0, 0, 0, 1 }; float *boxed = attribute->d.constant.boxed.v.float_value; int n_components = attribute->d.constant.boxed.size; int i; for (i = 0; i < n_components; i++) vector[i] = boxed[i]; switch (attribute->name_state->name_id) { case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY: GE (ctx, glColor4f (vector[0], vector[1], vector[2], vector[3])); break; case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY: GE (ctx, glNormal3f (vector[0], vector[1], vector[2])); break; case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY: { int layer_number = attribute->name_state->layer_number; const CoglPipelineGetLayerFlags flags = COGL_PIPELINE_GET_LAYER_NO_CREATE; CoglPipelineLayer *layer = _cogl_pipeline_get_layer_with_flags (pipeline, layer_number, flags); if (layer) { int unit = _cogl_pipeline_layer_get_unit_index (layer); GE (ctx, glClientActiveTexture (GL_TEXTURE0 + unit)); GE (ctx, glMultiTexCoord4f (vector[0], vector[1], vector[2], vector[3])); } break; } case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY: GE (ctx, glVertex4f (vector[0], vector[1], vector[2], vector[3])); break; default: g_warn_if_reached (); } } }
void CSm3GroundDrawer::Draw(bool drawWaterReflection,bool drawUnitReflection,unsigned int overrideVP) { if(drawUnitReflection || drawWaterReflection) return; terrain::RenderContext *currc; if (drawWaterReflection) { if (!reflectrc) { reflectrc = tr->AddRenderContext(&reflectCam, true); tr->Update(); } SpringCamToTerrainCam(*camera, reflectCam); currc = reflectrc; } else currc = rc; tr->SetShaderParams(gs->sunVector, currc->cam->pos); if (shadowHandler->drawShadows) { terrain::ShadowMapParams params; shadowHandler->GetShadowMapSizeFactors (params.f_a, params.f_b); params.mid [0] = shadowHandler->xmid; params.mid [1] = shadowHandler->ymid; params.shadowMap = shadowHandler->shadowTexture; for (int a=0;a<16;a++) params.shadowMatrix[a] = shadowHandler->shadowMatrix[a]; tr->SetShadowParams (¶ms); } tr->SetActiveContext (currc); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glColor4f(1.0f,1.0f,1.0f,1.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION,gs->sunVector4); float d[4]={0.0f,0.0f,0.0f,1.0f}; for (int a=0;a<3;a++) d[a]=map->sunColor[a]; glLightfv(GL_LIGHT0, GL_DIFFUSE, d); for (int a=0;a<3;a++) d[a]=map->ambientColor[a]; glLightfv(GL_LIGHT0, GL_AMBIENT, d); for (int a=0;a<3;a++) d[a]=map->specularColor[a]; glLightfv (GL_LIGHT0, GL_SPECULAR, d); for (int a=0;a<4;a++) d[a]=0.0f; glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, d); const float zero[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightModelfv (GL_LIGHT_MODEL_AMBIENT, zero); glDisable(GL_LIGHT1); glEnable(GL_LIGHT0); glEnable(GL_RESCALE_NORMAL); // glLightfv (GL_LIGHT0, GL_SPOT_DIRECTION,dir.getf()); // glLightf (GL_LIGHT0, GL_SPOT_CUTOFF, 90.0f); /* const float ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; const float diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); const float md[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, md); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, md); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);*/ ///////////////////// tr->Draw (); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); if (drawMode != drawNormal) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0f,- 10.0f); glColor4f(1.0f,1.0f,1.0f,0.5f); tr->DrawOverlayTexture (infoTex); glDisable(GL_POLYGON_OFFSET_FILL); glDepthMask(GL_FALSE); glDisable(GL_BLEND); } glFrontFace(GL_CCW); glDisable(GL_CULL_FACE); glColor3ub(255,255,255); DrawObjects(drawWaterReflection, drawUnitReflection); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }
static void redrawTheWindow() { float const aspect = (float)width / (float)height; static float a=0; static float b=0; static float c=0; glDrawBuffer(GL_BACK); glViewport(0, 0, width, height); // Clear with alpha = 0.0, i.e. full transparency glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-aspect, aspect, -1, 1, 2.5, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); #if 0 glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif glLightfv(GL_LIGHT0, GL_POSITION, light0_dir); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color); glLightfv(GL_LIGHT1, GL_POSITION, light1_dir); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color); glLightfv(GL_LIGHT2, GL_POSITION, light2_dir); glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_color); glTranslatef(0., 0., -5.); glRotatef(a, 1, 0, 0); glRotatef(b, 0, 1, 0); glRotatef(c, 0, 0, 1); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glColor4f(1., 1., 1., 0.5); glCullFace(GL_FRONT); draw_cube(); glCullFace(GL_BACK); draw_cube(); a = fmod(a+0.1, 360.); b = fmod(b+0.5, 360.); c = fmod(c+0.25, 360.); glXSwapBuffers(Xdisplay, glX_window_handle); }
void W_slider::Draw() { glTranslated(posx, posy, 0); // Black outlining /*glColor4f(0.3f,0.3f,0.3f,0.5f); glBegin(GL_POLYGON); glVertex2d(6, 0); glVertex2d(width-6, 0); glVertex2d(width-2, -1); glVertex2d(width-1, -3); glVertex2d(width, -6); glVertex2d(width, -height+6); glVertex2d(width-1, -height+2); glVertex2d(width-3, -height+1); glVertex2d(width-6, -height); glVertex2d(6, -height); glVertex2d(2, -height+1); glVertex2d(1, -height+3); glVertex2d(0, -height+6); glVertex2d(0, -6); glVertex2d(1, -2); glVertex2d(3, -1); glVertex2d(6, 0); glEnd();*/ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Fill // glColor4f(1.0f, 1.0f, 1.0f,0.6f); // glColor4f(0.64f, 0.59f, 0.53f,1.0f); // glColor4f(0.75f, 0.75f, 0.75f,1.0f); // glColor4f(1.0f, 1.0f, 1.0f,0.4f); glColor4f(1.0f, 1.0f, 1.0f,0.4f); glBegin(GL_POLYGON); glVertex2d(6, -1); glVertex2d(width-6, -1); glVertex2d(width-2, -2); glVertex2d(width-1, -4); glVertex2d(width-1, -6); glVertex2d(width-1, -height+6); glVertex2d(width-2, -height+2); glVertex2d(width-4, -height+1); glVertex2d(width-6, -height+1); glVertex2d(6, -height+1); glVertex2d(2, -height+2); glVertex2d(1, -height+4); glVertex2d(1, -height+5); glVertex2d(1, -7); glVertex2d(2, -2); glVertex2d(4, -1); glVertex2d(6, 0); glEnd(); // draw a stripe in the buttons to indicate the current value glBegin(GL_QUADS); glColor4f(r,g,b,0.3f); if (vertical) { glVertex2d(0,(value-from)/(to-from)*height-height); glVertex2d(width,(value-from)/(to-from)*height-height); if (barSize){ glVertex2d(width,(value+barSize-from)/(to-from)*height-height); glVertex2d(0,(value+barSize-from)/(to-from)*height-height); } else{ glVertex2d(0,-height+1); glVertex2d(0, -1); } }else{ glVertex2d((value-from)/(to-from)*width,-1); glVertex2d((value-from)/(to-from)*width,-height+1); if (barSize){ glVertex2d((value+barSize-from)/(to-from)*width,-height+1); glVertex2d((value+barSize-from)/(to-from)*width, -1); } else{ glVertex2d(0,-height+1); glVertex2d(0, -1); } } glEnd(); /* glBegin(GL_QUADS); glColor4f(r,g,b,0.3f); glVertex2d((value-from)/(to-from)*width,-1); glVertex2d((value-from)/(to-from)*width,-height+1); if (barSize){ glVertex2d((value+barSize-from)/(to-from)*width,-height+1); glVertex2d((value+barSize-from)/(to-from)*width, -1); } else{ glVertex2d(0,-height+1); glVertex2d(0, -1); } glEnd(); }*/ // draw the border glColor4f(1.0f,1.0f,1.0f,0.7f); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textures.slider.texID); glBegin(GL_QUADS); glTexCoord2f(0.0f,1.0f); glVertex2d(0, 0); glTexCoord2f(0.25f,1.0f); glVertex2d(8, 0); glTexCoord2f(0.25,0.75f); glVertex2d(8, -8); glTexCoord2f(0.0f,0.75f); glVertex2d(0, -8); glTexCoord2f(0.49f,1.0f); glVertex2d(8, 0); glTexCoord2f(0.51f,1.0f); glVertex2d(width-8, 0); glTexCoord2f(0.51f,0.75f); glVertex2d(width-8, -8); glTexCoord2f(0.49f,0.75f); glVertex2d(8, -8); glTexCoord2f(0.75f,1.0f); glVertex2d(width-8, 0); glTexCoord2f(1.00f,1.0f); glVertex2d(width, 0); glTexCoord2f(1.00f,0.75f); glVertex2d(width, -8); glTexCoord2f(0.75f,0.75f); glVertex2d(width-8, -8); glTexCoord2f(0.75f,0.75f); glVertex2d(width-8, -8); glTexCoord2f(1.00f,0.75f); glVertex2d(width, -8); glTexCoord2f(1.00f,0.25f); glVertex2d(width, -height+8); glTexCoord2f(0.75f,0.25f); glVertex2d(width-8, -height+8); glTexCoord2f(0.75f,0.25f); glVertex2d(width-8, -height+8); glTexCoord2f(1.00f,0.25f); glVertex2d(width, -height+8); glTexCoord2f(1.00f,0.00f); glVertex2d(width, -height); glTexCoord2f(0.75f,0.00f); glVertex2d(width-8, -height); glTexCoord2f(0.25f,0.25f); glVertex2d(8, -height+8); glTexCoord2f(0.75f,0.25f); glVertex2d(width-8, -height+8); glTexCoord2f(0.75,0.00f); glVertex2d(width-8, -height); glTexCoord2f(0.25f,0.00f); glVertex2d(8, -height); glTexCoord2f(0.0f,0.25f); glVertex2d(0, -height+8); glTexCoord2f(0.25f,0.25f); glVertex2d(8, -height+8); glTexCoord2f(0.25f,0.00f); glVertex2d(8, -height); glTexCoord2f(0.0f,0.00f); glVertex2d(0, -height); glTexCoord2f(0.00f,0.75f); glVertex2d(0, -8); glTexCoord2f(0.25f,0.75f); glVertex2d(8, -8); glTexCoord2f(0.25f,0.25f); glVertex2d(8, -height+8); glTexCoord2f(0.00f,0.25f); glVertex2d(0, -height+8); glEnd(); glBindTexture(GL_TEXTURE_2D, textures.specular.texID); glColor4f(1.0f,1.0f,1.0f,0.6f); glBegin(GL_QUADS); glTexCoord2f(0.0f,1.0f); glVertex2d(0, 0); glTexCoord2f(1.0f,1.0f); glVertex2d(width, 0); glTexCoord2f(1.0f,0.0f); glVertex2d(width,-height); glTexCoord2f(0.0f,0.0f); glVertex2d(0, -height); glEnd(); glDisable(GL_TEXTURE_2D); glTranslated(-posx,-posy,0); glColor4f(0.5f,0.5f,0.5f,0.5f); UI_widget::Draw(); }
void DrawCreditsText (double time_step){ double w = (double)param.x_resolution; double h = (double)param.y_resolution; double offs = 0.0; int i; TColor col; if (moving) y_offset += time_step * 30; for (i=0; i < numCredits; i++) { offs = h - 100 - y_offset + CreditList[i].offs; col = ( CreditList[i].col == 0 ? colWhite : colDYell ); FT.SetColor (col); FT.AutoSizeN (CreditList[i].size); FT.DrawString (-1, (int)offs, CreditList[i].text); } glDisable (GL_TEXTURE_2D); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_COLOR_ARRAY); const GLfloat col1[] = { bgcol.r, bgcol.g, bgcol.b, bgcol.a, bgcol.r, bgcol.g, bgcol.b, bgcol.a, bgcol.r, bgcol.g, bgcol.b, bgcol.a, bgcol.r, bgcol.g, bgcol.b, bgcol.a, }; const GLfloat col2[] = { bgcol.r, bgcol.g, bgcol.b, bgcol.a, bgcol.r, bgcol.g, bgcol.b, bgcol.a, bgcol.r, bgcol.g, bgcol.b, 0, bgcol.r, bgcol.g, bgcol.b, 0 }; const GLfloat vtx1[] = { 0, 0, w, 0, w, BOTT_Y, 0, BOTT_Y }; const GLfloat vtx2[] = { 0, BOTT_Y, w, BOTT_Y, w, BOTT_Y + 30, 0, BOTT_Y + 30 }; glColorPointer(4, GL_FLOAT, 0, col1); glVertexPointer(2, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN,0,4); glColorPointer(4, GL_FLOAT, 0, col2); glVertexPointer(2, GL_FLOAT, 0, vtx2); glDrawArrays(GL_TRIANGLE_FAN,0,4); const GLfloat vtx3[] = { 0, h - TOP_Y, w, h - TOP_Y, w, h, 0, h }; const GLfloat vtx4[] = { w, h - TOP_Y, 0, h - TOP_Y, 0, h - TOP_Y - 30, w, h - TOP_Y - 30 }; glColorPointer(4, GL_FLOAT, 0, col1); glVertexPointer(2, GL_FLOAT, 0, vtx3); glDrawArrays(GL_TRIANGLE_FAN,0,4); glColorPointer(4, GL_FLOAT, 0, col2); glVertexPointer(2, GL_FLOAT, 0, vtx4); glDrawArrays(GL_TRIANGLE_FAN,0,4); glColor4f (1, 1, 1, 1 ); glDisableClientState (GL_COLOR_ARRAY); glDisableClientState (GL_VERTEX_ARRAY); glEnable (GL_TEXTURE_2D); if (offs < TOP_Y) y_offset = 0; }
// Draw function void Quad::drawFunc() { bool ok = false; // Draw with texture unsigned int nv = getNumberOfVertices(); if (nv > 3) { if (!strip) { int rem = nv % 4; if (rem != 0) std::cerr << "Quad::drawFunc() - Quad have to have multiple of 4 vertices, add or remove vertices!!" << std::endl; else { BEGIN_DLIST glBegin(GL_QUADS); ok = true; } } else { int rem = nv % 2; if (rem != 0) std::cerr << "Quad::drawFunc() - quad strips have to have multiple of 2 vertices, add or remove vertices!!" << std::endl; else { BEGIN_DLIST glBegin(GL_QUAD_STRIP); ok = true; } } if (ok) { // get our regular vertices here const osg::Vec3* v = getVertices(); unsigned int ntc = getNumberOfTextureCoords(); // draw with texture if (ntc > 0 && hasTexture()) { const osg::Vec2* texCoord = getTextureCoord(); unsigned int tc = 0; // texture count for (unsigned int i = 0; i < nv; i++) { // add our textures coordinates if (tc < ntc) lcTexCoord2v(texCoord[tc++].ptr()); // now our vertices lcVertex3v( v[i].ptr() ); } } // draw without texture else { // get our color gradient and apply it (if we have one) ColorGradient* colGradient = dynamic_cast<ColorGradient*>(getColor()); for (unsigned int i = 0; i < nv; i++) { if (colGradient != 0) { Basic::Color* col = colGradient->getColorByIdx(i+1); if (col != 0) glColor4f(static_cast<GLfloat>(col->red()), static_cast<GLfloat>(col->green()), static_cast<GLfloat>(col->blue()), static_cast<GLfloat>(col->alpha())); } // now add our vertex lcVertex3v( v[i].ptr() ); } } glEnd(); END_DLIST } } else std::cerr << "Quad::drawFunc() - Quad or QuadStrip needs at least 4 vertices!" << std::endl;
void CShareBox::Draw() { const float alpha = std::max(guiAlpha, 0.4f); const float mx = MouseX(mouse->lastx); const float my = MouseY(mouse->lasty); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); // Large Box glColor4f(0.2f, 0.2f, 0.2f, alpha); DrawBox(box); // ok Box on mouse over if (InBox(mx, my, box + okBox)) { glColor4f(0.7f, 0.2f, 0.2f, alpha); DrawBox(box + okBox); } // apply Box on mouse over if (InBox(mx, my, box + applyBox)) { glColor4f(0.7f, 0.2f, 0.2f, alpha); DrawBox(box + applyBox); } // cancel Box on mouse over if (InBox(mx, my, box + cancelBox)) { glColor4f(0.7f,0.2f,0.2f,alpha); DrawBox(box + cancelBox); } glColor4f(0.2f, 0.2f, 0.2f, alpha); DrawBox(box + teamBox); if (hasScroll) { glColor4f(0.1f, 0.1f, 0.1f, alpha); DrawBox(box + scrollbarBox); float sz = scrollbarBox.y2 - scrollbarBox.y1; float tsz = sz / (float)(MAX_SHARE_TEAMS); float psz = tsz * (float)numTeamsDisp; scrollBox.y2 = scrollbarBox.y2 - startTeam * tsz; scrollBox.y1 = scrollBox.y2 - psz; glColor4f(0.8f, 0.8f, 0.8f, alpha); DrawBox(box + scrollBox); } if (InBox(mx, my, box + unitBox)) { glColor4f(0.7f, 0.2f, 0.2f, alpha); } else { glColor4f(0.2f, 0.2f, 0.2f, alpha); } DrawBox(box + unitBox); glColor4f(0.8f, 0.8f, 0.9f, 0.7f); DrawBox(box + metalBox); glColor4f(0.9f, 0.9f, 0.2f, 0.7f); DrawBox(box + energyBox); //draw share indicators in metal/energy bars glColor4f(0.9f, 0.2f, 0.2f, 0.7f); ContainerBox metalShareBox; metalShareBox.x1 = metalBox.x1 + metalShare * (metalBox.x2 - metalBox.x1) - 0.005f; metalShareBox.x2 = metalShareBox.x1 + 0.01f; metalShareBox.y1 = metalBox.y1 - 0.005f; metalShareBox.y2 = metalBox.y2 + 0.005f; DrawBox(box + metalShareBox); ContainerBox energyShareBox; energyShareBox.x1 = energyBox.x1 + energyShare * (energyBox.x2 - energyBox.x1) - 0.005f; energyShareBox.x2 = energyShareBox.x1 + 0.01f; energyShareBox.y1 = energyBox.y1 - 0.005f; energyShareBox.y2 = energyBox.y2 + 0.005f; DrawBox(box + energyShareBox); // show that share units is selected if (shareUnits) { //DrawBox(box + unitBox); glLineWidth(3); glBegin(GL_LINE_STRIP); glVertex2f(box.x1 + unitBox.x1 + 0.01f, box.y1 + unitBox.y1 + 0.025f); glVertex2f(box.x1 + unitBox.x1 + 0.02f, box.y1 + unitBox.y1 + 0.01f); glVertex2f(box.x1 + unitBox.x1 + 0.03f, box.y1 + unitBox.y1 + 0.04f); glEnd(); glLineWidth(1); } font->Begin(); font->glPrint(box.x1 + (okBox.x1 + okBox.x2) * 0.5f, box.y1 + (okBox.y1 + okBox.y2) * 0.5f, 1, FONT_CENTER | FONT_VCENTER | FONT_SCALE | FONT_NORM, "Ok"); font->glPrint(box.x1 + (applyBox.x1 + applyBox.x2) * 0.5f, box.y1 + (applyBox.y1 + applyBox.y2) * 0.5f, 1, FONT_CENTER | FONT_VCENTER | FONT_SCALE | FONT_NORM, "Apply"); font->glPrint(box.x1 + (cancelBox.x1 + cancelBox.x2) * 0.5f, box.y1 + (cancelBox.y1 + cancelBox.y2) * 0.5f, 1, FONT_CENTER | FONT_VCENTER | FONT_SCALE | FONT_NORM, "Cancel"); font->glPrint(box.x1 + 0.06f, box.y1 + 0.085f, 0.7f, FONT_SCALE | FONT_NORM, "Share selected units"); font->SetTextColor(1, 1, 0.4f, 0.8f); font->glPrint(box.x1 + 0.01f, box.y1 + 0.16f, 0.7f, FONT_SCALE | FONT_NORM, "Share Energy"); font->SetTextColor(1, 1, 1, 0.8f); font->glFormat(box.x1 + 0.25f, box.y1 + 0.12f, 0.7f, FONT_SCALE | FONT_NORM, "%.0f", float(teamHandler->Team(gu->myTeam)->energy)); font->glFormat(box.x1 + 0.14f, box.y1 + 0.12f, 0.7f, FONT_SCALE | FONT_NORM, "%.0f", teamHandler->Team(gu->myTeam)->energy * energyShare); font->SetTextColor(0.8f, 0.8f, 0.9f, 0.8f); font->glPrint(box.x1 + 0.01f, box.y1 + 0.22f, 0.7f, FONT_SCALE | FONT_NORM, "Share Metal"); font->SetTextColor(1, 1, 1, 0.8f); font->glFormat(box.x1 + 0.25f, box.y1 + 0.18f, 0.7f, FONT_SCALE | FONT_NORM, "%.0f", float(teamHandler->Team(gu->myTeam)->metal)); font->glFormat(box.x1 + 0.14f, box.y1 + 0.18f, 0.7f, FONT_SCALE | FONT_NORM, "%.0f", teamHandler->Team(gu->myTeam)->metal * metalShare); int teamPos = 0; for(int team = startTeam; team < MAX_SHARE_TEAMS && teamPos < numTeamsDisp; ++team, ++teamPos) { int actualTeam = team; if (team >= gu->myTeam) { actualTeam++; } const float alpha = (shareTeam == actualTeam) ? 0.8f : 0.4f; std::string teamName; if (teamHandler->Team(actualTeam)->leader >= 0) { teamName = playerHandler->Player(teamHandler->Team(actualTeam)->leader)->name; } else { teamName = "Uncontrolled"; } std::string ally, dead; if (teamHandler->Ally(gu->myAllyTeam, teamHandler->AllyTeam(actualTeam))) { font->SetTextColor(0.5f, 1.0f, 0.5f, alpha); ally = " <Ally>"; } else { font->SetTextColor(1.0f, 0.5f, 0.5f, alpha); ally = " <Enemy>"; } if (teamHandler->Team(actualTeam)->isDead) { font->SetTextColor(0.5f, 0.5f, 1.0f, alpha); dead = " <Dead>"; } if (actualTeam == teamHandler->GaiaTeamID()) { font->SetTextColor(0.8f, 0.8f, 0.8f, alpha); teamName = "Gaia"; ally = " <Gaia>"; } font->glFormat(box.x1 + teamBox.x1 + 0.002f, box.y1 + teamBox.y2 - 0.025f - teamPos * 0.025f, 0.7f, FONT_SCALE | FONT_NORM, "Team%i (%s)%s%s", actualTeam, teamName.c_str(), ally.c_str(), dead.c_str()); } font->End(); glEnable(GL_TEXTURE_2D); }
/* ============= R_Mirror ============= */ void R_Mirror (void) { float d; msurface_t *s; entity_t *ent; if (!mirror) return; memcpy (r_base_world_matrix, r_world_matrix, sizeof(r_base_world_matrix)); d = DotProduct (r_refdef.vieworg, mirror_plane->normal) - mirror_plane->dist; VectorMA (r_refdef.vieworg, -2*d, mirror_plane->normal, r_refdef.vieworg); d = DotProduct (vpn, mirror_plane->normal); VectorMA (vpn, -2*d, mirror_plane->normal, vpn); r_refdef.viewangles[0] = -asin (vpn[2])/M_PI*180; r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0])/M_PI*180; r_refdef.viewangles[2] = -r_refdef.viewangles[2]; ent = &cl_entities[cl.viewentity]; if (cl_numvisedicts < MAX_VISEDICTS) { cl_visedicts[cl_numvisedicts] = ent; cl_numvisedicts++; } gldepthmin = 0.5; gldepthmax = 1; glDepthRange (gldepthmin, gldepthmax); glDepthFunc (GL_LEQUAL); R_RenderScene (); R_DrawWaterSurfaces (); gldepthmin = 0; gldepthmax = 0.5; glDepthRange (gldepthmin, gldepthmax); glDepthFunc (GL_LEQUAL); // blend on top glEnable (GL_BLEND); glMatrixMode(GL_PROJECTION); if (mirror_plane->normal[2]) glScalef (1,-1,1); else glScalef (-1,1,1); glCullFace(GL_FRONT); glMatrixMode(GL_MODELVIEW); glLoadMatrixf (r_base_world_matrix); glColor4f (1,1,1,r_mirroralpha.value); s = cl.worldmodel->textures[mirrortexturenum]->texturechain; for ( ; s ; s=s->texturechain) R_RenderBrushPoly (s); cl.worldmodel->textures[mirrortexturenum]->texturechain = NULL; glDisable (GL_BLEND); glColor4f (1,1,1,1); }
void drawGlow(Camera *pCam, Player *pTarget, PlayerVisual *pV, Visual *d, float dim) { float mat[4*4]; float alpha, dist; float x, y; glPushMatrix(); getPositionFromData(&x, &y, pTarget->data); glTranslatef(x, y, 0); glDepthMask(GL_FALSE); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glGetFloatv(GL_MODELVIEW_MATRIX, mat); mat[0] = mat[5] = mat[10] = 1.0; mat[1] = mat[2] = 0.0; mat[4] = mat[6] = 0.0; mat[8] = mat[9] = 0.0; glLoadMatrixf(mat); { vec3 v; v.v[0] = x - pCam->cam[0]; v.v[1] = y - pCam->cam[1]; v.v[2] = 0 - pCam->cam[2]; dist = vec3Length(&v); } { const float fMin = 30; const float fMax = 100; if(dist < fMin) alpha = 0.0f; else if(dist > fMax) alpha = 1.0f; else alpha = (dist - fMin) / (fMax - fMin); // printf("dist: %.2f, alpha: %.2f\n", dist, alpha); } glBegin(GL_TRIANGLE_FAN); glColor4f(pV->pColorDiffuse[0], pV->pColorDiffuse[1], pV->pColorDiffuse[2], alpha); glVertex3f(0,TRAIL_HEIGHT/2, 0); glColor4f(0,0,0,0.0); glVertex3d(dim*cos(-0.2*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(-0.2*3.1415/5.0), 0); glVertex3d(dim*cos(1.0*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(1.0*3.1415/5.0), 0); glVertex3d(dim*cos(2.0*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(2.0*3.1415/5.0), 0); glVertex3d(dim*cos(3.0*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(3.0*3.1415/5.0), 0); glVertex3d(dim*cos(4.0*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(4.0*3.1415/5.0), 0); glVertex3d(dim*cos(5.2*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(5.2*3.1415/5.0), 0); glEnd(); polycount += 5; glBegin(GL_TRIANGLES); glColor4f(pV->pColorDiffuse[0], pV->pColorDiffuse[1], pV->pColorDiffuse[2], alpha); glVertex3f(0,TRAIL_HEIGHT/2, 0); glColor4f(0,0,0,0.0); glVertex3f(0,-TRAIL_HEIGHT/4,0); glVertex3d(dim*cos(-0.2f*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(-0.2*3.1415/5.0), 0); glColor4f(pV->pColorDiffuse[0], pV->pColorDiffuse[1], pV->pColorDiffuse[2], alpha); glVertex3f(0,TRAIL_HEIGHT/2, 0); glColor4f(0,0,0,0.0); glVertex3d(dim*cos(5.2*3.1415/5.0), TRAIL_HEIGHT/2+dim*sin(5.2*3.1415/5.0), 0); glVertex3f(0,-TRAIL_HEIGHT/4,0); glEnd(); polycount += 3; glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glPopMatrix(); }
void SimpleOpenGL2App::drawText3D( const char* txt, float worldPosX, float worldPosY, float worldPosZ, float size1) { saveOpenGLState(gApp2->m_renderer->getScreenWidth(),gApp2->m_renderer->getScreenHeight()); float viewMat[16]; float projMat[16]; CommonCameraInterface* cam = gApp2->m_renderer->getActiveCamera(); cam->getCameraViewMatrix(viewMat); cam->getCameraProjectionMatrix(projMat); float camPos[4]; cam->getCameraPosition(camPos); //b3Vector3 cp= b3MakeVector3(camPos[0],camPos[2],camPos[1]); // b3Vector3 p = b3MakeVector3(worldPosX,worldPosY,worldPosZ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc( GL_GREATER, 1.0f ); int viewport[4]={0,0,gApp2->m_renderer->getScreenWidth(),gApp2->m_renderer->getScreenHeight()}; float posX = 450.f; float posY = 100.f; float winx,winy, winz; if (!projectWorldCoordToScreen(worldPosX, worldPosY, worldPosZ,viewMat,projMat,viewport,&winx, &winy, &winz)) { return; } posX = winx; posY = gApp2->m_renderer->getScreenHeight()/2+(gApp2->m_renderer->getScreenHeight()/2)-winy; { //float width = 0.f; int pos=0; //float color[]={0.2f,0.2,0.2f,1.f}; glActiveTexture(GL_TEXTURE0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId); glEnable(GL_TEXTURE_2D);//BindTexture //float width = r.x; //float extraSpacing = 0.; float startX = posX; float startY = posY-g_DefaultLargeFont->m_CharHeight*size1; glEnable(GL_COLOR_MATERIAL); while (txt[pos]) { int c = txt[pos]; //r.h = g_DefaultNormalFont->m_CharHeight; //r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing; float endX = startX+g_DefaultLargeFont->m_CharWidth[c]*size1; float endY = posY; float currentColor[]={1.f,0.2,0.2f,1.f}; float u0 = g_DefaultLargeFont->m_CharU0[c]; float u1 = g_DefaultLargeFont->m_CharU1[c]; float v0 = g_DefaultLargeFont->m_CharV0[c]; float v1 = g_DefaultLargeFont->m_CharV1[c]; float color[4] = {currentColor[0],currentColor[1],currentColor[2],currentColor[3]}; float x0 = startX; float x1 = endX; float y0 = startY; float y1 = endY; int screenWidth = gApp2->m_renderer->getScreenWidth(); int screenHeight = gApp2->m_renderer->getScreenHeight(); float z = 2.f*winz-1.f;//*(far /*float identity[16]={1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1}; */ PrimVertex vertexData[4] = { PrimVertex( PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)), PrimVertex( PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)), PrimVertex(PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)), PrimVertex( PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)) }; glBegin(GL_TRIANGLES); //use red colored text for now glColor4f(1,0,0,1); float scaling = 1; glTexCoord2f(vertexData[0].uv.p[0],vertexData[0].uv.p[1]); glVertex3d(vertexData[0].position.p[0]*scaling, vertexData[0].position.p[1]*scaling,vertexData[0].position.p[2]*scaling); glTexCoord2f(vertexData[1].uv.p[0],vertexData[1].uv.p[1]); glVertex3d(vertexData[1].position.p[0]*scaling, vertexData[1].position.p[1]*scaling,vertexData[1].position.p[2]*scaling); glTexCoord2f(vertexData[2].uv.p[0],vertexData[2].uv.p[1]); glVertex3d(vertexData[2].position.p[0]*scaling, vertexData[2].position.p[1]*scaling,vertexData[2].position.p[2]*scaling); glTexCoord2f(vertexData[0].uv.p[0],vertexData[0].uv.p[1]); glVertex3d(vertexData[0].position.p[0]*scaling, vertexData[0].position.p[1]*scaling,vertexData[0].position.p[2]*scaling); glTexCoord2f(vertexData[2].uv.p[0],vertexData[2].uv.p[1]); glVertex3d(vertexData[2].position.p[0]*scaling, vertexData[2].position.p[1]*scaling,vertexData[2].position.p[2]*scaling); glTexCoord2f(vertexData[3].uv.p[0],vertexData[3].uv.p[1]); glVertex3d(vertexData[3].position.p[0]*scaling, vertexData[3].position.p[1]*scaling,vertexData[3].position.p[2]*scaling); glEnd(); startX = endX; pos++; } } glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); restoreOpenGLState(); }
/////////////////////////////////////////////////////////////////////////////// // draw a textured cube with GL_TRIANGLES /////////////////////////////////////////////////////////////////////////////// void draw() { glBindTexture(GL_TEXTURE_2D, textureId); glColor4f(1, 1, 1, 1); glBegin(GL_TRIANGLES); // front faces glNormal3f(0,0,1); // face v0-v1-v2 glTexCoord2f(1,1); glVertex3f(1,1,1); glTexCoord2f(0,1); glVertex3f(-1,1,1); glTexCoord2f(0,0); glVertex3f(-1,-1,1); // face v2-v3-v0 glTexCoord2f(0,0); glVertex3f(-1,-1,1); glTexCoord2f(1,0); glVertex3f(1,-1,1); glTexCoord2f(1,1); glVertex3f(1,1,1); // right faces glNormal3f(1,0,0); // face v0-v3-v4 glTexCoord2f(0,1); glVertex3f(1,1,1); glTexCoord2f(0,0); glVertex3f(1,-1,1); glTexCoord2f(1,0); glVertex3f(1,-1,-1); // face v4-v5-v0 glTexCoord2f(1,0); glVertex3f(1,-1,-1); glTexCoord2f(1,1); glVertex3f(1,1,-1); glTexCoord2f(0,1); glVertex3f(1,1,1); // top faces glNormal3f(0,1,0); // face v0-v5-v6 glTexCoord2f(1,0); glVertex3f(1,1,1); glTexCoord2f(1,1); glVertex3f(1,1,-1); glTexCoord2f(0,1); glVertex3f(-1,1,-1); // face v6-v1-v0 glTexCoord2f(0,1); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(-1,1,1); glTexCoord2f(1,0); glVertex3f(1,1,1); // left faces glNormal3f(-1,0,0); // face v1-v6-v7 glTexCoord2f(1,1); glVertex3f(-1,1,1); glTexCoord2f(0,1); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(-1,-1,-1); // face v7-v2-v1 glTexCoord2f(0,0); glVertex3f(-1,-1,-1); glTexCoord2f(1,0); glVertex3f(-1,-1,1); glTexCoord2f(1,1); glVertex3f(-1,1,1); // bottom faces glNormal3f(0,-1,0); // face v7-v4-v3 glTexCoord2f(0,0); glVertex3f(-1,-1,-1); glTexCoord2f(1,0); glVertex3f(1,-1,-1); glTexCoord2f(1,1); glVertex3f(1,-1,1); // face v3-v2-v7 glTexCoord2f(1,1); glVertex3f(1,-1,1); glTexCoord2f(0,1); glVertex3f(-1,-1,1); glTexCoord2f(0,0); glVertex3f(-1,-1,-1); // back faces glNormal3f(0,0,-1); // face v4-v7-v6 glTexCoord2f(0,0); glVertex3f(1,-1,-1); glTexCoord2f(1,0); glVertex3f(-1,-1,-1); glTexCoord2f(1,1); glVertex3f(-1,1,-1); // face v6-v5-v4 glTexCoord2f(1,1); glVertex3f(-1,1,-1); glTexCoord2f(0,1); glVertex3f(1,1,-1); glTexCoord2f(0,0); glVertex3f(1,-1,-1); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); }