I am very new to OpenGL programming but have done a lot of programming in Delphi. I want to make my OpenGL code compatible with Delphi so I want to know: the OpenGL data type GLboolean is compared to what in other languages? For example: is it an unsigned 32 bit integer or what? Please help ! Thankyou in advance! ]]>

Also, I have a sphere that orbits the cube, which I just want to color.

Now, I can display the textures, or color the items with the fragment/vertex shader, but I would like to change the color of just the sphere, but leave the cube unchanged.

Ultimately, then, I want to apply lighting and shading to both objects, equally. But, want to start out with baby steps.

Here are my vertex and fragment shaders

Code :

//fragment
//varying vec4 color;
//image texture
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main (void) {
//gl_FragColor = vec4(1.0, 0.5, 0.0, 0.0);
//one or the other gives me the desired results
gl_FragColor = texture2D(myTexture, vTexCoord);
}

and here is my vertex shader

Code :

//vertex
//varying vec4 color;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = vec2(gl_MultiTexCoord0);
//vTexCoord = gl_MultiTexCoord0;
//color = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

I try to rotate a cube around z axis, but it is rotating around a target.This is my code:

Code cpp:

ourShader.Use();
glm::mat4 transform;
transform = glm::translate(transform, glm::vec3(0.5f, -0.5f, 0.0f));
transform = glm::rotate(transform, glm::radians((GLfloat)glfwGetTime() * 50.0f), glm::vec3(0.0f, 0.0f, 1.0f));
GLint transformLoc = glGetUniformLocation(ourShader.Program, "transform");
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform));

And in the vertex shader:

Code glsl:

uniform mat4 transform;
...
gl_Position = transform * vec4(position, 1.0f);

Can you tell me what it could be the problem ?

Thank you! ]]>

Building portals mainly for a 3d GUI system, portals required for the clipping.

All the scenes rendered in a single render.

]]>

Code cpp:

#include <GL\glew.h>
#include <GLFW\glfw3.h>
#include <iostream>
int main()
{
glfwWindowHint(GLFW_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_VERSION_MINOR, 4);
if (!glfwInit())
std::cerr << "Failed to initialize GLFW." << std::endl;
GLFWwindow* window;
window = glfwCreateWindow(800, 600, "Window", NULL, NULL);
if (!window)
std::cerr << "Failed to create Window." << std::endl;
glfwMakeContextCurrent(window);
GLenum err;
if ((err = glewInit()) != GLEW_OK)
{
std::cerr << "Failed to initialize GLEW" << std::endl;
std::cerr << err << std::endl;
}
float data[] = { -0.5, -0.5, 0.1,
0.0, 0.5, 0.1,
0.5, -0.5, 0.1 };
GLuint vaoID;
GLuint vboID;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), &data[0], GL_STATIC_DRAW);
glBindVertexArray(0);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(vaoID);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
}

It produces a white triangle like you might expect. BUT. when i place some of the vao and vbo code in a class like this:

Code cpp:

#pragma once
#include <GL\glew.h>
class Model
{
public:
Model(float* data) {
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), &data[0], GL_STATIC_DRAW);
glBindVertexArray(0);
}
~Model();
GLuint vaoID;
GLuint vboID;
};

And the main code looks like this:

Code cpp:

#include <GL\glew.h>
#include <GLFW\glfw3.h>
#include <iostream>
#include "Model.h"
int main()
{
glfwWindowHint(GLFW_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_VERSION_MINOR, 4);
if (!glfwInit())
std::cerr << "Failed to initialize GLFW." << std::endl;
GLFWwindow* window;
window = glfwCreateWindow(800, 600, "Window", NULL, NULL);
if (!window)
std::cerr << "Failed to create Window." << std::endl;
glfwMakeContextCurrent(window);
GLenum err;
if ((err = glewInit()) != GLEW_OK)
{
std::cerr << "Failed to initialize GLEW" << std::endl;
std::cerr << err << std::endl;
}
float data[] = { -0.5, -0.5, 0.1,
0.0, 0.5, 0.1,
0.5, -0.5, 0.1 };
Model model(data);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(model.vaoID);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, model.vboID);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
}

It does not.

Why is this it has been foiling my projects for ages and i'm really fed up with it. ]]>

I have a height map which is being plotted from -1 to + 1 in the X direction, -1 to + 1 in Y and -1 to +1 in Z.

The height map is composed of many triangles. I want to zoom in the X direction so that I zoom into the details of the height map. I have no problems doing so as well as "panning" the map across the screen using the model matrix.

However, once I zoom in, then the surface becomes much wider than -1 to 1. How do I restrict the drawing to this limit? I would still need to rotate everything.

Thanks ]]>

I will be write in C++ ]]>

i don know how to do that. i have seen Nehe lesson 35 about playing avi video but it has low quality and i need much more.

i have seen many post in this forum but none of them solved my issue.

is there any one to help me to do that? ]]>

as i am new to the OpenGL. i want to load image to picturebox with visual c++.

i tried much and also i serach in google but i didn't get easy example of it.

pls help me.

thanks. ]]>

A video can be seen here:

https://youtu.be/AwB-4OycS6o

What we are seeing is a 3D surface of Signal strength vs Frequency vs Time obtained from a Software Defined Radio. The output from the radio is a Fast Fourier Transform of the IQ signals from the radio.

The plotting is done as a triangle strip with indices. There are approximately 400,000 triangles plotted each 100ms, so about 4,000,000 triangles per second. Each plot is done with one glDrawElements call.

Again many thanks for everyone's help.

Tom ]]>

I would like to ask for some help regarding OpenGL transformations. Before someone would ask, yes, it is a university assignment, but I'm not asking for any code, merely the theoretical answer.

One of the tasks is to rotate an existing cube (which is originally at the origo) around an arbitrary axis. This axis is a line, which the user can enter two sets of coordinates for to define it, as well as an angle of rotation. I handled the drawing of the line, the user input already and I know how to use the transformation functions, but I am stuck with this line rotation in theory.

Any help would be highly appreciated! ]]>

Code :

Code :

glm::f32 x = size.x / 2.0f;
glm::f32 y = size.y / 2.0f;
glm::f32 z = size.z / 2.0f;
glm::vec3 a0 = glm::vec3(+x, +y, +z);
glm::vec3 a1 = glm::vec3(-x, +y, +z);
glm::vec3 a2 = glm::vec3(-x, -y, +z);
glm::vec3 a3 = glm::vec3(+x, -y, +z);
glm::vec3 a4 = glm::vec3(+x, +y, -z);
glm::vec3 a5 = glm::vec3(-x, +y, -z);
glm::vec3 a6 = glm::vec3(-x, -y, -z);
glm::vec3 a7 = glm::vec3(+x, -y, -z);
glm::vec3 verts[] = {
a1, a2, a3, a3, a0, a1,
a2, a6, a7, a7, a3, a2,
a6, a5, a4, a4, a7, a6,
a5, a1, a0, a0, a4, a5,
a0, a3, a7, a7, a4, a0,
a5, a6, a2, a2, a1, a5
};
glm::vec3 norm[36];
for (int i = 0; i < 36; i += 3)
{
glm::vec3 normal = glm::normalize(
glm::cross(
glm::vec3(verts[i + 1]) - glm::vec3(verts[i]),
glm::vec3(verts[i + 2]) - glm::vec3(verts[i])));
norm[i] = normal;
norm[i + 1] = normal;
norm[i + 2] = normal;
}

I have taken code off the net but I believe the generator is for triangles and not triangle strip?

Can you help?

Heres my code, thanks.

Code :

diameter /= 2.0;
numVertices = 0;
glm::vec3 vertex(0.0f, 0.0f, 0.0f);
float lonstep = (float)(M_PI / (float)stacks);
float latstep = (float)(M_PI / (float)slices);
float lon, lat;
glm::vec2 texCoord(0.0f, 0.0f);
float dstack = 1.0f / (float)stacks;
float dslice = 1.0f / (float)slices;
float texX, texY;
std::vector<glm::vec3> vertices;
std::vector<glm::vec3> normals;
std::vector<glm::vec2> uvs;
for (lon = 0.0f, texX = 0.0f; lon <= 2 * M_PI; lon += (lonstep), texX += (dstack))
{
for (lat = 0.0, texY = 0.0f; lat <= 2 * M_PI + latstep; lat += (latstep), texY += (dslice))
{
vertex[0] = diameter * cosf(lon)*sinf(lat);
vertex[1] = diameter * sinf(lon)*sinf(lat);
vertex[2] = diameter * cosf(lat);
vertices.push_back(vertex); // vertex position
texCoord[0] = texX;
texCoord[1] = texY;
uvs.push_back(texCoord); // vertex texture coordnate
vertex = glm::normalize(vertex);
normals.push_back(vertex); // vertex normal
numVertices++;
vertex[0] = diameter * cosf(lon + lonstep)*sinf(lat);
vertex[1] = diameter * sinf(lon + lonstep)*sinf(lat);
vertex[2] = diameter * cosf(lat);
vertices.push_back(vertex); // vertex position
texCoord[0] = texX + dstack;
texCoord[1] = texY;
uvs.push_back(texCoord); // vertex texture coordnate
vertex = glm::normalize(vertex);
normals.push_back(vertex); // vertex normal
numVertices++;
}
}
std::vector<glm::vec3> tangents;
std::vector<glm::vec3> bitangents;
// problem here?
for (unsigned int i = 0; i < vertices.size(); i += 3)
{
// Shortcuts for vertices
glm::vec3 & v0 = vertices[i + 0];
glm::vec3 & v1 = vertices[i + 1];
glm::vec3 & v2 = vertices[i + 2];
// Shortcuts for UVs
glm::vec2 & uv0 = uvs[i + 0];
glm::vec2 & uv1 = uvs[i + 1];
glm::vec2 & uv2 = uvs[i + 2];
// Edges of the triangle : postion delta
glm::vec3 deltaPos1 = v1 - v0;
glm::vec3 deltaPos2 = v2 - v0;
// UV delta
glm::vec2 deltaUV1 = uv1 - uv0;
glm::vec2 deltaUV2 = uv2 - uv0;
float r = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV1.y * deltaUV2.x);
glm::vec3 tangent = (deltaPos1 * deltaUV2.y - deltaPos2 * deltaUV1.y)*r;
glm::vec3 bitangent = (deltaPos2 * deltaUV1.x - deltaPos1 * deltaUV2.x)*r;
// Set the same tangent for all three vertices of the triangle.
// They will be merged later, in vboindexer.cpp
tangents.push_back(tangent);
tangents.push_back(tangent);
tangents.push_back(tangent);
// Same thing for binormals
bitangents.push_back(bitangent);
bitangents.push_back(bitangent);
bitangents.push_back(bitangent);
}
for (unsigned int i = 0; i < vertices.size(); i += 1)
{
glm::vec3 & n = normals[i];
glm::vec3 & t = tangents[i];
glm::vec3 & b = bitangents[i];
// Gram-Schmidt orthogonalize
t = glm::normalize(t - n * glm::dot(n, t));
// Calculate handedness
if (glm::dot(glm::cross(n, t), b) < 0.0f) {
t = t * -1.0f;
}
}

i'm working on environment mapping. So i created a dynamic cube_map using geometry shader and gl_layer to single pass render all 6 direction thus this cube map texture is attached to an FBO. every thing worked fine. until i

decided to output this generated cube map as bmp images ( 6 faces --> 6 images). for this task i used

the problem is that the only out put image i get is the one attached to GL_TEXTURE_CUBE_MAP_POSITIVE_X the rest is corrupted data not that the cube map is rendered correctly in the screen.

this is how i created my cube map and bound it to FBO

Code :

// 2-generate the color buffer for the cube map simple as we did in cubemapTexture function
glGenTextures(1,&this->_mTexture);
glBindTexture(GL_TEXTURE_CUBE_MAP, this->_mTexture);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// loop throw the 6 faces of the cube again
for(uint i = 0; i < 6; i++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,0,GL_RGB,w,h,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
//3- generate the FBO
glGenFramebuffers(1,&this->_mFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER,this->_mFrameBuffer);
//4-attach CubeMap to FBO
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, this->_mTexture, 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, this->_mdepthTexture, 0);

than i do my rendering just fine

here this is the code to save my cube map into bmp file not that every face is size of 64 * 64 and the problem is only this call

thank you for your attention best regard.

Code :

void TextureGL::SaveCubeMapToImage() // this save all 6 faces of cube map into images in harddrive
{
BYTE front[3 * 64 * 64];
BYTE back[3 * 64 * 64];
BYTE top[3 * 64 * 64];
BYTE bottom[3 * 64 * 64];
BYTE left[3 * 64 * 64];
BYTE right[3 * 64 * 64];
glBindTexture(GL_TEXTURE_CUBE_MAP, this->_mTexture);
// get textures from cube map
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,right);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,left);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,top);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,bottom);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,front);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,back);
// write this images down
FIBITMAP* r = FreeImage_ConvertFromRawBits(right, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, r, "resources/textures/Irradiance/posX.bmp", 0);
FIBITMAP* l = FreeImage_ConvertFromRawBits(left, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, l, "resources/textures/Irradiance/negX.bmp", 0);
FIBITMAP* t = FreeImage_ConvertFromRawBits(top, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, t, "resources/textures/Irradiance/posY.bmp", 0);
FIBITMAP* b = FreeImage_ConvertFromRawBits(bottom, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, b, "resources/textures/Irradiance/negY.bmp", 0);
FIBITMAP* f = FreeImage_ConvertFromRawBits(front, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, f, "resources/textures/Irradiance/posZ.bmp", 0);
FIBITMAP* bac = FreeImage_ConvertFromRawBits(back, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, bac, "resources/textures/Irradiance/negZ.bmp", 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}