Created
May 16, 2020 07:28
-
-
Save HamedMasafi/e66416ee502364b821a2b6e13e87d9a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "myglwidget.h" | |
#include <QOpenGLContext> | |
#include <QOpenGLFunctions> | |
#include <QtMath> | |
#include <QDebug> | |
MyGlWidget::MyGlWidget(QWidget *parent) : QOpenGLWidget(parent) | |
{ | |
} | |
void MyGlWidget::initializeGL() | |
{ | |
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); | |
f->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
f->glClearDepthf(1.0f); | |
f->glEnable(GL_DEPTH_TEST); | |
f->glDepthFunc(GL_LEQUAL); | |
} | |
void MyGlWidget::resizeGL(int w, int h) | |
{ | |
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); | |
f->glViewport(0, 0, w, h); | |
qDebug() <<w<<h; | |
this->w = w; | |
this->h = h; | |
// //setup the projection and switch to model view for transformations | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glOrtho(-1, 1, -1, 1, -1, 1); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
} | |
void print_bitmap_string(/*void* font,*/ char* s) | |
{ | |
while (*s) { | |
glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *s); | |
s++; | |
} | |
} | |
void MyGlWidget::paintGL() | |
{ | |
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); | |
f->glClear (GL_COLOR_BUFFER_BIT); | |
f->glClear(GL_DEPTH_BUFFER_BIT); | |
glLoadIdentity(); | |
glColor3f(0, 1, 0); | |
glLineWidth(2); | |
glBegin(GL_LINES); | |
for (int i = 1; i < w; i += 10) { | |
double x1 = i; | |
double y1 = 0; | |
double x2 = i; | |
double y2 = h; | |
x1 = 2*x1 / w - 1; | |
y1 = 2*y1 / h - 1; | |
x2 = 2*x2 / w - 1; | |
y2 = 2*y2 / h - 1; | |
glVertex2f(x1, y1); | |
glVertex2f(x2, y2); | |
} | |
glEnd(); | |
{ | |
char* bitmap_font_names[7] = {"This is my firs text"}; | |
GLfloat x, y, ystep, yild, stroke_scale; | |
/* Draw the strings, according to the current mode and font. */ | |
glTranslatef(0.5,-1.0,0); | |
glColor4f(1.0, 1.0, 0.0, 0.0); | |
x = -225.0; | |
y = 70.0; | |
ystep = 100.0; | |
yild = 20.0; | |
glRasterPos2f(-150, y+1.25*yild); | |
print_bitmap_string(bitmap_font_names[0]); | |
} | |
f->glFlush (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment