Esempio n. 1
28
void drawString(char *string, float x, float y) {
	glRasterPos2f(x, y);
	for (char* c = string; *c != '\0'; c++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10 , *c);
}
Esempio n. 2
0
void cb_glext2d_realize(GtkWidget *widget, gpointer user_data)
{
	PangoFont *font;
	PangoFontMetrics *font_metrics;
	PangoFontDescription *font_desc;

	GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

	if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
		return;
	}

	glShadeModel(GL_FLAT);
	glDisable(GL_DITHER);

	// generate display list for our square base
	glNewList(GREY_2D_SQUARE_CALL_LIST, GL_COMPILE);
		glBegin(GL_QUAD_STRIP);
		glColor3ub(100, 100, 100);
		glVertex2f(-1, -1);
		glVertex2f(-1, 1);
		glVertex2f(1, -1);
		glVertex2f(1, 1);
		glEnd();
	glEndList();

	glNewList(WHITE_2D_SQUARE_CALL_LIST, GL_COMPILE);
		glBegin(GL_QUAD_STRIP);
		glColor3ub(255, 255, 255);
		glVertex2f(-1, -1);
		glVertex2f(-1, 1);
		glVertex2f(1, -1);
		glVertex2f(1, 1);
		glEnd();
	glEndList();

	// generate display lists for our font
	const char *font_string = gtk_entry_get_text(GTK_ENTRY(viz->prefs_label_font));
	viz->font_list_2d = glGenLists(128);
	font_desc = pango_font_description_from_string(font_string);
	font = gdk_gl_font_use_pango_font(font_desc, 0, 128, viz->font_list_2d);
	if (font == NULL) {
		g_warning("cannot load font '%s', falling back to '%s'", font_string, DEFAULT_LABEL_FONT);

		font_desc = pango_font_description_from_string(DEFAULT_LABEL_FONT);
		font = gdk_gl_font_use_pango_font(font_desc, 0, 128, viz->font_list_3d);
	}

	// use pango to determine dimensions of font
	font_metrics = pango_font_get_metrics(font, NULL);
	viz->font_height_2d = pango_font_metrics_get_ascent(font_metrics) + pango_font_metrics_get_descent(font_metrics);
	viz->font_height_2d = PANGO_PIXELS(viz->font_height_2d);
	pango_font_description_free(font_desc);
	pango_font_metrics_unref(font_metrics);

	// define display lists for our as labels
	glNewList(LABELS_2D_AS_CALL_LIST, GL_COMPILE);
		// output our labels
		glColor3f(1.0, 1.0, 1.0);

		// 0 label
		glRasterPos2f(-1.0, -1.0);
		glListBase(viz->font_list_2d);
		glCallLists(strlen(" 0"), GL_UNSIGNED_BYTE, " 0");

		// 65535 label
		glRasterPos2f(1.0, 1.0);
		glListBase(viz->font_list_2d);
		glCallLists(strlen(" 65535"), GL_UNSIGNED_BYTE, " 65535");
	glEndList();

	// enable the use of glDrawArrays with vertices and normals
	glEnableClientState(GL_VERTEX_ARRAY);
	
	gdk_gl_drawable_gl_end(gldrawable);
}
Esempio n. 3
0
void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dx, int dy, int width, int height, bool transparent,
	const DeviceDrawParams &draw_params)
{
	assert(rgba.type == MEM_PIXELS);

	mem_copy_from(rgba, y, w, h, rgba.memory_elements_size(1));

	if(transparent) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	}

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

	if(rgba.data_type == TYPE_HALF) {
		/* for multi devices, this assumes the inefficient method that we allocate
		 * all pixels on the device even though we only render to a subset */
		GLhalf *host_pointer = (GLhalf*)rgba.host_pointer;
		float vbuffer[16], *basep;
		float *vp = NULL;

		host_pointer += 4*y*w;

		/* draw half float texture, GLSL shader for display transform assumed to be bound */
		GLuint texid;
		glGenTextures(1, &texid);
		glBindTexture(GL_TEXTURE_2D, texid);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGBA, GL_HALF_FLOAT, host_pointer);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

		glEnable(GL_TEXTURE_2D);

		if(draw_params.bind_display_space_shader_cb) {
			draw_params.bind_display_space_shader_cb();
		}

		if(GLEW_VERSION_1_5) {
			if(!vertex_buffer)
				glGenBuffers(1, &vertex_buffer);

			glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
			/* invalidate old contents - avoids stalling if buffer is still waiting in queue to be rendered */
			glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), NULL, GL_STREAM_DRAW);

			vp = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);

			basep = NULL;
		}
		else {
			basep = vbuffer;
			vp = vbuffer;
		}

		if(vp) {
			/* texture coordinate - vertex pair */
			vp[0] = 0.0f;
			vp[1] = 0.0f;
			vp[2] = dx;
			vp[3] = dy;

			vp[4] = 1.0f;
			vp[5] = 0.0f;
			vp[6] = (float)width + dx;
			vp[7] = dy;

			vp[8] = 1.0f;
			vp[9] = 1.0f;
			vp[10] = (float)width + dx;
			vp[11] = (float)height + dy;

			vp[12] = 0.0f;
			vp[13] = 1.0f;
			vp[14] = dx;
			vp[15] = (float)height + dy;

			if(vertex_buffer)
				glUnmapBuffer(GL_ARRAY_BUFFER);
		}

		glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), basep);
		glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), ((char *)basep) + 2 * sizeof(float));

		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);

		if(vertex_buffer) {
			glBindBuffer(GL_ARRAY_BUFFER, 0);
		}

		if(draw_params.unbind_display_space_shader_cb) {
			draw_params.unbind_display_space_shader_cb();
		}

		glBindTexture(GL_TEXTURE_2D, 0);
		glDisable(GL_TEXTURE_2D);
		glDeleteTextures(1, &texid);
	}
	else {
		/* fallback for old graphics cards that don't support GLSL, half float,
		 * and non-power-of-two textures */
		glPixelZoom((float)width/(float)w, (float)height/(float)h);
		glRasterPos2f(dx, dy);

		uint8_t *pixels = (uint8_t*)rgba.host_pointer;

		pixels += 4*y*w;

		glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

		glRasterPos2f(0.0f, 0.0f);
		glPixelZoom(1.0f, 1.0f);
	}

	if(transparent)
		glDisable(GL_BLEND);
}
Esempio n. 4
0
// draw string in OpenGL at position x, y
void draw_string(GLfloat x, GLfloat y, const char* word)
{
	glColor4f(1.0, 1.0, 1.0, 0.0);
	glRasterPos2f(x, y);
	print_string(font_base, word);
}
Esempio n. 5
0
/*
==============
XY_DrawBlockGrid
==============
*/
void XY_DrawBlockGrid (void)
{
	float	x, y, xb, xe, yb, ye;
	int		w, h;
	char	text[32];

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_1D);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);

	w = g_qeglobals.d_xy.width/2 / g_qeglobals.d_xy.scale;
	h = g_qeglobals.d_xy.height/2 / g_qeglobals.d_xy.scale;

	xb = g_qeglobals.d_xy.origin[0] - w;
	if (xb < region_mins[0])
		xb = region_mins[0];
	xb = 1024 * floor (xb/1024);

	xe = g_qeglobals.d_xy.origin[0] + w;
	if (xe > region_maxs[0])
		xe = region_maxs[0];
	xe = 1024 * ceil (xe/1024);

	yb = g_qeglobals.d_xy.origin[1] - h;
	if (yb < region_mins[1])
		yb = region_mins[1];
	yb = 1024 * floor (yb/1024);

	ye = g_qeglobals.d_xy.origin[1] + h;
	if (ye > region_maxs[1])
		ye = region_maxs[1];
	ye = 1024 * ceil (ye/1024);

	// draw major blocks

	glColor3f(0,0,1);
	glLineWidth (2);

	glBegin (GL_LINES);
	
	for (x=xb ; x<=xe ; x+=1024)
	{
		glVertex2f (x, yb);
		glVertex2f (x, ye);
	}
	for (y=yb ; y<=ye ; y+=1024)
	{
		glVertex2f (xb, y);
		glVertex2f (xe, y);
	}
	
	glEnd ();
	glLineWidth (1);

	// draw coordinate text if needed

	for (x=xb ; x<xe ; x+=1024)
		for (y=yb ; y<ye ; y+=1024)
		{
			glRasterPos2f (x+512, y+512);
			sprintf (text, "%i,%i",(int)floor(x/1024), (int)floor(y/1024) );
			glCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
		}

	glColor4f(0, 0, 0, 0);
}
Esempio n. 6
0
void TeleportWindow::render(int window_w, int window_h)
{
	// Calculate size of 1 pixel
	float ps_w = 2. / window_w; // pixelsize x-direction
	float ps_h = 2. / window_h; // pixelsize y-direction
	float apsr = 1.*window_w / window_h; // aspectatio

	// Whole Window
	glColor3f(0.0, 0.0, 0.1);
	glBegin(GL_QUADS);
	{
		glVertex3f(-0.9, -0.9, -1.0);
		glVertex3f(-0.9,  0.9, -1.0);
		glVertex3f( 0.9,  0.9, -1.0);
		glVertex3f( 0.9, -0.9, -1.0);
	}
	glEnd();

	// Preview Widget
	glColor3f (0.1, 0.1, 0.1);
	glBegin(GL_QUADS);
	{
		glVertex3f(-0.45/apsr, -0.45, -1.0);
		glVertex3f(-0.45/apsr,  0.45, -1.0);
		glVertex3f( 0.45/apsr,  0.45, -1.0);
		glVertex3f( 0.45/apsr, -0.45, -1.0);
	}
	glEnd();

	glColor3f(1.0, 1.0, 1.0);
	glRasterPos2f(-0.9 + 4 * ps_w, -0.9 + 4 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_12,
		(unsigned char *)"Use arrow keys up and down to select the desired action.\
		Use arrow keys right and left to select your destination or type its name.");

	glColor3f(1, 1, 1);
	unsigned char *actionstring = (unsigned char *)
		m_actions.at(m_action_selected).getDescription().c_str();
	float actionstring_len = glutBitmapLength(GLUT_BITMAP_HELVETICA_18, actionstring);

	glRasterPos2f(0 - actionstring_len / 2 * ps_w, 1 - 70 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, actionstring);

	float offset_l = m_destination.length() * 4.5;
	glRasterPos2f(0 - offset_l * ps_w, 1 - 93 * ps_h);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)m_destination.c_str());

	glColor3f(1, 1, 1);
	// Render preview of TeleportTarget
	glPushAttrib(GL_ENABLE_BIT);
	{
		glEnable (GL_DEPTH);
		glEnable (GL_DEPTH_TEST);
		glEnable (GL_BLEND);

		glScalef(1.0f / apsr, 1.0f, 1.0f);

		glTranslatef(0.0f, 0.0f, -1.0f);
		if (m_target)
			m_target->renderPreview(m_preview_time, 0.4f);
		else
		{
			// Draw Wire Sphere
			glLineWidth(2.0);
			glPushMatrix();
			{
				glRotatef(m_preview_time * TELEPORT_PREVIEW_ROTSPEED, 0, 1, 0);
				glRotatef(90, 1, 0, 0);
				glutWireSphere(0.4, 20, 20);
			}
			glPopMatrix();

			// Draw red question mark
			glPushMatrix();
			{
				glColor3f(1.0f, 0.0f, 0.0f);
				glLineWidth(5.0);
				float textsize = 0.5;
				float font_height = textsize / glutStrokeHeight(GLUT_STROKE_MONO_ROMAN);
				float font_width  = textsize / glutStrokeLength(GLUT_STROKE_MONO_ROMAN,
					(unsigned char *)"?");

				glTranslatef(0.0f, 0.0f, 1.0f);
				glRotatef(m_preview_time * TELEPORT_PREVIEW_ROTSPEED, 0, 1, 0);
				glTranslatef(-textsize / 2, -textsize / 4, 0.4f);
				glScalef(font_width, font_height, font_width);
				glutStrokeString(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"?");
			}
		}
	}
	glPopAttrib();
}
Esempio n. 7
0
void
Display(void)
{
    int i;
    static double th[4] = {0.0, 0.0, 0.0, 0.0};
	static double t1 = 0.0, t2 = 0.0, t;
	char num_str[128];
    
    t1 = t2;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    for (i = 0; i < NUM_SHARKS; i++) {
        glPushMatrix();
        FishTransform(&sharks[i]);
        DrawShark(&sharks[i]);
        glPopMatrix();
    }

    glPushMatrix();
    FishTransform(&dolph);
    DrawDolphin(&dolph);
    glPopMatrix();

    glPushMatrix();
    FishTransform(&momWhale);
    DrawWhale(&momWhale);
    glPopMatrix();

    glPushMatrix();
    FishTransform(&babyWhale);
    glScalef(0.45, 0.45, 0.3);
    DrawWhale(&babyWhale);
    glPopMatrix();
    
    if(Timing)
    {
		t2 = mtime();
		t = t2 - t1;
		if(t > 0.0001) t = 1.0 / t;
		
		glDisable(GL_LIGHTING);
		//glDisable(GL_DEPTH_TEST);
		
		glColor3f(1.0, 0.0, 0.0);
		
		glMatrixMode (GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0, w_win, 0, h_win, -10.0, 10.0);
		
		glRasterPos2f(5.0, 5.0);
		
		switch(StrMode)
		{
			case GL_VENDOR:
				sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win);
				DrawStr(num_str);
				DrawStr(glGetString(GL_VENDOR));
			break;
			case GL_RENDERER:
				sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win);
				DrawStr(num_str);
				DrawStr(glGetString(GL_RENDERER));
			break;
			case GL_VERSION:
				sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win);
				DrawStr(num_str);
				DrawStr(glGetString(GL_VERSION));
			break;
			case GL_EXTENSIONS:
				sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win);
				DrawStr(num_str);
				DrawStr(glGetString(GL_EXTENSIONS));
			break;
		}
		
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		
		glEnable(GL_LIGHTING);
		//glEnable(GL_DEPTH_TEST);
	}
	
    count++;

    glutSwapBuffers();
}
Esempio n. 8
0
static void HandleDisplay(void) {
  const WebPDecBuffer* const pic = kParams.pic;
  const WebPIterator* const iter = &kParams.frameiter;
  GLfloat xoff, yoff;
  if (pic == NULL) return;
  glPushMatrix();
  glPixelZoom(1, -1);
  xoff = (GLfloat)(2. * iter->x_offset / kParams.canvas_width);
  yoff = (GLfloat)(2. * iter->y_offset / kParams.canvas_height);
  glRasterPos2f(-1.f + xoff, 1.f - yoff);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4);

  if (kParams.prev_frame.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
    // TODO(later): these offsets and those above should factor in window size.
    //              they will be incorrect if the window is resized.
    // glScissor() takes window coordinates (0,0 at bottom left).
    const int window_x = kParams.prev_frame.x_offset;
    const int window_y = kParams.canvas_height -
                         kParams.prev_frame.y_offset -
                         kParams.prev_frame.height;
    glEnable(GL_SCISSOR_TEST);
    // Only updated the requested area, not the whole canvas.
    glScissor(window_x, window_y,
              kParams.prev_frame.width, kParams.prev_frame.height);

    glClear(GL_COLOR_BUFFER_BIT);  // use clear color
    DrawCheckerBoard();

    glDisable(GL_SCISSOR_TEST);
  }
  kParams.prev_frame.width = iter->width;
  kParams.prev_frame.height = iter->height;
  kParams.prev_frame.x_offset = iter->x_offset;
  kParams.prev_frame.y_offset = iter->y_offset;
  kParams.prev_frame.dispose_method = iter->dispose_method;

  glDrawPixels(pic->width, pic->height,
               GL_RGBA, GL_UNSIGNED_BYTE,
               (GLvoid*)pic->u.RGBA.rgba);
  if (kParams.print_info) {
    char tmp[32];

    glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
    glRasterPos2f(-0.95f, 0.90f);
    PrintString(kParams.file_name);

    snprintf(tmp, sizeof(tmp), "Dimension:%d x %d", pic->width, pic->height);
    glColor4f(0.90f, 0.0f, 0.90f, 1.0f);
    glRasterPos2f(-0.95f, 0.80f);
    PrintString(tmp);
    if (iter->x_offset != 0 || iter->y_offset != 0) {
      snprintf(tmp, sizeof(tmp), " (offset:%d,%d)",
               iter->x_offset, iter->y_offset);
      glRasterPos2f(-0.95f, 0.70f);
      PrintString(tmp);
    }
  }
  glPopMatrix();
  glFlush();
}
Esempio n. 9
0
void display(void)
{
  int i = 0;
  GLfloat bbox[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
  GLfloat bbox2[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
  char string[20];

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /* Render GLC_BITMAP without kerning */
  glLoadIdentity();
  glColor3f(1.f, 0.f, 0.f);
  glRasterPos2f(50.f, 50.f);
  glcDisable(GLC_KERNING_QSO);
  glcRenderStyle(GLC_BITMAP);
  glcLoadIdentity();
  glcScale(100.f, 100.f);
  glcRenderString("VAV");
  glcMeasureString(GL_FALSE, "VAV");
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glTranslatef(50.f, 50.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", bbox[2] - bbox[0]);
  glcEnable(GLC_HINTING_QSO);
  glcScale(0.15f, 0.15f);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(bbox);
  glVertex2f(bbox[0], bbox[1] - 40.f);
  glVertex2fv(&bbox[2]);
  glVertex2f(bbox[2], bbox[3] - 40.f);
  glVertex2f(bbox[0], bbox[1] - 30.f);
  glVertex2f(bbox[2], bbox[3] - 30.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[0] + 5.f, bbox[1] - 25.f);
  glVertex2f(bbox[0], bbox[1] - 30.f);
  glVertex2f(bbox[0] + 5.f, bbox[1] - 35.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[2] - 5.f, bbox[1] - 25.f);
  glVertex2f(bbox[2], bbox[1] - 30.f);
  glVertex2f(bbox[2] - 5.f, bbox[1] - 35.f);
  glEnd();
  glLoadIdentity();
  glRasterPos2f(floor((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f,
		floorf((bbox[1] + 23.f) * 100.f) / 100.f);
  glcRenderString(string);
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_TEXTURE without kerning */
  glLoadIdentity();
  glcRenderStyle(GLC_TEXTURE);
  glColor3f(1.f, 0.f, 0.f);
  glScalef(100.f, 100.f, 1.f);
  glTranslatef(3.f, 0.5f, 0.f);
  glPushMatrix();
  /* In order to reproduce the conditions of bug #1987563, GLC_GL_OBJECTS must
   * be disabled when rendering GLC_TEXTURE w/o kerning.
   */
  glcRenderString("VAV");
  glPopMatrix();
  glcMeasureString(GL_TRUE, "VAV");
  glcGetStringCharMetric(1, GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", (bbox[2] - bbox[0]) * 100.f);
  glcEnable(GLC_HINTING_QSO);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(bbox);
  glVertex2f(bbox[0], bbox[1] - 0.4f);
  glVertex2fv(&bbox[2]);
  glVertex2f(bbox[2], bbox[3] - 0.4f);
  glVertex2f(bbox[0], bbox[1] - 0.3f);
  glVertex2f(bbox[2], bbox[3] - 0.3f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.25f);
  glVertex2f(bbox[0], bbox[1] - 0.3f);
  glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.35f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.25f);
  glVertex2f(bbox[2], bbox[1] - 0.3f);
  glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.35f);
  glEnd();
  /* When hinting is enabled, characters must be rendered at integer positions
   * otherwise hinting is compromised and characters look fuzzy.
   */
  glTranslatef(floorf((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0]) * 0.15f) * 50.f) / 100.f,
	       floorf((bbox[1] - 0.27f) * 100.f) / 100.f, 0.f);
  glScalef(0.15f, 0.15f, 1.f);
  glcRenderString(string);
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_BITMAP with kerning */
  glColor3f(1.f, 0.f, 0.f);
  glcEnable(GLC_KERNING_QSO);
  glcRenderStyle(GLC_BITMAP);
  glcLoadIdentity();
  glcScale(100.f, 100.f);
  glLoadIdentity();
  glRasterPos2f(50.f, 150.f);
  glcRenderString("VAV");
  glcMeasureString(GL_FALSE, "VAV");
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glTranslatef(50.f, 150.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", bbox[4] - bbox[6]);
  glcEnable(GLC_HINTING_QSO);
  glcScale(0.15f, 0.15f);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(&bbox[4]);
  glVertex2f(bbox[4], bbox[5] + 40.f);
  glVertex2fv(&bbox[6]);
  glVertex2f(bbox[6], bbox[7] + 40.f);
  glVertex2f(bbox[4], bbox[5] + 30.f);
  glVertex2f(bbox[6], bbox[7] + 30.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[4] - 5.f, bbox[5] + 25.f);
  glVertex2f(bbox[4], bbox[5] + 30.f);
  glVertex2f(bbox[4] - 5.f, bbox[5] + 35.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[6] + 5.f, bbox[7] + 25.f);
  glVertex2f(bbox[6], bbox[7] + 30.f);
  glVertex2f(bbox[6] + 5.f, bbox[7] + 35.f);
  glEnd();
  glLoadIdentity();
  glRasterPos2f(floorf((bbox[4] - bbox[6]
			- (bbox2[4] - bbox2[6])) * 50.f) / 100.f + 50.f,
		bbox[7] + 183.f);
  glcRenderString(string);
  glcScale(2.f, 2.f);
  glcMeasureString(GL_FALSE, "GL_BITMAP");
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glRasterPos2f(floorf((bbox[2] - bbox[0]
			- (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f,
		300.f);
  glcRenderString("GL_BITMAP");
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_TEXTURE with kerning */
  glLoadIdentity();
  glcRenderStyle(GLC_TEXTURE);
  glColor3f(1.f, 0.f, 0.f);
  glScalef(100.f, 100.f, 1.f);
  glTranslatef(3.f, 1.5f, 0.f);
  glPushMatrix();
  glcRenderString("VAV");
  glPopMatrix();
  glcMeasureString(GL_TRUE, "VAV");
  glcGetStringCharMetric(1, GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", (bbox[4] - bbox[6]) * 100.f);
  glcEnable(GLC_HINTING_QSO);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(&bbox[4]);
  glVertex2f(bbox[4], bbox[5] + 0.4f);
  glVertex2fv(&bbox[6]);
  glVertex2f(bbox[6], bbox[7] + 0.4f);
  glVertex2f(bbox[4], bbox[5] + 0.3f);
  glVertex2f(bbox[6], bbox[7] + 0.3f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.25f);
  glVertex2f(bbox[6], bbox[7] + 0.3f);
  glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.35f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.25f);
  glVertex2f(bbox[4], bbox[5] + 0.3f);
  glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.35f);
  glEnd();
  glPushMatrix();
  glTranslatef(floorf((bbox[4] - bbox[6]
		       - (bbox2[4] - bbox2[6]) * 0.15f) *50.f) / 100.f,
	       floorf((bbox[5] + 0.33f) * 100.f) / 100.f, 0.f);
  glScalef(0.15f, 0.15f, 1.f);
  glcRenderString(string);
  glPopMatrix();
  glcMeasureString(GL_FALSE, "GL_TEXTURE");
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glTranslatef(floorf((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0]) * 0.3f) * 50.f)  / 100.f,
	       1.5f, 0.f);
  glScalef(0.3f, 0.3f, 1.f);
  glcRenderString("GL_TEXTURE");
  glcDisable(GLC_HINTING_QSO);

  glFlush();
}
Esempio n. 10
0
void game_render()
{
  int i;

  /* drawmode */
  if (draw_fast) {
    glDisable(GL_LINE_SMOOTH);
    glDisable(GL_POINT_SMOOTH);
    glDisable(GL_BLEND);
  } else {
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  }


  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(-115,115,-115,115);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  /* clear background */
  glClearColor(0,0,0,1);
  glClear(GL_COLOR_BUFFER_BIT);

  /* frame around image */
  glColor3f(1,1,0);
  glBegin(GL_LINE_LOOP);
  glVertex2f(-110, 110);
  glVertex2f( 110, 110);
  glVertex2f( 110,-110);
  glVertex2f(-110,-110);
  glEnd();

  glColor3f(1,0,0);
  glBegin(GL_LINE_LOOP);
  glVertex2f(-105, 105);
  glVertex2f( 105, 105);
  glVertex2f( 105,-105);
  glVertex2f(-105,-105);
  glEnd();

  glColor3f(0,0,1);
  glBegin(GL_LINE_LOOP);
  glVertex2f(-100, 100);
  glVertex2f( 100, 100);
  glVertex2f( 100,-100);
  glVertex2f(-100,-100);
  glEnd();


  /* player */
  if (player.state) {
    glPushMatrix();
    glTranslatef(player.pos_x, player.pos_y, 0);
    glRotatef(player.dir, 0,0,1);

    glColor3f(.5,.5,1);
    glBegin(GL_LINE_LOOP);
    glVertex2f(-4,-4);
    glVertex2f( 0, 5);
    glVertex2f( 4,-4);
    glEnd();

    glColor3f(1,1,1);
    glBegin(GL_LINE_STRIP);
    glVertex2f(-2,-5);
    glVertex2f(-4,-2);
    glVertex2f(-2, 2);
    glVertex2f( 2, 2);
    glVertex2f( 4,-2);
    glVertex2f( 2,-5);
    glEnd();

    glPopMatrix();
  }

  /* enemy */
  for (i=0; i<sizeof(enemy)/sizeof(Entity); i++) {
    if (enemy[i].state) {
      glPushMatrix();
      glTranslatef(enemy[i].pos_x, enemy[i].pos_y, 0);

      glRotatef(enemy[i].dir, 0,0,1);

      glColor3f(1,0,0);
      glBegin(GL_LINE_STRIP);
      glVertex2f(-3,-4);
      glVertex2f(-5, 0);
      glVertex2f( 0, 5);
      glVertex2f( 5, 0);
      glVertex2f( 3,-4);
      glEnd();
      glColor3f(1,1,0);
      glBegin(GL_LINE_LOOP);
      glVertex2f( 0, 5);
      glVertex2f( 3,-4);
      glVertex2f(-3,-4);
      glEnd();

      glPopMatrix();
    }
  }

  /* vortex */
  for (i=0; i<sizeof(vortex)/sizeof(Entity); i++) {
    if (vortex[i].state) {

      glPushMatrix();
      glTranslatef(vortex[i].pos_x, vortex[i].pos_y, 0);
      glRotatef(vortex[i].dir, 0,0,1);

      glColor3f(0,.5,1);
      glBegin(GL_LINE_LOOP);
      gCircle(vortex[i].radius,6);
      glEnd();

      glColor3f(0,0,1);
      glBegin(GL_LINE_LOOP);
      gCircle(vortex[i].radius*.7, 6);
      glEnd();

      glColor3f(0,0,.5);
      glBegin(GL_LINE_LOOP);
      gCircle(vortex[i].radius*.4, 6);
      glEnd();

      glPopMatrix();
    }
  }

  /* p_bullet */
  for (i=0; i<sizeof(p_bullet)/sizeof(Entity); i++) {
    if (p_bullet[i].state) {
      glPushMatrix();
      glTranslatef(p_bullet[i].pos_x, p_bullet[i].pos_y, 0);
      glRotatef(p_bullet[i].dir, 0,0,1);

      glColor3f(1,1,1);
      glBegin(GL_LINES);
      glVertex2f(0, 1);
      glVertex2f(0,-1);
      glEnd();

      glPopMatrix();
    }
  }

  /* e_bullet */
  for (i=0; i<sizeof(e_bullet)/sizeof(Entity); i++) {
    if (e_bullet[i].state) {
      glPushMatrix();
      glTranslatef(e_bullet[i].pos_x, e_bullet[i].pos_y, 0);
      glRotatef(e_bullet[i].dir, 0,0,1);

      glColor3f(1,1,0);
      glBegin(GL_LINES);
      glVertex2f(0, 1);
      glVertex2f(0,-1);
      glEnd();

      glPopMatrix();
    }
  }

  /* particles */
  glColor3f(.5,.7,1);
  glBegin(GL_POINTS);
  for (i=0; i<sizeof(particle)/sizeof(Entity); i++) {
    if (particle[i].state)
      glVertex2f(particle[i].pos_x, particle[i].pos_y);
  }
  glEnd();

  /* textual info */
  if (fontbase) {
    char s[200];
    g_snprintf(s, sizeof(s), "wave %d score %d highscore %d", wave_cnt, score, highscore);

    glColor3f(.8,.8,.8);
    glRasterPos2f(-90, 90);
    glListBase(fontbase);
    glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);

  }
}
Esempio n. 11
0
void Visualizer::drawBanner() {
    mSquareShader->bind();

    {
        std::stringstream message;

        if (mCurAdjustment && getTime() - mLastAdjustTime < 3) {
            auto adj = mAdjustments.find(mCurAdjustment);
            if (adj != mAdjustments.end()) {
                glColor4f(0,0,0.5,1);
                Repeater::Knobs k = mRepeater->getKnobs();
                message << adj->second.name << ": " << adj->second.cb(k, 0.0f);
            } else {
                glColor4f(0.5,0,0,1);
                for (auto list : mAdjustments) {
                    message << list.first << ':' << list.second.name << ' ';
                }
            }
        } else {
            switch (mRepeater->getState()) {
            case Repeater::S_STARTUP:
                glColor4f(1, 0, 0, 1);
                message << "acquiring signal";
                break;
            case Repeater::S_RUNNING:
                glColor4f(0, 0, 0, 0.7);
                message << "whatwesaidwillbe";
                break;
            case Repeater::S_SHUTDOWN_REQUESTED:
            case Repeater::S_SHUTTING_DOWN:
            case Repeater::S_GONE:
                glColor4f(0, 0, 1, 1);
                message << "whatwesaidonlywas";
                break;
            }
        }

        void *font = GLUT_BITMAP_HELVETICA_18;
        glRasterPos2f(-mWidth*1.0/mHeight, -1.0 + 9.0/mHeight);
        glutBitmapString(font, (const unsigned char *)message.str().c_str());
    }

    if (0) {
        std::stringstream message;
        const Repeater::Knobs& k = mRepeater->getKnobs();
        message << "mode: ";
        switch (k.mode) {
        case Repeater::M_GAIN:
            message << "gain";
            break;
        case Repeater::M_TARGET:
            message << "target";
            break;
        case Repeater::M_FEEDBACK:
            message << "feedback";
            break;
        }
        message << " " << k.levels.find(k.mode)->second;
        size_t width = glutBitmapLength(GLUT_BITMAP_HELVETICA_18,
                                        (const unsigned char *)message.str().c_str());
        glRasterPos2f((mWidth - 2*width)*1.0/mHeight, -1);

        glColor4f(0, 0, 0, 1);
        glutBitmapString(GLUT_BITMAP_HELVETICA_18,
                         (const unsigned char *)message.str().c_str());
    }
}
Esempio n. 12
0
//------------------------------------------------------------------------------
// drawFunc()
//------------------------------------------------------------------------------
void Display::drawFunc()
{

   if (image != nullptr) {
      if (testTexture) {
         // ---
         // Draw using texture map
         // ---

         // enable textures, if we need to
         glEnable(GL_TEXTURE_2D);
         if (texture == 0) {
            glGenTextures(1,&texture);
         }

         // set our texture environment
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
         
         glBindTexture(GL_TEXTURE_2D, texture);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

         double start = getComputerTime();

         glTexImage2D(GL_TEXTURE_2D, 0, PIXEL_SIZE, imgWidth, imgHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

         glBegin(GL_POLYGON);

            glTexCoord2f( 1.0f, 1.0f );
            glVertex2f(  1.0f,  1.0f );

            glTexCoord2f( 0.0f, 1.0f );
            glVertex2f( 0.0f, 1.0f );

            glTexCoord2f( 0.0f, 0.0f );
            glVertex2f(  0.0f, 0.0f );

            glTexCoord2f( 1.0f, 0.0f );
            glVertex2f( 1.0f, 0.0f );

         glEnd();

         double end = getComputerTime();
         double dtime = (end - start);
         std::cout << "glTexImage2D() dtime = " << dtime << std::endl;
         glDisable(GL_TEXTURE_2D);
      }
      else {
         // ---
         // Draw using glDrawPixels()
         // ---

         glRasterPos2f(0.0, 0.0);

         double start = getComputerTime();

         glDrawPixels(imgWidth, imgHeight, GL_RGB, GL_UNSIGNED_BYTE, image);

         double end = getComputerTime();
         double dtime = (end - start);
         std::cout << "glDrawPixels() dtime = " << dtime << std::endl;
      }
   }
}
Esempio n. 13
0
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{            
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLpong";
    RegisterClass (&wc);
    hWnd = CreateWindow (
      "GLpong", "ponggl", 
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      70, 70, 800, 600,
      NULL, NULL, hInstance, NULL);
    EnableOpenGL (hWnd, &hDC, &hRC);
BuildFont();
	wglUseFontBitmaps(hDC, 32, 96, base);	
 
    while (!bQuit)
    {
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }           
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);

//glColor3f(1,1,1);           
//glPushMatrix();


glBegin(GL_TRIANGLE_FAN); //ball
//glColor3f(1,0,0);

glColor3f(0,1,0);
glVertex3f(posx+(GLfloat).01,posy+(GLfloat).01,0);
glVertex3f(posx-(GLfloat).01,posy+(GLfloat).01,0);
glVertex3f(posx-(GLfloat).01,posy-(GLfloat).01,0);
glVertex3f(posx+(GLfloat).01,posy-(GLfloat).01,0);
		
glEnd();

glBegin(GL_TRIANGLES); //paddle
//glColor3f(1,0,0);

glColor3f(0,1,0);
glVertex3f((GLfloat)(mousex-400)/400,(GLfloat)-1*(mousey-300)/300,0);
glVertex3f(0,0,0);
glVertex3f((GLfloat)(mousex-400)/400-(GLfloat).1,(GLfloat)-1*(mousey-300)/300,0);
		
glEnd();


                  
glRasterPos2f(0.05f,0.05f); 
glPrint("testx%f",(float)mousex); 

if (posx==0){richtungsvektor.x=(GLfloat).01;richtungsvektor.y=(GLfloat).03;}
if (posx>1){glPrint("gr%f",(float)posx);richtungsvektor.x=(GLfloat)-.01; }
if (posx<-1){glPrint("kl%f",(float)posx);richtungsvektor.x=(GLfloat)+.01; }
if (posy>1){glPrint("gr%f",(float)posy);richtungsvektor.y=(GLfloat)-.03; }
if (posy<-1){glPrint("kl%f",(float)posy);richtungsvektor.y=(GLfloat)+.03; }

//if (-0.5>posx){glPrint("kl%f",(float)posx);richtungsvektor.x=-.001; }

/*if (posx<-0.5f){richtungsvektor.x=-.001;}
if (posy>0.5f){richtungsvektor.y=.002;}
if (posy<-0.5f){richtungsvektor.y=-.002;}
*/
posx+=richtungsvektor.x;
posy+=richtungsvektor.y;





//glPopMatrix();
SwapBuffers (hDC);
        }
    }

    DisableOpenGL (hWnd, hDC, hRC);
    DestroyWindow (hWnd);

    return msg.wParam;

}
Esempio n. 14
0
static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf *ibuf, int fontid, int fstep)
{
    float offsx, offsy;

    if (ibuf == NULL) {
        printf("%s: no ibuf for picture '%s'\n", __func__, picture ? picture->name : "<NIL>");
        return;
    }
    if (ibuf->rect == NULL && ibuf->rect_float) {
        IMB_rect_from_float(ibuf);
        imb_freerectfloatImBuf(ibuf);
    }
    if (ibuf->rect == NULL)
        return;

    GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);

    /* offset within window */
    offsx = 0.5f * (((float)ps->win_x - ps->zoom * ibuf->x) / (float)ps->win_x);
    offsy = 0.5f * (((float)ps->win_y - ps->zoom * ibuf->y) / (float)ps->win_y);

    CLAMP(offsx, 0.0f, 1.0f);
    CLAMP(offsy, 0.0f, 1.0f);
    glRasterPos2f(offsx, offsy);

    glClearColor(0.1, 0.1, 0.1, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    /* checkerboard for case alpha */
    if (ibuf->planes == 32) {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        fdrawcheckerboard(offsx, offsy, offsx + (ps->zoom * ibuf->x) / (float)ps->win_x, offsy + (ps->zoom * ibuf->y) / (float)ps->win_y);
    }

    glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);

    glDisable(GL_BLEND);

    pupdate_time();

    if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) {
        int sizex, sizey;
        float fsizex_inv, fsizey_inv;
        char str[32 + FILE_MAX];
        cpack(-1);
        BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime);

        playanim_window_get_size(&sizex, &sizey);
        fsizex_inv = 1.0f / sizex;
        fsizey_inv = 1.0f / sizey;

        BLF_enable(fontid, BLF_ASPECT);
        BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f);
        BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f);
        BLF_draw(fontid, str, sizeof(str));
    }

    GHOST_SwapWindowBuffers(g_WS.ghost_window);
}
Esempio n. 15
0
void screen_title()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	// Establish view 
	glTranslatef(0, 0, -50);

	glDisable(GL_LIGHTING);
    glClear(GL_COLOR_BUFFER_BIT); // clear screen, to glClearColor()
    glColor3f(1.0,1.0,1.0);
	glRasterPos2f(-2,0);
	int len, i;
	string fin = "Continue";
	const char* a = fin.c_str();
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a);

	string fin2 = "New Game" ;
	const char* a2 = fin2.c_str();
	glRasterPos2f(-2, -2);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a2);

	string fin3 = "Instructions" ;
	const char* a3 = fin3.c_str();
	glRasterPos2f(-2, -4);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a3);

	string fin4 = "Exit Game" ;
	const char* a4 = fin4.c_str();
	glRasterPos2f(-2, -6);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a4);

	string fin5 = "Six Sides of Destruction" ;
	const char* a5 = fin5.c_str();
	glRasterPos2f(-4, 16);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a5);



	string fin6 = "" ;
	if(mute)
	{
		fin6 = "Press m to unmute";
	}
	else{
		fin6 = "Press m to mute";
	}
	const char* a6 = fin6.c_str();
	glRasterPos2f(-2, -20);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*) a6);


	// Cursor cube
	glPushMatrix();
	glTranslatef(-3, titleposition, 0);
	glRotatef(titledegrees, 1, 1, 0);

	// Draw cube on center
	// This is the front
	glBegin(GL_QUADS);
	glColor3f(1, 0, 0);
	glNormal3f(0, 0, 1);
	glVertex3f(-msize, -msize, msize);
	glVertex3f( msize, -msize, msize);
	glVertex3f( msize,  msize, msize);
	glVertex3f(-msize,  msize, msize);

	// This is the back
	glColor3f(1, 0, 0);
	glNormal3f(0, 0, -1);
	glVertex3f(-msize, -msize, -msize);
	glVertex3f( msize, -msize, -msize);
	glVertex3f( msize,  msize, -msize);
	glVertex3f(-msize,  msize, -msize);

	// This is the top
	glColor3f(0, 1, 0);
	glNormal3f(0, 1, 0);
	glVertex3f(-msize, msize, -msize);
	glVertex3f( msize, msize, -msize);
	glVertex3f( msize, msize, msize);
	glVertex3f(-msize, msize, msize);

	// This is the bottom
	glColor3f(0, 1, 0);
	glNormal3f(0, -1, 0);
	glVertex3f(-msize, -msize, -msize);
	glVertex3f( msize, -msize, -msize);
	glVertex3f( msize, -msize, msize);
	glVertex3f(-msize, -msize, msize);


	// This is the left
	glColor3f(0, 0, 1);
	glNormal3f(-1 , 0, 0);
	glVertex3f(-msize, -msize, -msize);
	glVertex3f(-msize,  msize, -msize);
	glVertex3f(-msize,  msize, msize);
	glVertex3f(-msize, -msize, msize);


	// This is the right
	glColor3f(0, 0, 1);
	glNormal3f(1 , 0, 0);
	glVertex3f(msize, -msize, -msize);
	glVertex3f(msize,  msize, -msize);
	glVertex3f(msize,  msize, msize);
	glVertex3f(msize, -msize, msize);
	glEnd();
	glPopMatrix();
	titledegrees += 0.5;
	if(titledegrees > 360)
	{
		titledegrees -= 360;
	}

	// Decorative cube
	glPushMatrix();
	glTranslatef(0, 8, 0);
	glRotatef(titledegrees, 0.5, 0, 1);

	// Draw cube on center
	// This is the front
	glBegin(GL_QUADS);
	glColor3f(1, 0, 0);
	glNormal3f(0, 0, 1);
	glVertex3f(-mgrow, -mgrow, mgrow);
	glVertex3f( mgrow, -mgrow, mgrow);
	glVertex3f( mgrow,  mgrow, mgrow);
	glVertex3f(-mgrow,  mgrow, mgrow);

	// This is the back
	glColor3f(1, 0, 0);
	glNormal3f(0, 0, -1);
	glVertex3f(-mgrow, -mgrow, -mgrow);
	glVertex3f( mgrow, -mgrow, -mgrow);
	glVertex3f( mgrow,  mgrow, -mgrow);
	glVertex3f(-mgrow,  mgrow, -mgrow);

	// This is the top
	glColor3f(0, 1, 0);
	glNormal3f(0, 1, 0);
	glVertex3f(-mgrow, mgrow, -mgrow);
	glVertex3f( mgrow, mgrow, -mgrow);
	glVertex3f( mgrow, mgrow, mgrow);
	glVertex3f(-mgrow, mgrow, mgrow);

	// This is the bottom
	glColor3f(0, 1, 0);
	glNormal3f(0, -1, 0);
	glVertex3f(-mgrow, -mgrow, -mgrow);
	glVertex3f( mgrow, -mgrow, -mgrow);
	glVertex3f( mgrow, -mgrow, mgrow);
	glVertex3f(-mgrow, -mgrow, mgrow);


	// This is the left
	glColor3f(0, 0, 1);
	glNormal3f(-1 , 0, 0);
	glVertex3f(-mgrow, -mgrow, -mgrow);
	glVertex3f(-mgrow,  mgrow, -mgrow);
	glVertex3f(-mgrow,  mgrow, mgrow);
	glVertex3f(-mgrow, -mgrow, mgrow);


	// This is the right
	glColor3f(0, 0, 1);
	glNormal3f(1 , 0, 0);
	glVertex3f(mgrow, -mgrow, -mgrow);
	glVertex3f(mgrow,  mgrow, -mgrow);
	glVertex3f(mgrow,  mgrow, mgrow);
	glVertex3f(mgrow, -mgrow, mgrow);
	glEnd();
	glPopMatrix();

	// Handle the growing and slinking aspect
	if(growing)
	{
		if(mgrow > 4)
		{
			growing = false;
			mgrow -= 0.005;
		}
		else{
		
			mgrow += 0.005;
		}

	}
	else
	{
		if(mgrow <0.1)
		{
			growing = true;
			mgrow += 0.005;
		}
		else{
			mgrow -= 0.005;
		}
	}

	glutSwapBuffers();
}
Esempio n. 16
0
void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dy, int width, int height, bool transparent,
	const DeviceDrawParams &draw_params)
{
	pixels_copy_from(rgba, y, w, h);

	if(transparent) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	}

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

	if(rgba.data_type == TYPE_HALF) {
		/* for multi devices, this assumes the inefficient method that we allocate
		 * all pixels on the device even though we only render to a subset */
		GLhalf *data_pointer = (GLhalf*)rgba.data_pointer;
		data_pointer += 4*y*w;

		/* draw half float texture, GLSL shader for display transform assumed to be bound */
		GLuint texid;
		glGenTextures(1, &texid);
		glBindTexture(GL_TEXTURE_2D, texid);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGBA, GL_HALF_FLOAT, data_pointer);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

		glEnable(GL_TEXTURE_2D);

		if(draw_params.bind_display_space_shader_cb) {
			draw_params.bind_display_space_shader_cb();
		}

		glPushMatrix();
		glTranslatef(0.0f, (float)dy, 0.0f);

		glBegin(GL_QUADS);
		
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f((float)width, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f((float)width, (float)height);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(0.0f, (float)height);

		glEnd();

		glPopMatrix();

		if(draw_params.unbind_display_space_shader_cb) {
			draw_params.unbind_display_space_shader_cb();
		}

		glBindTexture(GL_TEXTURE_2D, 0);
		glDisable(GL_TEXTURE_2D);
		glDeleteTextures(1, &texid);
	}
	else {
		/* fallback for old graphics cards that don't support GLSL, half float,
		 * and non-power-of-two textures */
		glPixelZoom((float)width/(float)w, (float)height/(float)h);
		glRasterPos2f(0, dy);

		uint8_t *pixels = (uint8_t*)rgba.data_pointer;

		pixels += 4*y*w;

		glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

		glRasterPos2f(0.0f, 0.0f);
		glPixelZoom(1.0f, 1.0f);
	}

	if(transparent)
		glDisable(GL_BLEND);
}
Esempio n. 17
0
void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
{
	float xzoom = glaGetOneFloat(GL_ZOOM_X);
	float yzoom = glaGetOneFloat(GL_ZOOM_Y);

	/* The pixel space coordinate of the intersection of
	 * the [zoomed] image with the origin.
	 */
	float ix = -x / xzoom;
	float iy = -y / yzoom;
		
	/* The maximum pixel amounts the image can be cropped
	 * at the lower left without exceeding the origin.
	 */
	int off_x = floor(max_ff(ix, 0.0f));
	int off_y = floor(max_ff(iy, 0.0f));

	/* The zoomed space coordinate of the raster position
	 * (starting at the lower left most unclipped pixel).
	 */
	float rast_x = x + off_x * xzoom;
	float rast_y = y + off_y * yzoom;

	GLfloat scissor[4];
	int draw_w, draw_h;

	/* Determine the smallest number of pixels we need to draw
	 * before the image would go off the upper right corner.
	 *
	 * It may seem this is just an optimization but some graphics
	 * cards (ATI) freak out if there is a large zoom factor and
	 * a large number of pixels off the screen (probably at some
	 * level the number of image pixels to draw is getting multiplied
	 * by the zoom and then clamped). Making sure we draw the
	 * fewest pixels possible keeps everyone mostly happy (still
	 * fails if we zoom in on one really huge pixel so that it
	 * covers the entire screen).
	 */
	glGetFloatv(GL_SCISSOR_BOX, scissor);
	draw_w = min_ii(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom));
	draw_h = min_ii(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom));

	if (draw_w > 0 && draw_h > 0) {
		int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);

		/* Don't use safe RasterPos (slower) if we can avoid it. */
		if (rast_x >= 0 && rast_y >= 0) {
			glRasterPos2f(rast_x, rast_y);
		}
		else {
			glaRasterPosSafe2f(rast_x, rast_y, 0, 0);
		}

		glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w);
		if (format == GL_LUMINANCE || format == GL_RED) {
			if (type == GL_FLOAT) {
				float *f_rect = (float *)rect;
				glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x));
			}
			else if (type == GL_INT || type == GL_UNSIGNED_INT) {
				int *i_rect = (int *)rect;
				glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y * row_w + off_x));
			}
		}
		else { /* RGBA */
			if (type == GL_FLOAT) {
				float *f_rect = (float *)rect;
				glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x) * 4);
			}
			else if (type == GL_UNSIGNED_BYTE) {
				unsigned char *uc_rect = (unsigned char *) rect;
				glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y * row_w + off_x) * 4);
			}
		}
		
		glPixelStorei(GL_UNPACK_ROW_LENGTH,  old_row_length);
	}
}
Esempio n. 18
0
void Painter::print_str(const char* s, float x, float y) {
    glRasterPos2f(x, y);
    glutBitmapString(GLUT_BITMAP_HELVETICA_10, reinterpret_cast<const unsigned char*>(s));
}
Esempio n. 19
0
///Much like Nehe's glPrint function, but modified to work
///with freetype fonts.
float Text(const Font &ft_font, GLfloat x, GLfloat y, GLfloat angle, GLfloat scaleX, GLfloat scaleY, GLfloat scaleZ, GLfloat r, GLfloat g, GLfloat b, const char *fmt, ...)  {

	// MODIF: I added these lines to allow rotating, scaling and coloring the font 
	// in the same function.
	gp2d::EnableTexturing();
	glColor3f(r,g,b);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(angle,0,0,1);
	glScalef(scaleX, scaleY, scaleZ);
	
	// We want a coordinate system where things coresponding to window pixels.
	// pushScreenCoordinateMatrix();					
	
	GLuint font=ft_font.list_base;
	float h=ft_font.h/.63f;						//We make the height about 1.5* that of
	float len;
	
	char		text[256];								// Holds Our String
	va_list		ap;										// Pointer To List Of Arguments

	if (fmt == NULL)									// If There's No Text
		*text=0;											// Do Nothing

	else {
	va_start(ap, fmt);									// Parses The String For Variables
	    vsprintf(text, fmt, ap);						// And Converts Symbols To Actual Numbers
	va_end(ap);											// Results Are Stored In Text
	}


	//Here is some code to split the text that we have been
	//given into a set of lines.
	//This could be made much neater by using
	//a regular expression library such as the one avliable from
	//boost.org (I've only done it out by hand to avoid complicating
	//this tutorial with unnecessary library dependencies).
	const char *start_line=text;
	vector<string> lines;

	const char * c = text;

	//for(const char *c=text;*c;c++) {
	for(;*c;c++) {
		if(*c=='\n') {
			string line;
			for(const char *n=start_line;n<c;n++) line.append(1,*n);
			lines.push_back(line);
			start_line=c+1;
		}
	}
	if(start_line) {
		string line;
		for(const char *n=start_line;n<c;n++) line.append(1,*n);
		lines.push_back(line);
	}

	glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT  | GL_ENABLE_BIT | GL_TRANSFORM_BIT);	
	glMatrixMode(GL_MODELVIEW);
	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

	glListBase(font);

	float modelview_matrix[16];	
	glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);

	//This is where the text display actually happens.
	//For each line of text we reset the modelview matrix
	//so that the line's text will start in the correct position.
	//Notice that we need to reset the matrix, rather than just translating
	//down by h. This is because when each character is
	//draw it modifies the current matrix so that the next character
	//will be drawn immediatly after it.  
	for(unsigned int i=0;i<lines.size();i++) {
		
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(x,y-h*i,0);
		glRotatef(180,1,0,0);
		glMultMatrixf(modelview_matrix);

	//  The commented out raster position stuff can be useful if you need to
	//  know the length of the text that you are creating.
	//  If you decide to use it make sure to also uncomment the glBitmap command
	//  in make_dlist().
		glRasterPos2f(0,0);
		glCallLists(lines[i].length(), GL_UNSIGNED_BYTE, lines[i].c_str());
		float rpos[4];
		glGetFloatv(GL_CURRENT_RASTER_POSITION ,rpos);
		len=x-rpos[0];
		glPopMatrix();

	}


	glPopAttrib();		

	// MODIF: I commented this line as it had problems with the way GP2D uses the matrices.
	// pop_projection_matrix();

	glPopMatrix();

	return len;

}
Esempio n. 20
0
int gomp_PlotClusterMatrix(int num1, int num2,
                         float min1, float min2,float min3,float min4,
                         float max1, float max2,float max3,float max4,
                         float rest)
/***********************************************************************/
{
    static float  vec[2],dist,st;
    static char   text[BUFF_LEN];
    static int    i,j,k;
    static int    mm;
    static const float *ClusterArray;
    static char   PropertyFont[] = "*";


    if(!gomp_GetClusterStatus()) {
        (void)gomp_PrintERROR("No cluster data available for plotting");
        (void)gomp_SetDisplayCLUSTERmatrix(CLUSTER_OFF);
        return(1);
    }

    ClusterArray = gomp_GetClusterData();

/* Plot the distance matrix */ 

    glGetIntegerv(GL_MATRIX_MODE, &mm);
    glMatrixMode(GL_PROJECTION);

    glDisable(GL_LIGHTING);

    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(1, num1, 1, num2 );
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(mm);


    st=0.5;

    for(i =0   ; i < num1 - 1 ; i++) {
        for(j=i+1 ; j < num2     ; j++)   {

            dist = ClusterArray[i + j * (j - 1) / 2];

            glColor3fv(gomp_WHITEv);

            if(dist > min1 && dist < max1 ) glColor3fv(gomp_GREENv);

            if(dist >= min2 && dist < max2) glColor3fv(gomp_BLUEv);

            if(dist >= min3 && dist < max3) glColor3fv(gomp_REDv);

            if(dist >= min4 && dist < max4) glColor3fv(gomp_YELLOWv);

            if(dist >= rest ) glColor3fv(gomp_CYANv);

            glBegin(GL_QUADS);

            vec[0]=(float)(i);
            vec[1]=(float)(j); 
            glVertex2fv(vec);
            vec[0]=(float)(i+1);
            vec[1]=(float)(j  );
            glVertex2fv(vec);
            vec[0]=(float)(i+1);
            vec[1]=(float)(j+1);
            glVertex2fv(vec);
            vec[0]=(float)(i  );
            vec[1]=(float)(j+1);
            glVertex2fv(vec);

            glEnd();

        }
    }

    glColor3fv(gomp_BLACKv);

    k=num1/50;

    if( k > 0) {

        for(i=1 ; i <= k ; i++) {

            j=50*i;

            glBegin(GL_LINES); 
            glVertex2i(j, 1);
            glVertex2i(j, num1);
            glEnd();
        }
    }

    k=num2/50;

    if( k > 0) {

        for(i=1 ; i <= k ; i++) {

            j=50*i;

            glBegin(GL_LINES); 
            glVertex2i(1, j);
            glVertex2i(num2, j);
            glEnd();

        }
    }

    glColor3fv(gomp_WHITEv);
    glRasterPos2f(num1/2.1, 4.0*num2/10.);
    sprintf(text,"         RMSD <  %4.2f  WHITE",min1);
    gomp_PrintString(text , PropertyFont);
    /* OGLXXX charstr: check list numbering */
    glColor3fv(gomp_GREENv);
    glRasterPos2f(num1/2.1, 3.5*num2/10.);
    sprintf(text," %4.2f  < RMSD <  %4.2f  GREEN",min1,max1);
    gomp_PrintString(text , PropertyFont);
    /* OGLXXX charstr: check list numbering */
    glColor3fv(gomp_BLUEv);
    glRasterPos2f(num1/2.1, 3.0*num2/10.);
    sprintf(text," %4.2f  < RMSD <  %4.2f  BLUE ",min2,max2);
    gomp_PrintString(text , PropertyFont);
    /* OGLXXX charstr: check list numbering */
    glColor3fv(gomp_REDv);
    glRasterPos2f(num1/2.1, 2.5*num2/10.);
    sprintf(text," %4.2f  < RMSD <  %4.2f  RED  ",min3,max3);
    gomp_PrintString(text , PropertyFont);
    /* OGLXXX charstr: check list numbering */
    glColor3fv(gomp_YELLOWv);
    glRasterPos2f(num1/2.1, 2.0*num2/10.);
    sprintf(text," %4.2f  < RMSD <  %4.2f  YELLOW",min4,max4);
    gomp_PrintString(text , PropertyFont);
    /* OGLXXX charstr: check list numbering */
    glColor3fv(gomp_CYANv);
    glRasterPos2f(num1/2.1, 1.5*num2/10.);
    sprintf(text," %4.2f  < RMSD           CYAN",rest);
    gomp_PrintString(text , PropertyFont);

    glGetIntegerv(GL_MATRIX_MODE, &mm);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glMatrixMode(mm);

    glEnable(GL_LIGHTING);

    return(0);
}
Esempio n. 21
0
void PhysicsInformation::render(int window_w, int window_h)
{
	if (m_hidden) return;

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	// Calculate size of 1 pixel
	float ps_w = 2. / window_w; // pixelsize x-direction
	float ps_h = 2. / window_h; // pixelsize y-direction

	// Timelapse
	std::ostringstream conversion_tl;
	conversion_tl<<game->getGameSpeed();
	std::string gamespeed_str = conversion_tl.str();
	std::string timelapse_text = "Timelapse: " + gamespeed_str + "x";

	glRasterPos2f(-1 + 5 * ps_w, 1 - 23 * ps_h);

	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)timelapse_text.c_str());

	// Camera type
	std::string camtype;
	switch (game->getSpaceship()->getCamBind())
	{
		case CAMERA_BOUND:
			camtype = "bound";
			break;
		case CAMERA_RELATIVE_ROT:
			camtype = "relative with rotation";
			break;
		case CAMERA_RELATIVE:
			camtype = "relative";
			break;
		case CAMERA_FREE:
			camtype = "free";
			break;
	}
	std::string camtype_text = "Camera: " + camtype;

	glRasterPos2f(-1 + 5 * ps_w, 1 - 46 * ps_h);

	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)camtype_text.c_str());

	// Ship Speed
	float shipvel = getVectorLength(game->getSpaceship()->getVelocity()) / USC;
	std::string speedtext = "Speed: " + std::to_string(shipvel) + " km/s";

	glRasterPos2f(-1 + 5 * ps_w, 1 - 69 * ps_h);

	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)speedtext.c_str());

	if (shipvel > SPEED_OF_LIGHT)
	{
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
		glRasterPos2f(1 - 150 * ps_w, 1 - 23 * ps_h);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)"SPEED OF LIGHT!");
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	}

	// Gravity Acceleration
	SimpleVec3d gravacc_v = game->getSpaceship()->getGravityAcc();
	float gravacc = getVectorLength(gravacc_v) * 1000 / USC; // / 1000 for km/s² to m/s²
	std::string gravacc_text = "Acceleration: " + std::to_string(gravacc) + " m/s ";
	gravacc_text.push_back(0xB2); // ² character

	glRasterPos2f(-1 + 5 * ps_w, 1 - 92 * ps_h);

	glutBitmapString(GLUT_BITMAP_HELVETICA_18, (unsigned char *)gravacc_text.c_str());
}
Esempio n. 22
0
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
                           unsigned int *rect, float alpha, const float rgb[3], const bool is_preview)
{
	ImBuf *ima = NULL;
	int draw_w = w;
	int draw_h = h;
	int draw_x = x;
	int draw_y = y;

	/* sanity check */
	if (w <= 0 || h <= 0 || w > 2000 || h > 2000) {
		printf("%s: icons are %i x %i pixels?\n", __func__, w, h);
		BLI_assert(!"invalid icon size");
		return;
	}

	/* modulate color */
	if (alpha != 1.0f)
		glPixelTransferf(GL_ALPHA_SCALE, alpha);

	if (rgb) {
		glPixelTransferf(GL_RED_SCALE, rgb[0]);
		glPixelTransferf(GL_GREEN_SCALE, rgb[1]);
		glPixelTransferf(GL_BLUE_SCALE, rgb[2]);
	}

	/* rect contains image in 'rendersize', we only scale if needed */
	if (rw != w || rh != h) {
		/* preserve aspect ratio and center */
		if (rw > rh) {
			draw_w = w;
			draw_h = (int)(((float)rh / (float)rw) * (float)w);
			draw_y += (h - draw_h) / 2;
		}
		else if (rw < rh) {
			draw_w = (int)(((float)rw / (float)rh) * (float)h);
			draw_h = h;
			draw_x += (w - draw_w) / 2;
		}
		/* if the image is squared, the draw_ initialization values are good */

		/* first allocate imbuf for scaling and copy preview into it */
		ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
		memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int));
		IMB_scaleImBuf(ima, draw_w, draw_h); /* scale it */
		rect = ima->rect;
	}

	/* draw */
	if (is_preview) {
		glaDrawPixelsSafe(draw_x, draw_y, draw_w, draw_h, draw_w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
	}
	else {
		int bound_options;
		GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);

		glRasterPos2f(draw_x, draw_y);
		glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, rect);

		GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
	}

	if (ima)
		IMB_freeImBuf(ima);

	/* restore color */
	if (alpha != 0.0f)
		glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
	
	if (rgb) {
		glPixelTransferf(GL_RED_SCALE, 1.0f);
		glPixelTransferf(GL_GREEN_SCALE, 1.0f);
		glPixelTransferf(GL_BLUE_SCALE, 1.0f);
	}
}
Esempio n. 23
0
/*
==============
XY_DrawGrid
==============
*/
void XY_DrawGrid (void)
{
	float	x, y, xb, xe, yb, ye;
	int		w, h;
	char	text[32];

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_1D);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);

	w = g_qeglobals.d_xy.width/2 / g_qeglobals.d_xy.scale;
	h = g_qeglobals.d_xy.height/2 / g_qeglobals.d_xy.scale;

	xb = g_qeglobals.d_xy.origin[0] - w;
	if (xb < region_mins[0])
		xb = region_mins[0];
	xb = 64 * floor (xb/64);

	xe = g_qeglobals.d_xy.origin[0] + w;
	if (xe > region_maxs[0])
		xe = region_maxs[0];
	xe = 64 * ceil (xe/64);

	yb = g_qeglobals.d_xy.origin[1] - h;
	if (yb < region_mins[1])
		yb = region_mins[1];
	yb = 64 * floor (yb/64);

	ye = g_qeglobals.d_xy.origin[1] + h;
	if (ye > region_maxs[1])
		ye = region_maxs[1];
	ye = 64 * ceil (ye/64);

	// draw major blocks

	glColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);

	if ( g_qeglobals.d_showgrid )
	{
		
		glBegin (GL_LINES);
		
		for (x=xb ; x<=xe ; x+=64)
		{
			glVertex2f (x, yb);
			glVertex2f (x, ye);
		}
		for (y=yb ; y<=ye ; y+=64)
		{
			glVertex2f (xb, y);
			glVertex2f (xe, y);
		}
		
		glEnd ();
		
	}

	// draw minor blocks
	if ( g_qeglobals.d_showgrid && g_qeglobals.d_gridsize*g_qeglobals.d_xy.scale >= 4)
	{
		glColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);

		glBegin (GL_LINES);
		for (x=xb ; x<xe ; x += g_qeglobals.d_gridsize)
		{
			if ( ! ((int)x & 63) )
				continue;
			glVertex2f (x, yb);
			glVertex2f (x, ye);
		}
		for (y=yb ; y<ye ; y+=g_qeglobals.d_gridsize)
		{
			if ( ! ((int)y & 63) )
				continue;
			glVertex2f (xb, y);
			glVertex2f (xe, y);
		}
		glEnd ();
	}

	// draw coordinate text if needed

	if ( g_qeglobals.d_savedinfo.show_coordinates)
	{
		glColor4f(0, 0, 0, 0);

		for (x=xb ; x<xe ; x+=64)
		{
			glRasterPos2f (x, g_qeglobals.d_xy.origin[1] + h - 6/g_qeglobals.d_xy.scale);
			sprintf (text, "%i",(int)x);
			glCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
		}
		for (y=yb ; y<ye ; y+=64)
		{
			glRasterPos2f (g_qeglobals.d_xy.origin[0] - w + 1, y);
			sprintf (text, "%i",(int)y);
			glCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
		}
	}
}
Esempio n. 24
0
        void DrawGLScene ()
        {
            glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity ();

            glTranslatef (0.0f, 0.5f, -3.0f);

            float pos [4] = {0.0f, -1.0f, -1.0f, 0.0f};
            glLightfv (GL_LIGHT0, GL_POSITION, pos);

            if (!changeToViewPointB) ChangeView (&viewPointA, &viewPointB, 0.001f);

            glTranslatef (0.0f, 0.0f, viewPointA.zoomZ);

            glRotatef (viewPointA.angleX, 1.0f, 0.0f, 0.0f);
            glRotatef (viewPointA.angleY, 0.0f, 1.0f, 0.0f);
            glRotatef (viewPointA.angleZ, 0.0f, 0.0f, 1.0f);

            glEnable (GL_NORMALIZE);

            glEnable (GL_LIGHTING);

            glEnable (GL_TEXTURE_2D);

            glEnable (GL_CULL_FACE);
            glCullFace (GL_FRONT);

            glEnable (GL_DEPTH_TEST);

            glDisable (GL_TEXTURE_GEN_S);
            glDisable (GL_TEXTURE_GEN_T);

            glDisable (GL_BLEND);

            glBindTexture(GL_TEXTURE_2D, Texture [0]);


            glBegin(GL_QUADS);

                // Back Face
                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.7f);  // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.7f);  // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.7f);  // Top Left Of The Texture and Quad
                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.7f);  // Bottom Left Of The Texture and Quad

                // Top Face
                glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.7f);  // Top Left Of The Texture and Quad
                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  0.3f);  // Bottom Left Of The Texture and Quad
                glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  0.3f);  // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.7f);  // Top Right Of The Texture and Quad

                // Bottom Face
                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.7f);  // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.7f);  // Top Left Of The Texture and Quad
                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.3f);  // Bottom Left Of The Texture and Quad
                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.3f);  // Bottom Right Of The Texture and Quad

                // Right face
                glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.7f);  // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.7f);  // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.3f);  // Top Left Of The Texture and Quad
                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.3f);  // Bottom Left Of The Texture and Quad

                // Left Face
                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.7f);  // Bottom Left Of The Texture and Quad
                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.3f);  // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.3f);  // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.7f);  // Top Left Of The Texture and Quad

            glEnd ();


            glDisable (GL_TEXTURE_2D);

            glDisable (GL_NORMALIZE);

            glDisable (GL_LIGHTING);

            glDisable (GL_TEXTURE_GEN_S);
            glDisable (GL_TEXTURE_GEN_T);

            glDisable (GL_DEPTH_TEST);

            glEnable (GL_CULL_FACE);
            glCullFace (GL_BACK);

            glEnable (GL_BLEND);

            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

            float alpha = 0.5f;


            glBegin (GL_QUADS);

                // Back Face
                glColor4f(0.3f, 0.3f, 1.0f, alpha);
                glVertex3f(-1.0f, -1.0f, -1.7f);
                glVertex3f(-1.0f,  1.0f, -1.7f);
                glVertex3f( 1.0f,  1.0f, -1.7f);
                glVertex3f( 1.0f, -1.0f, -1.7f);

                // Top Face
                glColor4f(0.3f, 0.3f, 1.0f, alpha);
                glVertex3f(-1.0f,  1.0f, -1.7f);
                glVertex3f(-1.0f,  1.0f,  0.0f);
                glVertex3f( 1.0f,  1.0f,  0.0f);
                glVertex3f( 1.0f,  1.0f, -1.7f);

                // Bottom Face
                glColor4f(0.3f, 0.3f, 1.0f, alpha);
                glVertex3f(-1.0f, -1.0f, -1.7f);
                glVertex3f( 1.0f, -1.0f, -1.7f);
                glVertex3f( 1.0f, -1.0f,  0.0f);
                glVertex3f(-1.0f, -1.0f,  0.0f);

                // Right face
                glColor4f(0.3f, 0.3f, 1.0f, alpha);
                glVertex3f( 1.0f, -1.0f, -1.7f);
                glVertex3f( 1.0f,  1.0f, -1.7f);
                glVertex3f( 1.0f,  1.0f,  0.0f);
                glVertex3f( 1.0f, -1.0f,  0.0f);

                // Left Face
                glColor4f(0.3f, 0.3f, 1.0f, alpha);
                glVertex3f(-1.0f, -1.0f, -1.7f);
                glVertex3f(-1.0f, -1.0f,  0.0f);
                glVertex3f(-1.0f,  1.0f,  0.0f);
                glVertex3f(-1.0f,  1.0f, -1.7f);

            glEnd ();


            DrawNextTimeLayer ();


            glDisable (GL_TEXTURE_2D);

            glDisable (GL_LIGHTING);

            glDisable (GL_DEPTH_TEST);

            glLoadIdentity ();

            glTranslatef (0.0f, 0.0f, -3.0f);

            glColor3f (1.0f, 1.0f, 1.0f);
            glRasterPos2f (-2.2f, 1.15f);

            if (ShowInfo) Print ("PRESS [I] TO SHOW INFO");
            else          Print ("PRESS [I] TO HIDE INFO");


            if (ShowInfo)
            {
                glDisable (GL_TEXTURE_2D);

                glDisable (GL_LIGHTING);

                glDisable (GL_DEPTH_TEST);

                glLoadIdentity ();

                glTranslatef (0.0f, 0.0f, -3.0f);

                glColor3f (1.0f, 1.0f, 1.0f);
                glRasterPos2f (-2.2f, 0.95f);

                if (!Pause) Print ("[SIMULATION]");
                else        Print ("[PAUSE]");


                glRasterPos2f (-2.2f, 0.85f);
                Print ("Fluid surface");

                glRasterPos2f (-2.2f, 0.75f);
                Print ("deformation coefficient: %2.1f", CurrentWaveAmplitudeMode);

                glRasterPos2f (-2.2f, 0.65f);
                Print ("One drop in %2.1f seconds", CurrentWaveFrequencyMode * 2.0f);

                glRasterPos2f (-2.2f, 0.55f);
                Print ("Viscosity: %0.5f", VIS);

                glRasterPos2f (-2.2f, 0.45f);
                Print ("Wave propogation speed: %0.3f", ALPHA);


                glRasterPos2f (-2.2f, 0.25f);
                Print ("[p] - wave propogation speed");

                glRasterPos2f (-2.2f, 0.15f);
                Print ("[t] - frequency [v] - viscosity");

                glRasterPos2f (-2.2f, 0.05f);
                Print ("[h] - amplitude");

                glRasterPos2f (-2.2f, -0.15f);
                Print ("Press [key] to decrease value");

                glRasterPos2f (-2.2f, -0.25f);
                Print ("Press [shift] + [key] to increase value");


                glRasterPos2f (-2.2f, -0.45f);
                Print ("Press [q][w][e][a][s][d] to rotate the pool");

                glRasterPos2f (-2.2f, -0.55f);
                Print ("Press [-][=] to zoom in/out the pool");

                glRasterPos2f (-2.2f, -0.75f);
                Print ("Press [spacebar] to stop time");

                glRasterPos2f (-2.2f, -0.85f);
                Print ("Hold [spacebar] to calm fluid surface");

                glRasterPos2f (-2.2f, -0.95f);
                Print ("Press [r] to reset settings");


                glRasterPos2f (0.4f, 1.15f);
                Print ("Maximal height: %4.4f", MaxHeight);

                glRasterPos2f (0.4f, 1.05f);
                Print ("Average velocity: %1.7f", VelocitySum / (SIZE_X * SIZE_Y));
            }


            glutSwapBuffers ();
        }
Esempio n. 25
0
/*
==============
XY_Overlay
==============
*/
void XY_Overlay (void)
{
	int	w, h;
	int	r[4];
	static	vec3_t	lastz;
	static	vec3_t	lastcamera;


	glViewport(0, 0, g_qeglobals.d_xy.width, g_qeglobals.d_xy.height);

	//
	// set up viewpoint
	//
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity ();

	w = g_qeglobals.d_xy.width/2 / g_qeglobals.d_xy.scale;
	h = g_qeglobals.d_xy.height/2 / g_qeglobals.d_xy.scale;
	glOrtho (g_qeglobals.d_xy.origin[0] - w, g_qeglobals.d_xy.origin[0] + w
		, g_qeglobals.d_xy.origin[1] - h, g_qeglobals.d_xy.origin[1] + h, -8000, 8000);
	//
	// erase the old camera and z checker positions
	// if the entire xy hasn't been redrawn
	//
	if (g_qeglobals.d_xy.d_dirty)
	{
		glReadBuffer (GL_BACK);
		glDrawBuffer (GL_FRONT);

		glRasterPos2f (lastz[0]-9, lastz[1]-9);
		glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
		glCopyPixels(r[0], r[1], 18,18, GL_COLOR);

		glRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
		glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
		glCopyPixels(r[0], r[1], 100,100, GL_COLOR);
	}
	g_qeglobals.d_xy.d_dirty = true;

	//
	// save off underneath where we are about to draw
	//
	VectorCopy (z.origin, lastz);
	VectorCopy (camera.origin, lastcamera);

	glReadBuffer (GL_FRONT);
	glDrawBuffer (GL_BACK);

	glRasterPos2f (lastz[0]-9, lastz[1]-9);
	glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
	glCopyPixels(r[0], r[1], 18,18, GL_COLOR);

	glRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
	glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
	glCopyPixels(r[0], r[1], 100,100, GL_COLOR);

	//
	// draw the new icons
	//
	glDrawBuffer (GL_FRONT);

    glShadeModel (GL_FLAT);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_1D);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
	glColor3f(0, 0, 0);

	DrawCameraIcon ();
	DrawZIcon ();

	glDrawBuffer (GL_BACK);
    glFinish();
}
Esempio n. 26
0
template< > inline void glRasterPos2< float >			( float x,float y )			{	glRasterPos2f(x,y);	};
Esempio n. 27
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	if(msec < 1.0f)
		accumulator += msec;
	else
		accumulator += dt;

	while(accumulator >= dt)
	{
		//for (int i = 0; i < 5; i++)
		mWorld->update(dt);
		accumulator -= dt; 
	}


	if (mouseD == true)
    {
        if (dragBody != NULL)
        {
           PointMass *pm = dragBody->getPointMass(dragPoint);
			dragBody->setDragForce(VectorTools::calculateSpringForce(pm->Position, pm->Velocity, Vector2(dragX,dragY), Vector2::ZERO, 0.0f, 100.0f, 10.0f), dragPoint);
        }
    }
    else
    {
        dragBody = NULL;
        dragPoint = -1;
    }

	if(mouseD == true)
	{
		if(dragBody == NULL)
		{
			int body;
            mWorld->getClosestPointMass(Vector2(dragX,dragY), body, dragPoint);
			if(mWorld->getBody(body)->Type == 2)
				dragBody = (SpringBody*)mWorld->getBody(body);
		}
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear Screen And Depth Buffer
    glLoadIdentity();

    //draw text
	glColor3f(0,0,0);
	glRasterPos2f(-24,23);
	glPrint("FPS: %4d  AVG: %3.1f  MS: %3f\n", fps, average, msec);	


	bod->DrawMe();

	for(unsigned int i = 0;i < pressureBodies.size();i++)
		pressureBodies[i]->DrawMe();

	for(unsigned int i = 0;i < springBodies.size();i++)
		springBodies[i]->DrawMe();

	for(unsigned int i = 0;i < fallingBodies.size();i++)
		fallingBodies[i]->DrawMe();

	//draw line from body to cursor
	if(dragBody != NULL)
	{
		Renderer::RenderLine(dragBody->getPointMass(dragPoint)->Position,Vector2(dragX,dragY),0,0,1);
	}
	
	return TRUE;										// Keep Going
}
Esempio n. 28
0
static void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable (GL_LINE_SMOOTH);
    glEnable (GL_BLEND);
    glEnable (GL_POLYGON_SMOOTH);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);

    
    glColor3f(0.6,0.3,0.0);
    rectangle(GL_QUADS);

    glColor3f(1.0,1.0,1.0);
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0xF0F0);
    glLineWidth(3.0f);
    glBegin(GL_LINE_LOOP);
        glVertex2f(-1,-0.7);
        glVertex2f(1,-0.7);
        glVertex2f(1,-0.1);
        glVertex2f(-1,-0.1);
    glEnd();

    glColor3f(1.0,1.0,1.0);
    glPushMatrix();
        glTranslatef(-.65,-.15,0);
        glColor3f(0.2,1.0,.2);
        triangle();
    glPopMatrix();

    glPushMatrix();
        glTranslatef(-.65,.95,0);
        glColor3f(0.0,0.0,0.0);
        triangle(); 
    glPopMatrix();

    glPushMatrix();
        glColor3f(0.0,0.0,0.0);
        glTranslatef(0.0,.78,0.0);
        drawCircle(0.18f);
    glPopMatrix();

    glPushMatrix();
        glColor3f(1.0,0.0,0.0);
        glTranslatef(0.0,-0.3,0.0);
        drawCircle(0.18f);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0.0,-0.05,0.0);
    glScalef(0.08,0.007,0.08);
    //glPointSize(0.5f);
    glBegin(GL_POINTS);
    for (float i=-19.0f; i < 109.5f; i += .5f) {
        glColor3f(0,i*.1,i*-.1);
        glVertex2f(i,sin(i)*3);
    }
    glEnd();
    glPopMatrix();

    glPushMatrix();
    char* string = "Brian Gianforcaro - RIT 2008/2009";
    int len = (int) strlen(string);
    glColor3f(1.0,1.0,1.0);
    glRasterPos2f(-0.4,1.05);
    for (int i = 0; i < len; i++) {
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, string[i]);
    }
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0.45,-.54,0);
        glEnable(GL_POLYGON_STIPPLE);
        glPolygonStipple(stippleBits);
        glBegin(GL_POLYGON);
            glColor3f(1.0,0,0);
            glVertex2f(0,0);
            glColor3f(0,1.0,0);
            glVertex2f(.4,0);
            glColor3f(0,0,1.0);
            glVertex2f(.4,.4);
            glColor3f(1.0,1.0,1.0);
            glVertex2f(0,.4);
        glEnd();
    glPopMatrix();
    glDisable(GL_POLYGON_STIPPLE);

    glColor3f(0,0,0);
    glPushMatrix();
        glTranslatef(0.45,.56,0);
        glBegin(GL_POLYGON);
            glVertex2f(0,0);
            glVertex2f(.4,0);
            glVertex2f(.4,.4);
            glVertex2f(0,.4);
        glEnd();
    glPopMatrix();


    glColor3f(1,1,1);
    glDisable(GL_LINE_STIPPLE);
    glPushMatrix();
    glTranslatef(-1,-1.1,0);
        glBegin(GL_LINES);
        for (float i = 0; i < 2.1; i+=.1f) {
            glVertex2f(i, 0);
            glVertex2f(i, .3);
        }
        for (float i = 0; i < .35; i+=.05f) {
            glVertex2f(0, i);
            glVertex2f(2, i);
        }
        glEnd();
    glPopMatrix();


    glFlush();
}
Esempio n. 29
0
/** 在指定位置输出字符串 */
void GLFont::PrintText(char *string, float x, float y)
{
	HBITMAP hBitmap,hOldBmp; /**< 定义两个位图句柄 */
	BITMAP bm;               /**< 位图结构变量 */
	SIZE size;               /**< 位图尺寸 */
	GLboolean lp,tp;
	HDC hDC = ::CreateCompatibleDC(0); /**< 暂存设备场景 */
	glGetBooleanv(GL_LIGHTING,&lp);  /**< 查看场景中是否有光照 */
	glGetBooleanv(GL_TEXTURE_2D,&tp);/**< 查看场景中是否启用纹理 */
	/** 保存和设置一些属性 */
	glLoadIdentity();
	glPushMatrix();
	glTranslatef(0,0,-10.0f);
	glDisable(GL_LIGHTING);    /**< 关闭光照 */
	glDisable(GL_TEXTURE_2D);  /**< 关闭纹理 */
	glDisable(GL_DEPTH_TEST);  /**< 关闭深度测试 */
	SelectObject(hDC, m_hFont); /**< 选择字体 */
	::GetTextExtentPoint32(hDC, string, strlen(string), &size);/**< 获取字符位图大小 */
	hBitmap = CreateBitmap(size.cx, size.cy,1, 1, NULL); /**< 创建与hDC相关单色位图 */
	hOldBmp = (HBITMAP)SelectObject(hDC,hBitmap); /**< 选择位图 */
  
	SetBkColor(hDC, RGB(0, 0, 0));              /**< 背景色为黑色 */
	SetTextColor(hDC, RGB(255, 255, 255));      /**< 字体颜色白色 */
	SetBkMode(hDC, OPAQUE);                     /**< 用当前的背景颜色填充背景 */
	TextOut(hDC, 0, 0, string, strlen(string)); /**< 输出文字到暂存hDC */
	/** 获得相关位图数据结构 */
	GetObject(hBitmap, sizeof(bm), &bm);
	size.cx = (bm.bmWidth + 31) & (~31); /**< 边缘对齐 */
	size.cy = bm.bmHeight;
	int bufsize = size.cx * size.cy/8;  /**< 图形数据长度 */
    /** 定义单色位图结构 */  
	struct {
	BITMAPINFOHEADER bih;
	RGBQUAD col[2];
	}bic;
    /** 获取单色位图结构信息 */
	BITMAPINFO *binf = (BITMAPINFO *)&bic;
	binf->bmiHeader.biSize = sizeof(binf->bmiHeader); /**< 修改结构信息 */
	binf->bmiHeader.biWidth = bm.bmWidth;
	binf->bmiHeader.biHeight = bm.bmHeight;
	binf->bmiHeader.biPlanes = 1;
	binf->bmiHeader.biBitCount = 1;       /**< 单色 */
	binf->bmiHeader.biCompression = BI_RGB;  /**< 颜色方式 */
	binf->bmiHeader.biSizeImage = bufsize;
	binf->bmiHeader.biXPelsPerMeter = 1;
	binf->bmiHeader.biYPelsPerMeter = 1;
	binf->bmiHeader.biClrUsed = 0;
	binf->bmiHeader.biClrImportant = 0;
	/** 定义图形数据块 */ 
	UCHAR* pBmpBits = new UCHAR[bufsize];	
	memset(pBmpBits, 0, sizeof(UCHAR)*bufsize);
	/** 将设备无关数据保存在pBmpBits指向的数据块中 */
	::GetDIBits(hDC, hBitmap, 0, bm.bmHeight, pBmpBits, binf,DIB_RGB_COLORS);
	 
	/** 显示字符串 */
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /**< 指定像素存储模式 */
	glRasterPos2f(x,y);                  /**< 定位 */
	glBitmap(size.cx, size.cy, 0.0, 0.0, 0.0, 0.0, pBmpBits); /**< 位图显示 */
	delete pBmpBits;                       /**< 删除指针 */
	SelectObject(hDC, hOldBmp);           /**< 恢复原来位图信息 */
	DeleteObject(hBitmap);
	::DeleteDC(hDC);
	/** 恢复一些属性 */
	if(lp)
         glEnable(GL_LIGHTING);       /**< 启用光照 */
	if(tp)
		glEnable(GL_TEXTURE_2D);      /**< 启用纹理 */
	glEnable(GL_DEPTH_TEST);          /**< 启用深度测试 */
	glPopMatrix();
}
Esempio n. 30
0
enum piglit_result
test_bitmap(void *null)
{
	GLuint pb_unpack[1];
	GLuint pb_pack[1];
	int use_unpack = 1;
	int use_pack = 0;
	GLubyte bitmap[TEXSIZE * TEXSIZE / 8];
	GLfloat buf[WINSIZE * WINSIZE * 3];
	GLfloat white[3] = { 1.0, 1.0, 1.0 };
	GLfloat black[3] = { 0.0, 0.0, 0.0 };
	int i, j;
	GLubyte *pbo_unpack_mem = NULL;
	GLfloat *pbo_pack_mem = NULL;
	GLfloat expected[WINSIZE * WINSIZE * 3];
	float tolerance[4];
	bool pass = true;

	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
	glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);

	for (use_pack = 0; use_pack < 2; use_pack++) {
		for (use_unpack = 0; use_unpack < 2;
		   use_unpack++) {
			glClearColor(0.0, 0.0, 0.0, 1.0);
			glClear(GL_COLOR_BUFFER_BIT);

			if (use_unpack) {
				glGenBuffersARB(1, pb_unpack);
				glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB,
						pb_unpack[0]);
				glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,
						TEXSIZE * TEXSIZE,
						NULL, GL_STREAM_DRAW);
				pbo_unpack_mem = (GLubyte *) glMapBufferARB(
						GL_PIXEL_UNPACK_BUFFER_ARB,
						GL_WRITE_ONLY);
			}
			else {
				pbo_unpack_mem = bitmap;
			}

			for (i = 0; i < TEXSIZE * TEXSIZE / 8; i++) {
				pbo_unpack_mem[i] = 0xAA; /* Binary 10101010 */
			}


			glColor4f(1.0, 1.0, 1.0, 0.0);
			glRasterPos2f(0.0, 0.0);
			if (use_unpack) {
				glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
				/* Draw white into every other pixel,
				 * for a white/black checkerboard. */
				glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0, NULL);
				glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB,
						0);
			}
			else {
				glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0,
					 pbo_unpack_mem);
			}

			if (!piglit_automatic)
				piglit_present_results();

			/* Check the result */
			if (use_pack) {
				glGenBuffersARB(1, pb_pack);
				glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB,
						pb_pack[0]);
				glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB,
						WINSIZE * WINSIZE *
						4 * sizeof(GLfloat), NULL,
						GL_STREAM_DRAW);
				glReadPixels(0, 0, WINSIZE, WINSIZE,
					     GL_RGB, GL_FLOAT,
					     NULL);
				pbo_pack_mem =
					(GLfloat *) glMapBufferARB(
						GL_PIXEL_PACK_BUFFER_ARB,
						GL_READ_ONLY);
			}
			else {
				pbo_pack_mem = buf;
				glReadPixels(0, 0, WINSIZE, WINSIZE,
					     GL_RGB, GL_FLOAT, pbo_pack_mem);
			}

			/* Compute expected and compare it to the result. */
			for (j = 0; j < WINSIZE; j++) {
				for (i = 0; i < WINSIZE; i++) {
					int idx = (j * WINSIZE + i) * 3;
					if ((i & 1) || (i >= TEXSIZE) ||
					   (j >= TEXSIZE)) {
						expected[idx + 0] = black[0];
						expected[idx + 1] = black[1];
						expected[idx + 2] = black[2];
					}
					else {
						expected[idx + 0] = white[0];
						expected[idx + 1] = white[1];
						expected[idx + 2] = white[2];
					}
				}
			}
			piglit_compute_probe_tolerance(GL_RGB, &tolerance[0]);
			pass &= piglit_compare_images_color(0, 0, WINSIZE,
							    WINSIZE, 3,
							    tolerance,
							    expected,
							    pbo_pack_mem);

			if (use_pack) {
				glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
				glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
				glDeleteBuffersARB(1, pb_pack);
			}

			if (use_unpack) {
				glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
				glDeleteBuffersARB(1, pb_unpack);
			}
		}
	}
	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}