小编gen*_*ult的帖子

OpenGL背面纹理

我有一个女巫的游戏牌我想要模拟一个翻转动画.

所以我在我的Tile上使用glRotatef(角度,0,1,0)来模拟从180度角开始的翻转动画,这样我的瓷砖开始后翻并向我显示背面.一切都很好,但问题是,当我的瓷砖开始后翻时,我不想看到翻转的纹理.

我希望看到的结果是黑色(由顶点颜色提供)或背面的不同纹理和前脸的游戏纹理.更简单的是我想建立一种游戏卡.

任何人都可以建议我解决我的问题的方法?

iphone opengl-es

0
推荐指数
1
解决办法
1184
查看次数

为什么UIKit绘图不能直接使用图形处理器加速

你会听到很多关于OpenGL直接使用图形处理器的优点,这就是使用这种技术而不是UIKit的主要优势.但是,如果用这种方式做得好得多,为什么UIKit也不这样做呢?

iphone cocoa-touch opengl-es

0
推荐指数
1
解决办法
842
查看次数

如何在IOS应用程序(OpenGL)中放置href链接

我的应用程序是用OpenGL和C++编写的,我不使用XIB文件进行演示.那么如何创建一个用户点击的href链接并将其带给浏览器中的某个人?

c++ opengl-es objective-c ios

0
推荐指数
1
解决办法
182
查看次数

以编程方式获取UIview + glview

我在我的uiview中有glview,现在我必须拍摄uiview和glview的组合视图.我google了很多,但我发现任何有用的东西,我知道如何采取glview的scrrenshot

nt width = glView.frame.size.width; int height = glView.frame.size.height;

NSInteger myDataLength = width * height * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// gl renders "upside down" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y < height; y++)
{
    for(int x = 0; …
Run Code Online (Sandbox Code Playgroud)

iphone opengl-es

0
推荐指数
1
解决办法
3374
查看次数

从OBJ文件渲染网格时出现问题

我正在调整问题,或者我想要理解OBJ文件中的顶点/索引/面.我想最终以编程方式解析OBJ文件,但首先我需要了解如何手动完成.我正在使用GLWallpaperService(由网络上的开发人员提供)中的示例进行调整来完成此操作.

我遇到的问题是它似乎与他提供的代码一起工作,以生成一个具有不同颜色面的通用立方体,他必须单独实现和绘制.我调整后的代码试图从我从搅拌机输出并插入值的坐标中绘制一个基本的立方体.

public class GLCube {
private final int _nrOfVertices = 8;

private FloatBuffer _vertexBuffer;
private FloatBuffer _normalBuffer;
private ShortBuffer _indiceBuffer;

public GLCube() {
    this.init();
}

private void init() {
    // 3 is the number of coordinates to each vertex.
    _vertexBuffer = BufferFactory.createFloatBuffer(_nrOfVertices * 3);
    _normalBuffer = BufferFactory.createFloatBuffer(18);
    _indiceBuffer = BufferFactory.createShortBuffer(72);

    // Coordinates for the vertexes of the cube.
    float[] vertexCoords = {
            /*
            1f,  1f,  0f,
            0f,  1f,  0f, 
            0f,  0f,  0f, 
            1f,  0f,  0f, 
            1f,  0f, -1f, 
            1f, …
Run Code Online (Sandbox Code Playgroud)

android opengl-es cube .obj live-wallpaper

0
推荐指数
1
解决办法
1370
查看次数

opengl纹理无法正确渲染

我遇到的问题是我不能让我的纹理以正确的比例渲染,并且由于某种原因,纹理也在重复自身,中间有一个空格.

这是我正在使用的纹理(我正在用这种纹理填充屏幕):

质地

渲染时它看起来像这样(红色轮廓是整个屏幕,纹理使用1像素边框渲染):

截图

这是代码:

package game;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Timer;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.TextureLoader;

public class WarZone {

private boolean done = false;
private String windowTitle = "War Zone";
private DisplayMode displayMode;
private Timer timer;
private float dt;

public static void main(String[] args) {
    new WarZone().run(false);
}

public void run(boolean fullscreen) {
    try {
        init();
        switchToOrtho();
        while (!done) {
            timer.tick();
            update();
            render();
            Display.update();
        }
        cleanup();
    } catch (Exception …
Run Code Online (Sandbox Code Playgroud)

java opengl graphics textures

0
推荐指数
1
解决办法
1835
查看次数

如何删除一次制作的所有纹理?

如何删除我制作的所有纹理?假设我加载了一些纹理:

GLuint tx_wall,tx_floor,tx_tiles;
tx_wall=LoadTexture("tex_wall.raw",512,512),
tx_floor=LoadTexture("tex_floor.raw",512,512),
tx_tiles=LoadTexture("tex_tiles.raw",512,512);
Run Code Online (Sandbox Code Playgroud)

然后使用它们:

glBindTexture(GL_TEXTURE_2D,tx_wall);
  glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex3f(0,   0,  0);
    glTexCoord2f(1, 0); glVertex3f(0,  50,  0);
    glTexCoord2f(1, 1); glVertex3f(0,   0, 14);
    glTexCoord2f(0, 1); glVertex3f(0,  50, 14);
  glEnd();
glBindTexture(GL_TEXTURE_2D,tx_floor);
  glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex3f(0,   0,  0);
    glTexCoord2f(1, 0); glVertex3f(50,  50, 0);
    glTexCoord2f(1, 1); glVertex3f(50,  50, 0);
    glTexCoord2f(0, 1); glVertex3f(0,   0,  0);
  glEnd();
(and so on)
Run Code Online (Sandbox Code Playgroud)

当游戏结束时,删除它们:

glDeleteTextures(1,&tx_wall);
glDeleteTextures(1,&tx_floor);
glDeleteTextures(1,&tx_tiles);
Run Code Online (Sandbox Code Playgroud)

一切正常,但如果我有10或20个纹理,我将如何终止它们而不取名字?

c++ opengl

0
推荐指数
1
解决办法
1243
查看次数

C++ 多态性和类型转换

我对 C++ 比较陌生,一直在使用 OpenGL 开发基本的 3D 渲染引擎。我有以下问题:我有一个名为 GeomEntity 的类,它是所有几何基元的基类。我有另一个名为 DefaultMaterial 的类,它是所有材质的基类(由不同类型的着色器程序组成)。因为我将拥有多种类型的材质,例如:ColorMaterial、TextureMaterial、AnimatedMaterial 等,我需要在 GeomEntity 类中放置对材质的引用,以便从主应用程序我可以使用此功能设置任何材料:

  void GeomEntity ::addMaterial (const DefaultMaterial *mat){

         material=mat;////material is the member variable pointer of type DefaultMaterial

  }
Run Code Online (Sandbox Code Playgroud)

但问题是,虽然所有这些材质都派生自 DefaultMaterial,但它们都有自己独特的方法,如果我默认将它们引用到 DefaultMaterial 变量,则无法触发这些方法。例如在主应用程序中:

  Sphere sphere;
  ....
  sphere.addMaterial(&animMaterial);///of type AnimatedMaterial
  sphere.material->interpolateColor(timerSinceStart);
   ///doesn't happen anything  as the sphere.material is
  /// of type DefaultMaterial that has   no interpolateColor() method
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用模板或强制转换,但我想听听 C++ 中这种多态性的最佳实践。在 Java 或 C# 中,我真的会使用这样的东西:

((AnimatedMaterial)sphere.material).interpolateColor(timerSinceStart);
Run Code Online (Sandbox Code Playgroud)

c++ oop polymorphism

0
推荐指数
1
解决办法
6632
查看次数

OpenGL管道中的剪切空间

剪切和投影如何在简化的解释中工作?它与标准化顶点和矩阵乘法有关,包括将x,y,z除以第四个变量.我无法理解实际发生的事情.

opengl graphics pipeline clipping matrix

0
推荐指数
1
解决办法
679
查看次数

在OpenGL中相对于相机旋转对象

我在OpenGL中遇到问题让我的对象(一个行星)相对于当前的相机旋转旋转.它似乎首先工作,但在旋转一点后,旋转不再正确/相对于相机.

我正在计算屏幕上mouseX和mouseY移动的增量(差异).旋转存储在称为"planetRotation"的Vector3D中.

这是我的代码来计算相对于planetRotation的旋转:

Vector3D rotateAmount;
rotateAmount.x = deltaY;
rotateAmount.y = deltaX;
rotateAmount.z = 0.0;

glPushMatrix();
    glLoadIdentity();
    glRotatef(-planetRotation.z, 0.0, 0.0, 1.0);
    glRotatef(-planetRotation.y, 0.0, 1.0, 0.0);
    glRotatef(-planetRotation.x, 1.0, 0.0, 0.0);
    GLfloat rotMatrix[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, rotMatrix);
glPopMatrix();

Vector3D transformedRot = vectorMultiplyWithMatrix(rotateAmount, rotMatrix);
planetRotation = vectorAdd(planetRotation, transformedRot);
Run Code Online (Sandbox Code Playgroud)

理论上 - 它的作用是在'rotateAmount'变量中设置一个旋转.然后通过将此向量与逆模型变换矩阵(rotMatrix)相乘,将其转换为模型空间.

然后将该变换后的旋转添加到当前旋转.

要渲染这是正在设置的转换:

glPushMatrix();
    glRotatef(planetRotation.x, 1.0, 0.0, 0.0);
    glRotatef(planetRotation.y, 0.0, 1.0, 0.0);
    glRotatef(planetRotation.z, 0.0, 0.0, 1.0);
    //render stuff here
glPopMatrix();
Run Code Online (Sandbox Code Playgroud)

相机有点摆动,我试图执行的旋转,似乎与当前的变换无关.

我究竟做错了什么?

opengl camera transform rotational-matrices

0
推荐指数
1
解决办法
599
查看次数