Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gui pisan u c
#23
Ovde su neki osnovni primeri sa OpenGL u C preko standardne GLUT biblioteke:
https://www.opengl.org/archives/resource...mples.html

Ovo je isto GLUT samo u C++ varijanti:
https://cs.lmu.edu/~ray/notes/openglexamples/

GLSL - tutorial o shejderima:
https://learnopengl.com/Getting-started/Shaders

Konkretno jedan minimalan primer sa Fontovima i transformacijom

[Image: attachment.php?aid=37997]

Code:
/* Copyright (c) Mark J. Kilgard, 1994. */

/* This program is freely distributable without licensing fees
   and is provided without guarantee or warrantee expressed or
   implied. This program is -not- in the public domain. */

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <GL/glut.h>

void
bitmap_output(int x, int y, char *string, void *font)
{
  int len, i;

  glRasterPos2f(x, y);
  len = (int) strlen(string);
  for (i = 0; i < len; i++) {
    glutBitmapCharacter(font, string[i]);
  }
}

void
stroke_output(GLfloat x, GLfloat y, char *format,...)
{
  va_list args;
  char buffer[200], *p;

  va_start(args, format);
  vsprintf(buffer, format, args);
  va_end(args);
  glPushMatrix();
  glTranslatef(x, y, 0);
  glScalef(0.005, 0.005, 0.005);
  for (p = buffer; *p; p++)
    glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
  glPopMatrix();
}

void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  bitmap_output(40, 35, "This is written in a GLUT bitmap font.",
    GLUT_BITMAP_TIMES_ROMAN_24);
  bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.",
    GLUT_BITMAP_9_BY_15);
  bitmap_output(70, 240, "                Helvetica is yet another bitmap font.",
    GLUT_BITMAP_HELVETICA_18);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluPerspective(40.0, 1.0, 0.1, 20.0);
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  gluLookAt(0.0, 0.0, 4.0,  /* eye is at (0,0,30) */
    0.0, 0.0, 0.0,      /* center is at (0,0,0) */
    0.0, 1.0, 0.);      /* up is in postivie Y direction */
  glPushMatrix();
  glTranslatef(0, 0, -4);
  glRotatef(50, 0, 1, 0);
  stroke_output(-2.5, 1.1, "  This is written in a");
  stroke_output(-2.5, 0, " GLUT stroke font.");
  stroke_output(-2.5, -1.1, "using 3D perspective.");
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glFlush();
}

void
reshape(int w, int h)
{
  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, w, 0, h);
  glScalef(1, -1, 1);
  glTranslatef(0, -h, 0);
  glMatrixMode(GL_MODELVIEW);
}

int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(465, 250);
  glutCreateWindow("GLUT bitmap & stroke font example");
  glClearColor(1.0, 1.0, 1.0, 1.0);
  glColor3f(0, 0, 0);
  glLineWidth(3.0);
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}


Attached Files Thumbnail(s)

Reply


Messages In This Thread
Gui pisan u c - by savan - 07-19-2022, 10:25 AM
RE: Gui pisan u c - by savan - 07-19-2022, 10:32 AM
RE: Gui pisan u c - by savan - 07-19-2022, 10:58 AM
RE: Gui pisan u c - by savan - 07-19-2022, 12:21 PM
RE: Gui pisan u c - by mikikg - 07-19-2022, 09:44 PM
RE: Gui pisan u c - by mikikg - 07-19-2022, 10:40 PM
RE: Gui pisan u c - by savan - 07-20-2022, 10:43 AM
RE: Gui pisan u c - by mikikg - 07-20-2022, 01:42 PM
RE: Gui pisan u c - by savan - 07-20-2022, 02:59 PM
RE: Gui pisan u c - by gorankg - 07-20-2022, 08:52 PM
RE: Gui pisan u c - by savan - 07-20-2022, 09:45 PM
RE: Gui pisan u c - by mikikg - 07-20-2022, 10:23 PM
RE: Gui pisan u c - by savan - 07-21-2022, 08:11 AM
RE: Gui pisan u c - by mikikg - 07-21-2022, 10:20 AM
RE: Gui pisan u c - by savan - 07-22-2022, 06:50 PM
RE: Gui pisan u c - by mikikg - 07-22-2022, 07:36 PM
RE: Gui pisan u c - by savan - 07-22-2022, 07:55 PM
RE: Gui pisan u c - by mikikg - 07-22-2022, 07:56 PM
RE: Gui pisan u c - by savan - 07-23-2022, 07:45 AM
RE: Gui pisan u c - by savan - 07-23-2022, 02:08 PM
RE: Gui pisan u c - by mikikg - 07-23-2022, 07:41 PM
RE: Gui pisan u c - by mikikg - 07-23-2022, 08:03 PM
RE: Gui pisan u c - by mikikg - 07-23-2022, 08:44 PM
RE: Gui pisan u c - by savan - 07-24-2022, 09:19 AM
RE: Gui pisan u c - by savan - 07-24-2022, 09:45 AM
RE: Gui pisan u c - by savan - 07-24-2022, 10:07 AM
RE: Gui pisan u c - by mikikg - 07-24-2022, 11:35 AM
RE: Gui pisan u c - by savan - 07-24-2022, 12:48 PM
RE: Gui pisan u c - by savan - 07-24-2022, 01:01 PM
RE: Gui pisan u c - by mikikg - 07-24-2022, 01:04 PM
RE: Gui pisan u c - by savan - 07-24-2022, 03:48 PM
RE: Gui pisan u c - by mikikg - 07-24-2022, 06:10 PM
RE: Gui pisan u c - by savan - 07-24-2022, 08:35 PM
RE: Gui pisan u c - by savan - 07-25-2022, 04:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)