• 11
• 9
• 12
• 9
• 11
• ### Similar Content

• By tj8146
I have attached my project in a .zip file if you wish to run it for yourself.
I am making a simple 2d top-down game and I am trying to run my code to see if my window creation is working and to see if my timer is also working with it. Every time I run it though I get errors. And when I fix those errors, more come, then the same errors keep appearing. I end up just going round in circles.  Is there anyone who could help with this?

Errors when I build my code:
1>Renderer.cpp 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2039: 'string': is not a member of 'std' 1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stddef.h(18): note: see declaration of 'std' 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2061: syntax error: identifier 'string' 1>c:\users\documents\opengl\game\game\renderer.cpp(28): error C2511: 'bool Game::Rendering::initialize(int,int,bool,std::string)': overloaded member function not found in 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.h(9): note: see declaration of 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.cpp(35): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(36): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(43): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>Done building project "Game.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Renderer.cpp
#include <GL/glew.h> #include <GLFW/glfw3.h> #include "Renderer.h" #include "Timer.h" #include <iostream> namespace Game { GLFWwindow* window; /* Initialize the library */ Rendering::Rendering() { mClock = new Clock; } Rendering::~Rendering() { shutdown(); } bool Rendering::initialize(uint width, uint height, bool fullscreen, std::string window_title) { if (!glfwInit()) { return -1; } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); glViewport(0, 0, (GLsizei)width, (GLsizei)height); glOrtho(0, (GLsizei)width, (GLsizei)height, 0, 1, -1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glfwSwapInterval(1); glEnable(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); glLoadIdentity(); return true; } bool Rendering::render() { /* Loop until the user closes the window */ if (!glfwWindowShouldClose(window)) return false; /* Render here */ mClock->reset(); glfwPollEvents(); if (mClock->step()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glfwSwapBuffers(window); mClock->update(); } return true; } void Rendering::shutdown() { glfwDestroyWindow(window); glfwTerminate(); } GLFWwindow* Rendering::getCurrentWindow() { return window; } } Renderer.h
#pragma once namespace Game { class Clock; class Rendering { public: Rendering(); ~Rendering(); bool initialize(uint width, uint height, bool fullscreen, std::string window_title = "Rendering window"); void shutdown(); bool render(); GLFWwindow* getCurrentWindow(); private: GLFWwindow * window; Clock* mClock; }; } Timer.cpp
#include <GL/glew.h> #include <GLFW/glfw3.h> #include <time.h> #include "Timer.h" namespace Game { Clock::Clock() : mTicksPerSecond(50), mSkipTics(1000 / mTicksPerSecond), mMaxFrameSkip(10), mLoops(0) { mLastTick = tick(); } Clock::~Clock() { } bool Clock::step() { if (tick() > mLastTick && mLoops < mMaxFrameSkip) return true; return false; } void Clock::reset() { mLoops = 0; } void Clock::update() { mLastTick += mSkipTics; mLoops++; } clock_t Clock::tick() { return clock(); } } TImer.h
#pragma once #include "Common.h" namespace Game { class Clock { public: Clock(); ~Clock(); void update(); bool step(); void reset(); clock_t tick(); private: uint mTicksPerSecond; ufloat mSkipTics; uint mMaxFrameSkip; uint mLoops; uint mLastTick; }; } Common.h
#pragma once #include <cstdio> #include <cstdlib> #include <ctime> #include <cstring> #include <cmath> #include <iostream> namespace Game { typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef float ufloat; }
Game.zip
• By lxjk
Hi guys,
There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
This method can be naturally extended to clustered light culling as well.
The following image shows the general ideas

Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test

I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!

Eric

• Good evening everyone!

I was wondering if there is something equivalent of  GL_NV_blend_equation_advanced for AMD?
Basically I'm trying to find more compatible version of it.

Thank you!

• Hello guys,

How do I know? Why does wavefront not show for me?
I already checked I have non errors yet.

And my download (mega.nz) should it is original but I tried no success...
- Add blend source and png file here I have tried tried,.....

PS: Why is our community not active? I wait very longer. Stop to lie me!
Thanks !

• I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.

# OpenGL Surface plot for any data

This topic is 3189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I need to draw surface plot using OpenGL for the following data. X-Axis | Y-Axis | Z-Axis ========================= Jan-08 | 120.0 | 25.5 Feb-08 | 125.7 | 24.15 Mar-08 | 100.0 | 42.11 Apr-08 | 190.0 | 15.62 May-08 | 109.0 | 21.88 Jun-08 | 150.5 | 56.55 Jul-08 | 191.8 | 89.93 Aug-08 | 177.7 | 15.65 I searched in the web and found some samples all of which draw a sin function or exp functional data. But I need the surface plot for the above data. So, I am not able to figure out. Can anybody tell me an idea to do this. Thanks in advance, Regards, Srinu

##### Share on other sites
I don't have any experience with surface plots but AFAIK you need a function that takes two arguments to plot it as a 3D surface (with the arguments generally representing the X- and Z-Axis).

Your data just resembles a bunch of points, so the most natural way would be to connect them to a line (converting the months to numbers, like Jan = 1). If you need a surface you might draw a quad/two triangles between two adjacent datasets (where each dataset has 2 points - one specified by X,Y,Z and one with one coordinate set to 0), e.g. for Jan and Feb you could use the points:

X/Y/Z
1/120.0/0
1/120.0/25.5
2/125.7/0
2/125.7/24.15

Hope that helps.

##### Share on other sites
Hi Lord,
Thanks for the response. Your idea sounds like a good one. I am going to implement it to see whether it works. But, I am stuck at converting these coordinates to OpenGL coordinates. Could you please tell me how to do this?

Thanks,
Srinu

##### Share on other sites
I'm not sure where you're stuck, but you could just convert the months to January = 0.0, February = 1.0, March = 2.0 and so on (or use another scale, if you like). Then you alreay have the needed coordinates and just need to call glVertex3f(x,y,z) or - which would be better - put the coordinates into a VBO and render that.

##### Share on other sites
Thats ok. But OpenGL coords should be between -1 to 1, right? So, these coords must be converted to their equivalent opengl coords.
For example Take a 3d point - 1.0, 120.0, 25.5. We can not render this point in OpenGL window. It must be converted to OpenGL window coords. I am asking how to do this convertion?

Thanks,
Srinu

##### Share on other sites
For a 2 dimensional plot, you could make the vertical axis the Y & Z variables and the horizontal the X (time), then plot the data as vectors instead of points. Or you could do something more interesting, like use the Z data to be the diameter of a circle with the X variables on the horizontal and y be the vertical. Then if you scale the axes properly, you'd have circles of diameter Z centered at height Y and the proper time X which should be spaced not to overlap. Or you could represent one of the fields as color (X makes the most sense, having exact and regular values to easily correspond to a given color). I would look at some differential equation or vector field graphs to see techniques people use for graphic 3 dimensional data in 2 dimensional graphs if thats what you want, or you could make the graph 3D if you really want.

##### Share on other sites
Quote:
 Original post by srinivaz111Thats ok. But OpenGL coords should be between -1 to 1, right? So, these coords must be converted to their equivalent opengl coords. For example Take a 3d point - 1.0, 120.0, 25.5. We can not render this point in OpenGL window. It must be converted to OpenGL window coords. I am asking how to do this convertion?Thanks,Srinu

No, you use whatever coordinates you want and OpenGL will internally scale it.

##### Share on other sites
You can use any (reasonable) number for a OpenGL coordinate. However, to get it drawn to screen you have to setup your modelview and projection matrices properly.

If you don't want to do that you'd have to convert the coordinates to range [-1,1] for x and y and to [0,1] for z. This shouldn't be too hard (e.g. if months go from 0 to 11 you can set x to month * (2.0f/11.0f) - 1.0f).

However, I'd recommend using the matrices as they would allow you to use different viewing angles.

##### Share on other sites
not able to draw the plot using the method where I took 2 points for every coordinate. I got a weird graph. I am following the Contour plot method which involves defining a texture and drawing triangles and setting the texture to those triangles. Can anybody who knows the contour plot method please help me?
I am sending the code also. Please look into it.

This is the actual data for which I have to plot the graph

X-Axis | Y-Axis | Z-Axis
=========================
Jan-08 | 120.0 | 25.5
Feb-08 | 125.7 | 24.15
Mar-08 | 100.0 | 42.11
Apr-08 | 190.0 | 15.62
May-08 | 109.0 | 21.88
Jun-08 | 150.5 | 56.55
Jul-08 | 191.8 | 89.93
Aug-08 | 177.7 | 15.65

So, I have taken the following points table

float data[24][3] =
{
{1.0,120.0,0},
{1.0,120.0,0.5},
{1.0,120.0,25.5},
{2.0,125.7,0},
{2.0,125.7,0.5},
{2.0,125.7,24.15},
{3.0,100.0,0},
{3.0,100.0,0.5},
{3.0,100.0,42.11},
{4.0,190.0,0},
{4.0,190.0,0.5},
{4.0,190.0,15.62},
{5.0,109.0,0},
{5.0,109.0,0.5},
{5.0,109.0,21.88},
{6.0,150.5,0},
{6.0,150.5,0.5},
{6.0,150.5,56.55},
{7.0,191.8,0},
{7.0,191.8,0.5},
{7.0,191.8,89.93},
{8.0,177.7,0},
{8.0,177.7,0.5},
{8.0,177.7,15.65}

};

Here is the code:

void MyGraph::Generate3DData()
{
m_fWidth = 1.0f;
m_fStep = 0.05f;
int nSurface = 1;
int nVertex = nSurface + 1;

v3DVector tempVector;

for (int x=0; x<24; x+=3)
{
double ogl_x, ogl_y, ogl_z;
GetOpenGLCoords(data[x][0], data[x][1], data[x][2], &ogl_x, &ogl_y, &ogl_z);
tempVector.push_back(C3DVector(ogl_x, ogl_y, ogl_z));

GetOpenGLCoords(data[x+1][0], data[x+1][1], data[x+1][2], &ogl_x, &ogl_y, &ogl_z);
tempVector.push_back(C3DVector(ogl_x, ogl_y, ogl_z));

GetOpenGLCoords(data[x+2][0], data[x+2][1], data[x+2][2], &ogl_x, &ogl_y, &ogl_z);
tempVector.push_back(C3DVector(ogl_x, ogl_y, ogl_z));

m_vVertexNormal.push_back(tempVector);

tempVector.clear();
}

tempVector.clear();

/* int size = m_vVertexNormal.size();
std::vector<v3DVector>::iterator it;
for (it=m_vVertexNormal.begin(); it!=m_vVertexNormal.end(); it++)
{
v3DVector tVector = *it;
int vsize = tVector.size();
}
*/

// Surface Normal
for(int nX = 0; nX < 7; nX ++)
{
for(int nY(0); nY < 2; nY ++)
{
C3DVector temp3DVector(0, 0,0);
C3DVector point1 = m_vVertexNormal.at(nX).at(nY);
C3DVector point2 = m_vVertexNormal.at(nX+1).at(nY);
C3DVector point3 = m_vVertexNormal.at(nX+1).at(nY+1);

CalculateNormal(point1, point2, point3, temp3DVector);

tempVector.push_back( temp3DVector );
}
m_vSurfaceNormal.push_back(tempVector);
tempVector.clear();
}

// Vertex Normal
for(nX = 0; nX < 7; nX ++)
for(int nY(0); nY < 2; nY ++)
{
m_vVertexNormal.at(nX).at(nY) += m_vSurfaceNormal.at(nX).at(nY);
m_vVertexNormal.at(nX+1).at(nY) += m_vSurfaceNormal.at(nX).at(nY);
m_vVertexNormal.at(nX).at(nY+1) += m_vSurfaceNormal.at(nX).at(nY);
m_vVertexNormal.at(nX+1).at(nY+1) += m_vSurfaceNormal.at(nX).at(nY);
}
for(nX = 0; nX < 8; nX ++)
for(int nY(0); nY < 3; nY ++)
m_vVertexNormal.at(nX).at(nY).Average();
}

BOOL MyGraph::CalculateNormal(C3DVector& fPoint1, C3DVector& fPoint2, C3DVector& fPoint3, C3DVector& fNormal)
{
float fx = (fPoint2.GetY()-fPoint1.GetY())*(fPoint3.GetZ()-fPoint2.GetZ())-
(fPoint3.GetY()-fPoint2.GetY())*(fPoint2.GetZ()-fPoint1.GetZ());

// (y2-y1)(z3-z2)-(y3-y2)(z2-z1)

float fy = (fPoint3.GetX()-fPoint2.GetX())*(fPoint2.GetZ()-fPoint1.GetZ())-
(fPoint2.GetX()-fPoint1.GetX())*(fPoint3.GetZ()-fPoint2.GetZ());

float fz = (fPoint2.GetX()-fPoint1.GetX())*(fPoint3.GetY()-fPoint2.GetY())-
(fPoint3.GetX()-fPoint2.GetX())*(fPoint2.GetY()-fPoint1.GetY());

float fd = (float) sqrt(fx*fx + fy*fy + fz*fz);

fNormal.SetVector(fx/fd, fy/fd, fz/fd);

return TRUE;
}

void MyGraph::GetOpenGLCoords(float x, float y, float z, double *ogl_x, double *ogl_y, double *ogl_z)
{

*ogl_x = x * (2.0/11.0) - 1.0;
*ogl_y = y * (2.0/191.8) - 1.0;
*ogl_z = z/89.93;
}

void MyGraph::CreateGraph3DList(UINT nList)
{
::glNewList(nList , GL_COMPILE);
for(int x=0, int nX(0); nX < m_vSurfaceNormal.size(); nX++, x+=2)
{
double ogl_x, ogl_y, ogl_z;
GetOpenGLCoords(data[x][0], data[x][1], data[x][2], &ogl_x, &ogl_y, &ogl_z);

float fx = ogl_x; //(nX*m_fStep - 1)*m_fWidth;

::glBegin(GL_TRIANGLE_STRIP);
for(int nY(0); nY < 3/*m_vSurfaceNormal.size()*/; nY++)
{
float fNormal[3];
m_vVertexNormal.at(nX).at(nY).GetVector(fNormal);
::glNormal3fv(fNormal);
float fy = ogl_y;//(nY*m_fStep - 1)*m_fWidth;
float fz = ogl_z;//GetZ(fx, fy);
::glTexCoord1f((fz+1)/2);
::glVertex3d(fx, fy, fz/2);

m_vVertexNormal.at(nX+1).at(nY).GetVector(fNormal);
::glNormal3fv(fNormal);

GetOpenGLCoords(data[x+1][0], data[x+1][1], data[x+1][2], &ogl_x, &ogl_y, &ogl_z);

float fx2 = ogl_x;//fx+m_fStep;
fz = ogl_z;//GetZ(fx2, fy);
::glTexCoord1f((fz+1)/2);
::glVertex3d(fx2, fy, fz/2);
}
::glEnd();
}
::glEndList();
}

Please look into it and show me a way to achieve it.

~Srinu

##### Share on other sites
First, please use the source tags

Quote:
 Original post by srinivaz111So, I have taken the following points tablefloat data[24][3] = { {1.0,120.0,0}, {1.0,120.0,0.5}, {1.0,120.0,25.5}, {2.0,125.7,0}, {2.0,125.7,0.5}, {2.0,125.7,24.15}, {3.0,100.0,0}, {3.0,100.0,0.5}, {3.0,100.0,42.11}, {4.0,190.0,0}, {4.0,190.0,0.5}, {4.0,190.0,15.62}, {5.0,109.0,0}, {5.0,109.0,0.5}, {5.0,109.0,21.88}, {6.0,150.5,0}, {6.0,150.5,0.5}, {6.0,150.5,56.55}, {7.0,191.8,0}, {7.0,191.8,0.5}, {7.0,191.8,89.93}, {8.0,177.7,0}, {8.0,177.7,0.5}, {8.0,177.7,15.65}};

I just skimmed over your code but looking at your data I can make a guess:

You draw the data as a triangle strip, so you get triangles like (in your coords):

{1.0,120.0,0}/{1.0,120.0,0.5}/{1.0,120.0,25.5} -- this basically is a line and wouldn't be rendered (degenerate triangle)
{1.0,120.0,0.5}/{1.0,120.0,25.5}/{2.0,125.7,0}
{1.0,120.0,25.5}/{2.0,125.7,0}/{2.0,125.7,0.5}
{2.0,125.7,0}/{2.0,125.7,0.5}/{2.0,125.7,24.15} -- this is a line, too
...

Why are those {..,..,0.5} point in there? If you remove them, the graph should look better.
If not, I maybe misunderstood you and a screenshot would help me to get a better impression on what your graph looks like.