Game Programming Using QT 全书笔记
2017-03-19 16:56
281 查看
01. 字符串的处理
QString基本上和String是相同的
QString contains a split() method that takes the separator string as its parameter and returns a list of string that are represented in Qt by the QStringList class.
Methods such as toInt(), toDouble(), or toLongLong() make it easy to extract numberical values from strings.
02.第四章比较晦涩,一些字符串的处理,以及保存一些东西,以后需要的时候在学习。
现在遵循的宗旨是看Qt,看不懂的就跳过,再看不懂的再跳过。
直到看懂为止,努力学习,结合官网。
Chapter 5: Graphics with Qt
03.主要学会的知识
绘制2D和3D图形,
不怎会会,要求有点高。
贴上源码
04. 绘制一个棋盘
国际象棋的走法是什么呢?
需要理解国际象棋的下法,然后写出相应的源码出来吗?
那就下写中国想起怎么样?
可是不会写啊!
Game Programming Using QT
非常好的一本书。
05. opengl qt中使用
总结:
In this chapter, we learn about using graphics with Qt. You should be aware we have only scratched the surface of Qt capabilities in this regard. What was presented in this chapter will let you implement custom widgets, do some basic painting on images,
and render OpenGL scenes. There are many more functionalities that we didn't go through, such as composition modes, paths, SVG handling, and many others. We will come back to some of these features in subsequent chapters, but we will leave most for you to
discover on your own.
Chapter 6: Graphics View
QString基本上和String是相同的
QString contains a split() method that takes the separator string as its parameter and returns a list of string that are represented in Qt by the QStringList class.
Methods such as toInt(), toDouble(), or toLongLong() make it easy to extract numberical values from strings.
02.第四章比较晦涩,一些字符串的处理,以及保存一些东西,以后需要的时候在学习。
现在遵循的宗旨是看Qt,看不懂的就跳过,再看不懂的再跳过。
直到看懂为止,努力学习,结合官网。
Chapter 5: Graphics with Qt
03.主要学会的知识
绘制2D和3D图形,
不怎会会,要求有点高。
贴上源码
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = customwidget TEMPLATE = app SOURCES += main.cpp\ widget.cpp HEADERS += widget.h
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { Q_OBJECT Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionChanged) Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionChanged) public: Widget(QWidget *parent = 0); ~Widget(); int selectionStart() const { return m_selectionStart; } int selectionEnd() const { return m_selectionEnd; } public slots: void addPoint(unsigned yVal) { m_points << qMax(0u, yVal); update(); } void clear() { m_points.clear(); update(); } signals: void selectionChanged(); protected: void paintEvent(QPaintEvent *); void drawChart(QPainter *painter, const QRect &rect, const QRect &exposedRect); void drawSelection(QPainter *painter, const QRect &rect, const QRect &exposedRect); void mousePressEvent(QMouseEvent *mouseEvent); void mouseMoveEvent(QMouseEvent *mouseEvent); QList<quint16> m_points; int m_selectionStart; int m_selectionEnd; }; #endif // WIDGET_H
#include "widget.h" #include <QMouseEvent> #include <QPainter> Widget::Widget(QWidget *parent) : QWidget(parent), m_selectionStart(-1), m_selectionEnd(-1) { } Widget::~Widget() { } void Widget::paintEvent(QPaintEvent *pe) { QRect exposedRect = pe->rect(); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); QPen pen(Qt::black); pen.setWidth(4); 4000 painter.setPen(pen); QRect r = rect().adjusted(10, 10, -10, -10); painter.drawRoundedRect(r, 20, 10); painter.save(); r.adjust(2, 2, -2, -2); painter.setViewport(r); r.moveTo(0, -r.height()/2); painter.setWindow(r); drawSelection(&painter, r, exposedRect); drawChart(&painter, r, exposedRect); painter.restore(); } void Widget::drawChart(QPainter *painter, const QRect &, const QRect &exposedRect) { painter->setPen(Qt::red); painter->drawLine(exposedRect.left(), 0, exposedRect.width(), 0); painter->save(); painter->setRenderHint(QPainter::Antialiasing, false); const int lastPoint = qMin(m_points.size(), exposedRect.right()+1); for(int i=exposedRect.left(); i < lastPoint; ++i) { if(m_selectionStart <= i && m_selectionEnd >=i) { painter->setPen(Qt::white); } else painter->setPen(Qt::blue); painter->drawLine(i, -m_points.at(i), i, m_points.at(i)); } painter->restore(); } void Widget::mousePressEvent(QMouseEvent *mouseEvent) { m_selectionStart = m_selectionEnd = mouseEvent->pos().x() - 12; emit selectionChanged(); update(); } void Widget::mouseMoveEvent(QMouseEvent *mouseEvent) { m_selectionEnd = mouseEvent->pos().x() - 12; emit selectionChanged(); update(); } void Widget::drawSelection(QPainter *painter, const QRect &rect, const QRect &exposedRect) { if(m_selectionStart < 0 ) return; painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(palette().highlight()); QRect selectionRect = rect; selectionRect.setLeft(m_selectionStart); selectionRect.setRight(m_selectionEnd); painter->drawRect(selectionRect.intersected(exposedRect)); painter->restore(); }
#include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; for(int i=0;i<450;++i) w.addPoint(qrand() % 120); w.show(); return a.exec(); }
04. 绘制一个棋盘
国际象棋的走法是什么呢?
需要理解国际象棋的下法,然后写出相应的源码出来吗?
那就下写中国想起怎么样?
可是不会写啊!
Game Programming Using QT
非常好的一本书。
05. opengl qt中使用
总结:
In this chapter, we learn about using graphics with Qt. You should be aware we have only scratched the surface of Qt capabilities in this regard. What was presented in this chapter will let you implement custom widgets, do some basic painting on images,
and render OpenGL scenes. There are many more functionalities that we didn't go through, such as composition modes, paths, SVG handling, and many others. We will come back to some of these features in subsequent chapters, but we will leave most for you to
discover on your own.
Chapter 6: Graphics View
相关文章推荐
- Game Programming Using QT第三章
- 使用Java语言进行2D游戏编程基础 Fundamental 2D Game Programming with Java 全书笔记(未完结)
- 5.7 a simple method for rendering gemstones--game programming gems 5 笔记
- Isometric Game Programming 笔记(三)格子间的移动
- Introduction to 3D Game Programming with DirectX 11学习笔记 6 Direct3D中的绘制(四)渲染状态
- 5.2 let it snow--game programming gems 5 笔记
- Introduction to 3D Game Programming with DirectX 11学习笔记 6 Direct3D中的绘制(二)顶点着色器
- Introduction to 3D Game Programming with DirectX 11学习笔记 6 Direct3D中的绘制(一)
- Isometric Game Programming 笔记(四)移动鼠标来滚动视图
- Introduction to 3D Game Programming with DirectX 11学习笔记 4.2Direct3D进行初始化
- Introduction to 3D Game Programming with DirectX 11学习笔记 4.1 初识Direct3D
- Introduction to 3D Game Programming with DirectX 11学习笔记 6 Direct3D中的绘制(三)像素着色器
- 5.10 recombinant shaders--game programming gems 笔记
- Introduction to 3D Game Programming with DirectX 11学习笔记 1~3章
- Introduction to 3D Game Programming with DirectX 11学习笔记 4.4 演示程序框架
- Introduction to 3D Game Programming with DirectX 11学习笔记 5 渲染管线(三)
- Beginning C++ Through Game Progamming 全书学习笔记
- 3D Game Programming for Kids 学习笔记
- Introduction to 3D Game Programming with DirectX 11学习笔记 5 渲染管线(一)
- 5.3 widgets:rendering fast and persistent foliage--game programming gems 5笔记