我正在使用openGL和"freeglut"库进行体积渲染和显示.在主线程中,我初始化openGL窗口,然后逐帧获取体积数据,体积渲染在获取一个体数据后完成.这很好用,但需要很长时间.是否有可能继续在主线程中初始化openGL窗口,并在另一个线程中进行体积渲染和显示?我检查了wglMakeCurrent,它没有更新主线程中初始化的窗口.
我正在使用openframeworks(通过OpenGL渲染),我正在尝试从它的中心旋转图像.
我知道我应该使用ofRotate(),ofTranslate()但我没有设法自己解决.这是我到目前为止所尝试的:
ofPushMatrix();
ofRotate(ofRandom(10),0.0,0.0,1.0);
leafImg.draw(100,100);
ofPopMatrix();
Run Code Online (Sandbox Code Playgroud) 我试图在visual studio 2010中使用openGL,到目前为止我的代码看起来都是这样
#include<gl\GLU.h>
#include<gl\GL.h>
int main(int argc, char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Simple GLUT application");
glutMainLoop();
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio不承认任何过剩方法,并且抛出诸如"glutInit not recognized"之类的错误
我知道如何链接库是一个错误,但我是新的,所以请善待.有谁知道如何让这个例子正常工作?
我正在使用一个简单的旋转多边形,当用户点击并向上拖动时它应加速,并在用户点击并向下拖动时向下显示.不幸的是,我已经搜索了所有的东西,似乎无法找到任何特定的GL功能或变量,很容易让我操纵速度(我也搜索过"帧速率",也是......)
是否有一个简单的电话/一系列电话来做这样的事情,或者我是否真的需要在代码的不同部分用计时器做事情?
我的代码如下工作:绘制一个三角形,然后当点击"1"时,三角形被缩放,但发生的是三角形都被缩放和翻译.
这是我的代码:全局变量
#include <glut.h>
void Display(void);
void MyKeyboard(unsigned char,int,int);
void MyMouse(int,int,int,int);
int x1 =20 .0f;
int y1 = 30.0f;
int x2 = 40.0f;
int y2 = 50.0f;
int x3 = 60.0f;
int y3 = 10.0f;
Run Code Online (Sandbox Code Playgroud)
主要方法
void main(int argc,char** argr)
{
glutInit(&argc,argr);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000,600);
glutInitWindowPosition(50,50);
glutCreateWindow("Mouse and Keyboard");
glutDisplayFunc(Display);
glutKeyboardFunc(MyKeyboard);
glutMouseFunc(MyMouse);
glClearColor(0.0f,0.0f,0.0f,0.0f);
gluOrtho2D(0.0,1000.0,0.0,600.0);
glutMainLoop();
}
Run Code Online (Sandbox Code Playgroud)
显示方法
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x1, 600-y1, 0.0f);
glVertex3f(x2, 600-y2, 0.0f);
glVertex3f(x3, 600-y3, 0.0f);
glEnd( );
glPopMatrix();
glFlush();
}
Run Code Online (Sandbox Code Playgroud)
键盘事件
void MyKeyboard(unsigned …Run Code Online (Sandbox Code Playgroud) 我目前正在为我的应用程序运行一些速度测试,我正在尝试找到更多方法来优化我的程序,特别是我的显示列表.目前我得到:
12 FPS,882,000个顶点
40 FPS,234,000个顶点
95 FPS,72,000个顶点
我知道我需要尽量减少拨打电话的数量,所以不要:
for(int i = 0; i < Number; i++) {
glBegin(GL_QUADS);
...normal and vertex declarations here
glEnd();
}
Run Code Online (Sandbox Code Playgroud)
更好的方法是这样做:
glBegin(GL_QUADS);
for(int i = 0; i < Number; i++) {
...normal and vertex declarations here
}
glEnd();
Run Code Online (Sandbox Code Playgroud)
这确实有助于将我的FPS提高到上面列出的结果,但是,还有其他方法可以优化我的显示列表吗?也许通过使用嵌套顶点数组以外的东西来存储我的模型数据?
我有一个编译着色器或程序(不确定正确的术语),我需要删除它.
如何找到已编译程序和/或着色器的ID?
我知道它存在是因为调试器告诉我我正在尝试重新定义它,并且因为这个而无法再次编译它:
ERROR: 0:1: error(#198) Redefinition at_coord_Y
ERROR: 1:1: error(#248) Function already has a body main
Run Code Online (Sandbox Code Playgroud)
着色器源的第一行是:
"in float at_coord_Y;"
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式使用它来找到Id吗?
编辑1:希望澄清一下,着色器无法编译,因为它已经存在.
GLint compiled = UNDEFINED_VALUE;
const GLchar* shaderSrc[] = {
"in float at_coord_Y;",
"void main()",
"{",
// Dont mind the empty space
"}"
};
GLuint shaderId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shaderId, glNumberOfLines(shaderSrc), shaderSrc, NULL);
glCompileShader(shaderId); // Fail to compile because it already exists. Redefinition error.
glGetShaderiv(shaderId), GL_COMPILE_STATUS, &compiled); // Compile status GL_FALSE
Run Code Online (Sandbox Code Playgroud)
但是如何找到现有着色器(或程序)的Id?
我的问题是在背景图像上方或上方绘制多边形或其他一些OpenGL基元.总结不同层中的油漆,但在OpenGL中,我认为没有层.
现在我正在尝试在背景图像上绘制一个三角形和一条线.
为了绘制背景,我使用具有OpenGL窗口大小的正方形,然后将png图像应用于此正方形作为纹理.
之后我尝试用不同颜色绘制三角形和线条,但除了背景图像之外我什么都看不到.
我玩alpha通道,但我没有看到任何东西.
码:
void init()
{
// glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
// The following two lines enable semi transparent
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
int width, height;
bool hasAlpha;
char filename[] = "prueba-luz.png";
bool success = loadPngImage(filename, width, height, hasAlpha, &textureImage);
if (!success)
{
cout << "Unable to load png file" << endl;
return;
}
cout << "Image loaded " << width << " " << height << " alpha " << hasAlpha << endl;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的代码,只是绘制一个建筑物,我想添加建筑物的阴影.我已经尝试了很多代码示例,但要么它们太复杂了,而且绘制了一些对象.或者太模糊了 我怎样才能看到建筑的阴影?
#include "GLee/GLee.h" //GL header file, including extensions
#include "glut.h"
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "tga.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
char g_SelectedColor = 'w';
int g_Width;
int g_Height;
int a=0.0 ,b=0.0, c=500, d=0.0, e=0.0, f=0.0,g=0.0,h=1.0,i=0.0;
static int rotationAngle=0;
void init();
void myMouseFunction( int button, int state, int mouseX, int mouseY );
void myKeyboardFunction( unsigned char key, int mouseX, int mouseY );
void Reshape( int width, int height );
void timer( int val );
void display(); …Run Code Online (Sandbox Code Playgroud)